Skip to content

Commit

Permalink
Merge pull request #27 from moonstream-to/no-metatx
Browse files Browse the repository at this point in the history
No metatx param mostly for test purpose
  • Loading branch information
kompotkot authored Dec 19, 2023
2 parents 3b1daea + 4b4c325 commit a5484b0
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ type SignDropperRequest struct {
Sensible bool `json:"sensible"`
Requests []*DropperClaimMessage `json:"requests"`

NoMetatx bool `json:"no_metatx"`
}

type SignDropperResponse struct {
ChainId int `json:"chain_id"`
Dropper string `json:"dropper"`
TtlDays int `json:"ttl_days"`
Sensible bool `json:"sensible"`
Requests []*DropperClaimMessage `json:"requests"`

MetatxRegistered bool `json:"metatx_registered"`
}

Expand Down Expand Up @@ -284,9 +294,6 @@ func (server *Server) signDropperRoute(w http.ResponseWriter, r *http.Request, s
authorizationContext := r.Context().Value("authorizationContext").(AuthorizationContext)
authorizationToken := authorizationContext.AuthorizationToken

queries := r.URL.Query()
isMetatxDrop := queries.Has("is_metatx_drop")

body, readErr := io.ReadAll(r.Body)
if readErr != nil {
http.Error(w, "Unable to read body", http.StatusBadRequest)
Expand Down Expand Up @@ -320,7 +327,7 @@ func (server *Server) signDropperRoute(w http.ResponseWriter, r *http.Request, s
message.Signature = hex.EncodeToString(signedMessage)
message.Signer = server.AvailableSigners[signer].key.Address.Hex()

if isMetatxDrop {
if !req.NoMetatx {
callRequests[i] = CallRequestSpecification{
Caller: message.Claimant,
Method: "claim",
Expand All @@ -336,16 +343,24 @@ func (server *Server) signDropperRoute(w http.ResponseWriter, r *http.Request, s
}
}

if isMetatxDrop {
resp := SignDropperResponse{
ChainId: req.ChainId,
Dropper: req.Dropper,
TtlDays: req.TtlDays,
Sensible: req.Sensible,
Requests: req.Requests,
}

if !req.NoMetatx {
createReqErr := server.MoonstreamEngineAPIClient.CreateCallRequests(authorizationToken, "", req.Dropper, req.TtlDays, callRequests, 100, 1)
if createReqErr == nil {
log.Printf("New %d call_requests registered at metatx for %s", len(callRequests), req.Dropper)
req.MetatxRegistered = true
resp.MetatxRegistered = true
}
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(req)
json.NewEncoder(w).Encode(resp)
}

// Serve handles server run
Expand Down

0 comments on commit a5484b0

Please sign in to comment.