mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
rpcbinding: initial support for iterators, see #2768
Already better than stackitem.Item.
This commit is contained in:
parent
57ec67b375
commit
d569fe01e6
3 changed files with 21 additions and 9 deletions
11
cli/smartcontract/testdata/nameservice/nns.go
vendored
11
cli/smartcontract/testdata/nameservice/nns.go
vendored
|
@ -2,12 +2,13 @@
|
||||||
package nameservice
|
package nameservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,8 +60,8 @@ func New(actor Actor) *Contract {
|
||||||
|
|
||||||
|
|
||||||
// Roots invokes `roots` method of contract.
|
// Roots invokes `roots` method of contract.
|
||||||
func (c *ContractReader) Roots() (stackitem.Item, error) {
|
func (c *ContractReader) Roots() (uuid.UUID, result.Iterator, error) {
|
||||||
return unwrap.Item(c.invoker.Call(Hash, "roots"))
|
return unwrap.SessionIterator(c.invoker.Call(Hash, "roots"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPrice invokes `getPrice` method of contract.
|
// GetPrice invokes `getPrice` method of contract.
|
||||||
|
@ -79,8 +80,8 @@ func (c *ContractReader) GetRecord(name string, typev *big.Int) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllRecords invokes `getAllRecords` method of contract.
|
// GetAllRecords invokes `getAllRecords` method of contract.
|
||||||
func (c *ContractReader) GetAllRecords(name string) (stackitem.Item, error) {
|
func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator, error) {
|
||||||
return unwrap.Item(c.invoker.Call(Hash, "getAllRecords", name))
|
return unwrap.SessionIterator(c.invoker.Call(Hash, "getAllRecords", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve invokes `resolve` method of contract.
|
// Resolve invokes `resolve` method of contract.
|
||||||
|
|
|
@ -449,7 +449,10 @@ returns false.
|
||||||
If your contract is NEP-11 or NEP-17 that's autodetected and an appropriate
|
If your contract is NEP-11 or NEP-17 that's autodetected and an appropriate
|
||||||
package is included as well. Notice that the type data available in the
|
package is included as well. Notice that the type data available in the
|
||||||
manifest is limited, so in some cases the interface generated may use generic
|
manifest is limited, so in some cases the interface generated may use generic
|
||||||
stackitem types. Iterators are not supported yet.
|
stackitem types. Any InteropInterface returned from a method is treated as
|
||||||
|
iterator and an appropriate unwrapper is used with UUID and iterator structure
|
||||||
|
result. This pair can then be used in Invoker `TraverseIterator` method to
|
||||||
|
retrieve actual resulting items.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ ./bin/neo-go contract generate-rpcwrapper --manifest manifest.json --out rpcwrapper.go --hash 0x1b4357bff5a01bdf2a6581247cf9ed1e24629176
|
$ ./bin/neo-go contract generate-rpcwrapper --manifest manifest.json --out rpcwrapper.go --hash 0x1b4357bff5a01bdf2a6581247cf9ed1e24629176
|
||||||
|
|
|
@ -334,9 +334,17 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
|
||||||
for i := range ctr.SafeMethods {
|
for i := range ctr.SafeMethods {
|
||||||
switch ctr.SafeMethods[i].ReturnType {
|
switch ctr.SafeMethods[i].ReturnType {
|
||||||
case "interface{}":
|
case "interface{}":
|
||||||
|
abim := cfg.Manifest.ABI.GetMethod(ctr.SafeMethods[i].NameABI, len(ctr.SafeMethods[i].Arguments))
|
||||||
|
if abim.ReturnType == smartcontract.InteropInterfaceType {
|
||||||
|
imports["github.com/google/uuid"] = struct{}{}
|
||||||
|
imports["github.com/nspcc-dev/neo-go/pkg/neorpc/result"] = struct{}{}
|
||||||
|
ctr.SafeMethods[i].ReturnType = "uuid.UUID, result.Iterator"
|
||||||
|
ctr.SafeMethods[i].CallFlag = "SessionIterator"
|
||||||
|
} 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 = "stackitem.Item"
|
||||||
ctr.SafeMethods[i].CallFlag = "Item"
|
ctr.SafeMethods[i].CallFlag = "Item"
|
||||||
|
}
|
||||||
case "bool":
|
case "bool":
|
||||||
ctr.SafeMethods[i].CallFlag = "Bool"
|
ctr.SafeMethods[i].CallFlag = "Bool"
|
||||||
case "*big.Int":
|
case "*big.Int":
|
||||||
|
|
Loading…
Reference in a new issue