Skip to content

Commit

Permalink
Add block number as query parameter in get gist data endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
artemskriabin committed May 16, 2024
1 parent 4f8ce46 commit e0a7f07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions internal/service/api/handlers/get_gist_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion internal/service/api/requests/get_gist_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e0a7f07

Please sign in to comment.