Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order fix for get method #559

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7268,6 +7268,16 @@
},
"type": "array"
}
},
{
"in": "query",
"name": "fix_order",
"required": false,
"schema": {
"default": true,
"description": "A temporary fix to switch to a scheme with direct ordering of arguments. \nIf equal to false, then the method takes arguments in direct order,\ne.g. for get_nft_content(int index, cell individual_content) we pass a list of arguments [index, individual_content].\nIf equal to true, then the method takes arguments in reverse order, e.g. [individual_content, index].",
"type": "boolean"
}
}
],
"responses": {
Expand Down
11 changes: 11 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,17 @@ paths:
items:
type: string
example: [ "0:9a33970f617bcd71acf2cd28357c067aa31859c02820d8f01d74c88063a8f4d8" ]
- name: fix_order
in: query
required: false
schema:
type: boolean
description: |-
A temporary fix to switch to a scheme with direct ordering of arguments.
If equal to false, then the method takes arguments in direct order,
e.g. for get_nft_content(int index, cell individual_content) we pass a list of arguments [index, individual_content].
If equal to true, then the method takes arguments in reverse order, e.g. [individual_content, index].
default: true
responses:
'200':
description: method execution result
Expand Down
13 changes: 9 additions & 4 deletions pkg/api/account_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"golang.org/x/exp/slices"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -200,6 +201,10 @@ func (h *Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params
}
return nil, toError(http.StatusInternalServerError, err)
}
// TODO: remove parameter after user migration
if params.FixOrder.IsSet() && params.FixOrder.Value == true && len(params.Args) > 1 {
slices.Reverse(params.Args)
}
key, err := getMethodCacheKey(account.ID, params.MethodName, contract.LastTransactionLt, params.Args)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand All @@ -208,12 +213,12 @@ func (h *Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params
return result, nil
}
stack := make([]tlb.VmStackValue, 0, len(params.Args))
for _, p := range params.Args {
r, err := stringToTVMStackRecord(p)
for i := len(params.Args) - 1; i >= 0; i-- {
r, err := stringToTVMStackRecord(params.Args[i])
if err != nil {
return nil, toError(http.StatusBadRequest, fmt.Errorf("can't parse arg '%v' as any TVMStackValue", p))
return nil, toError(http.StatusBadRequest, fmt.Errorf("can't parse arg '%v' as any TVMStackValue", params.Args[i]))
}
stack = append(stack, r)
stack = append(stack, r) // we need to put the arguments on the stack in reverse order
}
// RunSmcMethodByID fetches the contract from the storage on its own,
// and it can happen that the contract has been changed and has another lt,
Expand Down
4 changes: 4 additions & 0 deletions pkg/oas/oas_handlers_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions pkg/oas/oas_parameters_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading