diff --git a/cmd/api/handlers/contract.go b/cmd/api/handlers/contract.go index b28068985..f45bf20db 100644 --- a/cmd/api/handlers/contract.go +++ b/cmd/api/handlers/contract.go @@ -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) { @@ -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) } } diff --git a/cmd/api/handlers/requests.go b/cmd/api/handlers/requests.go index 9b62ce0dc..1c64df3b4 100644 --- a/cmd/api/handlers/requests.go +++ b/cmd/api/handlers/requests.go @@ -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"` }