From 6dc7266489ed50238f7e33551ddf02d990c5624f Mon Sep 17 00:00:00 2001 From: ilya-korotya Date: Tue, 17 Sep 2024 16:44:31 +0200 Subject: [PATCH] add query param to resolve gist information --- pkg/app/handler.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/app/handler.go b/pkg/app/handler.go index 1807b1b..7f31d75 100644 --- a/pkg/app/handler.go +++ b/pkg/app/handler.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log" + "math/big" "net/http" "strings" @@ -88,14 +89,27 @@ func (d *DidDocumentHandler) GetByENSDomain(w http.ResponseWriter, r *http.Reque func (d *DidDocumentHandler) GetGist(w http.ResponseWriter, r *http.Request) { chain := r.URL.Query().Get("chain") - networkid := r.URL.Query().Get("networkid") + networkid := r.URL.Query().Get("network") if chain == "" || networkid == "" { log.Println("'chain' and 'networkid' should be set") w.WriteHeader(http.StatusBadRequest) return } - gistInfo, err := d.DidDocumentService.GetGist(r.Context(), chain, networkid, nil) + gist := r.URL.Query().Get("gist") + var opts *services.ResolverOpts + if gist != "" { + opts = &services.ResolverOpts{} + gistRoot, ok := big.NewInt(0).SetString(gist, 10) + if !ok { + log.Println("invalid gist root format") + w.WriteHeader(http.StatusBadRequest) + return + } + opts.GistRoot = gistRoot + } + + gistInfo, err := d.DidDocumentService.GetGist(r.Context(), chain, networkid, opts) if errors.Is(err, services.ErrNetworkIsNotSupported) { w.WriteHeader(http.StatusNotFound) log.Printf(`{"error":"resolver for '%s:%s' network not found"}`, chain, networkid)