From e0a7f0735abcdbab44caf00918897d156731fbc3 Mon Sep 17 00:00:00 2001 From: Artem Skriabin Date: Thu, 16 May 2024 16:37:38 +0300 Subject: [PATCH] Add block number as query parameter in get gist data endpoint --- internal/service/api/handlers/get_gist_data.go | 18 ++++++++++++++++++ internal/service/api/requests/get_gist_data.go | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/service/api/handlers/get_gist_data.go b/internal/service/api/handlers/get_gist_data.go index ff5d23c..8360bdc 100644 --- a/internal/service/api/handlers/get_gist_data.go +++ b/internal/service/api/handlers/get_gist_data.go @@ -2,6 +2,9 @@ package handlers import ( "context" + validation "github.com/go-ozzo/ozzo-validation/v4" + "gitlab.com/distributed_lab/logan/v3" + "gitlab.com/distributed_lab/logan/v3/errors" "math/big" "net/http" @@ -43,6 +46,21 @@ func GetGistData(w http.ResponseWriter, r *http.Request) { return } + if req.BlockNumber > blockNum { + Log(r).WithFields(logan.F{ + "requested_block_number": req.BlockNumber, + "latest_block_number": blockNum, + }).Error("Requested block number is higher than latest") + ape.RenderErr(w, problems.BadRequest(validation.Errors{ + "/block_number": errors.New("Requested block number is higher than latest"), + })...) + return + } + + if req.BlockNumber != 0 { + blockNum = req.BlockNumber + } + stateContract := StateContract(r) gistProof, err := stateContract.GetGISTProof(&bind.CallOpts{ diff --git a/internal/service/api/requests/get_gist_data.go b/internal/service/api/requests/get_gist_data.go index ca859d9..767ba30 100644 --- a/internal/service/api/requests/get_gist_data.go +++ b/internal/service/api/requests/get_gist_data.go @@ -8,7 +8,8 @@ import ( ) type GetGistDataRequest struct { - UserDID string `url:"user_did"` + UserDID string `url:"user_did"` + BlockNumber uint64 `url:"block_number"` } func NewGetGistDataRequest(r *http.Request) (GetGistDataRequest, error) {