Skip to content

Commit

Permalink
Merge pull request #12 from rarimo/fix/block_number_gist_data
Browse files Browse the repository at this point in the history
Add block number as query parameter in get gist data endpoint
  • Loading branch information
artemskriabin authored May 16, 2024
2 parents c6eabc3 + ce3d02b commit 9a88abf
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 @@ -44,6 +47,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 9a88abf

Please sign in to comment.