From b1e7f40226eac46878f79488dac62e33ffeed812 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 18 Feb 2023 00:06:45 +0300 Subject: [PATCH] rpcbinding: fix wrappers for Any type, fix #2898 --- cli/smartcontract/testdata/types/config.yml | 2 +- cli/smartcontract/testdata/types/rpcbindings.out | 10 ++++++++++ cli/smartcontract/testdata/types/types.go | 4 ++++ pkg/smartcontract/rpcbinding/binding.go | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cli/smartcontract/testdata/types/config.yml b/cli/smartcontract/testdata/types/config.yml index a36d2e655..b97936c40 100644 --- a/cli/smartcontract/testdata/types/config.yml +++ b/cli/smartcontract/testdata/types/config.yml @@ -1,3 +1,3 @@ name: "Types" sourceurl: https://github.com/nspcc-dev/neo-go/ -safemethods: ["bool", "int", "bytes", "string", "hash160", "hash256", "publicKey", "signature", "bools", "ints", "bytess", "strings", "hash160s", "hash256s", "publicKeys", "signatures", "aAAStrings", "maps", "crazyMaps"] +safemethods: ["bool", "int", "bytes", "string", "any", "hash160", "hash256", "publicKey", "signature", "bools", "ints", "bytess", "strings", "hash160s", "hash256s", "publicKeys", "signatures", "aAAStrings", "maps", "crazyMaps"] diff --git a/cli/smartcontract/testdata/types/rpcbindings.out b/cli/smartcontract/testdata/types/rpcbindings.out index 602e589ac..2b419a2ad 100644 --- a/cli/smartcontract/testdata/types/rpcbindings.out +++ b/cli/smartcontract/testdata/types/rpcbindings.out @@ -90,6 +90,16 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) { } (unwrap.Item(c.invoker.Call(Hash, "aAAStrings", s))) } +// Any invokes `any` method of contract. +func (c *ContractReader) Any(a interface{}) (interface{}, error) { + return func (item stackitem.Item, err error) (interface{}, error) { + if err != nil { + return nil, err + } + return item.Value(), nil + } (unwrap.Item(c.invoker.Call(Hash, "any", a))) +} + // Bool invokes `bool` method of contract. func (c *ContractReader) Bool(b bool) (bool, error) { return unwrap.Bool(c.invoker.Call(Hash, "bool", b)) diff --git a/cli/smartcontract/testdata/types/types.go b/cli/smartcontract/testdata/types/types.go index 2d97dd081..f59aac0e8 100644 --- a/cli/smartcontract/testdata/types/types.go +++ b/cli/smartcontract/testdata/types/types.go @@ -20,6 +20,10 @@ func String(s string) string { return "" } +func Any(a interface{}) interface{} { + return nil +} + func Hash160(h interop.Hash160) interop.Hash160 { return nil } diff --git a/pkg/smartcontract/rpcbinding/binding.go b/pkg/smartcontract/rpcbinding/binding.go index b447c1dd0..b8f53d91a 100644 --- a/pkg/smartcontract/rpcbinding/binding.go +++ b/pkg/smartcontract/rpcbinding/binding.go @@ -565,7 +565,7 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st ctr.HasIterator = true } else { imports["github.com/nspcc-dev/neo-go/pkg/vm/stackitem"] = struct{}{} - ctr.SafeMethods[i].ReturnType = "stackitem.Item" + ctr.SafeMethods[i].ReturnType = "interface{}" ctr.SafeMethods[i].Unwrapper = "Item" } case "bool":