From ada1068b7f31ff1748a926cfcb77eabe04789354 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 2 Dec 2024 21:16:39 +0300 Subject: [PATCH 1/2] order fix for get method --- api/openapi.json | 10 +++++++ api/openapi.yml | 11 +++++++ pkg/api/account_handlers.go | 13 +++++--- pkg/oas/oas_handlers_gen.go | 4 +++ pkg/oas/oas_parameters_gen.go | 56 +++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) diff --git a/api/openapi.json b/api/openapi.json index 3056bd32..9c768d3f 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -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 is true, then the method takes arguments in reverse order, e.g. [individual_content, index].", + "type": "boolean" + } } ], "responses": { diff --git a/api/openapi.yml b/api/openapi.yml index f7f1be40..67324dd7 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -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 is true, then the method takes arguments in reverse order, e.g. [individual_content, index]. + default: true responses: '200': description: method execution result diff --git a/pkg/api/account_handlers.go b/pkg/api/account_handlers.go index 58ebb5c1..bfc1f164 100644 --- a/pkg/api/account_handlers.go +++ b/pkg/api/account_handlers.go @@ -8,6 +8,7 @@ import ( "encoding/json" "errors" "fmt" + "golang.org/x/exp/slices" "net/http" "sort" "strings" @@ -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) @@ -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, diff --git a/pkg/oas/oas_handlers_gen.go b/pkg/oas/oas_handlers_gen.go index aa846c9b..39ebb97b 100644 --- a/pkg/oas/oas_handlers_gen.go +++ b/pkg/oas/oas_handlers_gen.go @@ -1219,6 +1219,10 @@ func (s *Server) handleExecGetMethodForBlockchainAccountRequest(args [2]string, Name: "args", In: "query", }: params.Args, + { + Name: "fix_order", + In: "query", + }: params.FixOrder, }, Raw: r, } diff --git a/pkg/oas/oas_parameters_gen.go b/pkg/oas/oas_parameters_gen.go index 7b54eaca..b47eb857 100644 --- a/pkg/oas/oas_parameters_gen.go +++ b/pkg/oas/oas_parameters_gen.go @@ -709,6 +709,7 @@ type ExecGetMethodForBlockchainAccountParams struct { // Contract get method name. MethodName string Args []string + FixOrder OptBool } func unpackExecGetMethodForBlockchainAccountParams(packed middleware.Parameters) (params ExecGetMethodForBlockchainAccountParams) { @@ -735,6 +736,15 @@ func unpackExecGetMethodForBlockchainAccountParams(packed middleware.Parameters) params.Args = v.([]string) } } + { + key := middleware.ParameterKey{ + Name: "fix_order", + In: "query", + } + if v, ok := packed[key]; ok { + params.FixOrder = v.(OptBool) + } + } return params } @@ -873,6 +883,52 @@ func decodeExecGetMethodForBlockchainAccountParams(args [2]string, argsEscaped b Err: err, } } + // Set default value for query: fix_order. + { + val := bool(true) + params.FixOrder.SetTo(val) + } + // Decode query: fix_order. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "fix_order", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotFixOrderVal bool + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToBool(val) + if err != nil { + return err + } + + paramsDotFixOrderVal = c + return nil + }(); err != nil { + return err + } + params.FixOrder.SetTo(paramsDotFixOrderVal) + return nil + }); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "fix_order", + In: "query", + Err: err, + } + } return params, nil } From 962bb2fb1ffd3c552dd6eefb883e9eaebbfa3d3f Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 2 Dec 2024 21:18:52 +0300 Subject: [PATCH 2/2] typo fix --- api/openapi.json | 2 +- api/openapi.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/openapi.json b/api/openapi.json index 9c768d3f..03069717 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -7275,7 +7275,7 @@ "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 is true, then the method takes arguments in reverse order, e.g. [individual_content, index].", + "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" } } diff --git a/api/openapi.yml b/api/openapi.yml index 67324dd7..d7f79500 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -405,7 +405,7 @@ paths: 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 is true, then the method takes arguments in reverse order, e.g. [individual_content, index]. + If equal to true, then the method takes arguments in reverse order, e.g. [individual_content, index]. default: true responses: '200':