Skip to content

Commit

Permalink
API: add stats flag to contracts endpoint (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Feb 10, 2023
1 parent e63c562 commit 8074ab8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/api/handlers/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func GetContract() gin.HandlerFunc {
return
}

var args withStatsRequest
if err := c.BindQuery(&args); handleError(c, ctx.Storage, err, http.StatusNotFound) {
return
}

contract, err := ctx.Contracts.Get(req.Address)
if err != nil {
if ctx.Storage.IsRecordNotFound(err) {
Expand All @@ -44,11 +49,19 @@ func GetContract() gin.HandlerFunc {

ctxs := c.MustGet("contexts").(config.Contexts)

res, err := contractWithStatsPostprocessing(ctxs, ctx, contract)
if handleError(c, ctx.Storage, err, 0) {
return
if args.HasStats() {
res, err := contractWithStatsPostprocessing(ctxs, ctx, contract)
if handleError(c, ctx.Storage, err, 0) {
return
}
c.SecureJSON(http.StatusOK, res)
} else {
res, err := contractPostprocessing(ctx, contract)
if handleError(c, ctx.Storage, err, 0) {
return
}
c.SecureJSON(http.StatusOK, res)
}
c.SecureJSON(http.StatusOK, res)
}
}

Expand Down
9 changes: 9 additions & 0 deletions cmd/api/handlers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ type getContractCodeRequest struct {
Level int64 `form:"level,omitempty"`
}

type withStatsRequest struct {
Stats *bool `form:"stats,omitempty" binding:"omitempty"`
}

// HasStats -
func (req withStatsRequest) HasStats() bool {
return req.Stats == nil || *req.Stats
}

type networkQueryRequest struct {
Network string `form:"network,omitempty" binding:"omitempty,network"`
}
Expand Down

0 comments on commit 8074ab8

Please sign in to comment.