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) {