rpcbinding: fix wrappers for Any type, fix #2898

This commit is contained in:
Roman Khimov 2023-02-18 00:06:45 +03:00
parent 1bdd62702c
commit b1e7f40226
4 changed files with 16 additions and 2 deletions

View file

@ -1,3 +1,3 @@
name: "Types" name: "Types"
sourceurl: https://github.com/nspcc-dev/neo-go/ 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"]

View file

@ -90,6 +90,16 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
} (unwrap.Item(c.invoker.Call(Hash, "aAAStrings", s))) } (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. // Bool invokes `bool` method of contract.
func (c *ContractReader) Bool(b bool) (bool, error) { func (c *ContractReader) Bool(b bool) (bool, error) {
return unwrap.Bool(c.invoker.Call(Hash, "bool", b)) return unwrap.Bool(c.invoker.Call(Hash, "bool", b))

View file

@ -20,6 +20,10 @@ func String(s string) string {
return "" return ""
} }
func Any(a interface{}) interface{} {
return nil
}
func Hash160(h interop.Hash160) interop.Hash160 { func Hash160(h interop.Hash160) interop.Hash160 {
return nil return nil
} }

View file

@ -565,7 +565,7 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
ctr.HasIterator = true ctr.HasIterator = true
} else { } else {
imports["github.com/nspcc-dev/neo-go/pkg/vm/stackitem"] = struct{}{} 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" ctr.SafeMethods[i].Unwrapper = "Item"
} }
case "bool": case "bool":