Skip to content

Commit 1c9c1ee

Browse files
authored
Merge pull request #559 from tonkeeper/order-fix-for-get-method
Order fix for get method
2 parents 4519d58 + 962bb2f commit 1c9c1ee

5 files changed

+90
-4
lines changed

api/openapi.json

+10
Original file line numberDiff line numberDiff line change
@@ -7268,6 +7268,16 @@
72687268
},
72697269
"type": "array"
72707270
}
7271+
},
7272+
{
7273+
"in": "query",
7274+
"name": "fix_order",
7275+
"required": false,
7276+
"schema": {
7277+
"default": true,
7278+
"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].",
7279+
"type": "boolean"
7280+
}
72717281
}
72727282
],
72737283
"responses": {

api/openapi.yml

+11
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,17 @@ paths:
396396
items:
397397
type: string
398398
example: [ "0:9a33970f617bcd71acf2cd28357c067aa31859c02820d8f01d74c88063a8f4d8" ]
399+
- name: fix_order
400+
in: query
401+
required: false
402+
schema:
403+
type: boolean
404+
description: |-
405+
A temporary fix to switch to a scheme with direct ordering of arguments.
406+
If equal to false, then the method takes arguments in direct order,
407+
e.g. for get_nft_content(int index, cell individual_content) we pass a list of arguments [index, individual_content].
408+
If equal to true, then the method takes arguments in reverse order, e.g. [individual_content, index].
409+
default: true
399410
responses:
400411
'200':
401412
description: method execution result

pkg/api/account_handlers.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"errors"
1010
"fmt"
11+
"golang.org/x/exp/slices"
1112
"net/http"
1213
"sort"
1314
"strings"
@@ -200,6 +201,10 @@ func (h *Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params
200201
}
201202
return nil, toError(http.StatusInternalServerError, err)
202203
}
204+
// TODO: remove parameter after user migration
205+
if params.FixOrder.IsSet() && params.FixOrder.Value == true && len(params.Args) > 1 {
206+
slices.Reverse(params.Args)
207+
}
203208
key, err := getMethodCacheKey(account.ID, params.MethodName, contract.LastTransactionLt, params.Args)
204209
if err != nil {
205210
return nil, toError(http.StatusInternalServerError, err)
@@ -208,12 +213,12 @@ func (h *Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params
208213
return result, nil
209214
}
210215
stack := make([]tlb.VmStackValue, 0, len(params.Args))
211-
for _, p := range params.Args {
212-
r, err := stringToTVMStackRecord(p)
216+
for i := len(params.Args) - 1; i >= 0; i-- {
217+
r, err := stringToTVMStackRecord(params.Args[i])
213218
if err != nil {
214-
return nil, toError(http.StatusBadRequest, fmt.Errorf("can't parse arg '%v' as any TVMStackValue", p))
219+
return nil, toError(http.StatusBadRequest, fmt.Errorf("can't parse arg '%v' as any TVMStackValue", params.Args[i]))
215220
}
216-
stack = append(stack, r)
221+
stack = append(stack, r) // we need to put the arguments on the stack in reverse order
217222
}
218223
// RunSmcMethodByID fetches the contract from the storage on its own,
219224
// and it can happen that the contract has been changed and has another lt,

pkg/oas/oas_handlers_gen.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oas/oas_parameters_gen.go

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)