Merge pull request #2918 from nspcc-dev/any-wrapper-fix

rpcbinding: fix wrappers for Any type, fix #2898
This commit is contained in:
Roman Khimov 2023-02-18 23:15:15 +03:00 committed by GitHub
commit b945f22b13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 2 deletions

View file

@ -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"]

View file

@ -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))

View file

@ -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
}

View file

@ -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":