Skip to content

Commit

Permalink
Added: query parameter with_storage_diff to operations endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanSerikov authored and m-kus committed Nov 5, 2020
1 parent fbf20cf commit bbcccfc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
31 changes: 20 additions & 11 deletions cmd/api/handlers/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
// @Param size query integer false "Expected OPG count" mininum(1)
// @Param status query string false "Comma-separated operations statuses"
// @Param entrypoints query string false "Comma-separated called entrypoints list"
// @Param with_storage_diff query bool false "Include storage diff to operations or not"
// @Accept json
// @Produce json
// @Success 200 {object} OperationResponse
Expand All @@ -57,7 +58,7 @@ func (ctx *Context) GetContractOperations(c *gin.Context) {
return
}

resp, err := PrepareOperations(ctx.ES, ops.Operations)
resp, err := PrepareOperations(ctx.ES, ops.Operations, filtersReq.WithStorageDiff)
if handleError(c, err, 0) {
return
}
Expand Down Expand Up @@ -102,7 +103,7 @@ func (ctx *Context) GetOperation(c *gin.Context) {
return
}

resp, err := PrepareOperations(ctx.ES, op)
resp, err := PrepareOperations(ctx.ES, op, true)
if handleError(c, err, 0) {
return
}
Expand Down Expand Up @@ -219,7 +220,7 @@ func formatErrors(errs []cerrors.IError, op *Operation) error {
return nil
}

func prepareOperation(es elastic.IElastic, operation models.Operation, bmd []models.BigMapDiff) (Operation, error) {
func prepareOperation(es elastic.IElastic, operation models.Operation, bmd []models.BigMapDiff, withStorageDiff bool) (Operation, error) {
var op Operation
op.FromModel(operation)

Expand All @@ -230,9 +231,11 @@ func prepareOperation(es elastic.IElastic, operation models.Operation, bmd []mod
if err := formatErrors(operation.Errors, &op); err != nil {
return op, err
}
if operation.DeffatedStorage != "" && strings.HasPrefix(op.Destination, "KT") && op.Status == consts.Applied {
if err := setStorageDiff(es, op.Destination, operation.DeffatedStorage, &op, bmd); err != nil {
return op, err
if withStorageDiff {
if operation.DeffatedStorage != "" && strings.HasPrefix(op.Destination, "KT") && op.Status == consts.Applied {
if err := setStorageDiff(es, op.Destination, operation.DeffatedStorage, &op, bmd); err != nil {
return op, err
}
}
}

Expand All @@ -250,14 +253,20 @@ func prepareOperation(es elastic.IElastic, operation models.Operation, bmd []mod
}

// PrepareOperations -
func PrepareOperations(es elastic.IElastic, ops []models.Operation) ([]Operation, error) {
func PrepareOperations(es elastic.IElastic, ops []models.Operation, withStorageDiff bool) ([]Operation, error) {
resp := make([]Operation, len(ops))
for i := 0; i < len(ops); i++ {
bmd, err := es.GetBigMapDiffsUniqueByOperationID(ops[i].ID)
if err != nil {
return nil, err
var bmd []models.BigMapDiff
var err error

if withStorageDiff {
bmd, err = es.GetBigMapDiffsUniqueByOperationID(ops[i].ID)
if err != nil {
return nil, err
}
}
op, err := prepareOperation(es, ops[i], bmd)

op, err := prepareOperation(es, ops[i], bmd, withStorageDiff)
if err != nil {
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/api/handlers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ type OauthParams struct {
}

type operationsRequest struct {
LastID string `form:"last_id" binding:"omitempty,numeric"`
From uint `form:"from" binding:"omitempty"`
To uint `form:"to" binding:"omitempty,gtfield=From"`
Size uint64 `form:"size" binding:"min=0"`
Status string `form:"status" binding:"omitempty,status"`
Entrypoints string `form:"entrypoints" binding:"omitempty,excludesall=\"'"`
LastID string `form:"last_id" binding:"omitempty,numeric"`
From uint `form:"from" binding:"omitempty"`
To uint `form:"to" binding:"omitempty,gtfield=From"`
Size uint64 `form:"size" binding:"min=0"`
Status string `form:"status" binding:"omitempty,status"`
Entrypoints string `form:"entrypoints" binding:"omitempty,excludesall=\"'"`
WithStorageDiff bool `form:"with_storage_diff"`
}

type pageableRequest struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/handlers/run_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (ctx *Context) RunOperation(c *gin.Context) {
bmd = append(bmd, *diffs[j])
}
}
op, err := prepareOperation(ctx.ES, *operations[i], bmd)
op, err := prepareOperation(ctx.ES, *operations[i], bmd, true)
if handleError(c, err, 0) {
return
}
Expand Down

0 comments on commit bbcccfc

Please sign in to comment.