parent
d569fe01e6
commit
a7f86dcb7f
5 changed files with 138 additions and 3 deletions
|
@ -25,6 +25,17 @@ func (c *ContractReader) {{.Name}}({{range $index, $arg := .Arguments -}}
|
|||
{{- range $arg := .Arguments -}}, {{.Name}}{{end}})
|
||||
{{- end}}
|
||||
}
|
||||
{{- if eq .CallFlag "SessionIterator"}}
|
||||
|
||||
// {{.Name}}Expanded is similar to {{.Name}} (uses the same contract
|
||||
// method), but can be useful if the server used doesn't support sessions and
|
||||
// doesn't expand iterators. It creates a script that will get the specified
|
||||
// number of result items from the iterator right in the VM and return them to
|
||||
// you. It's only limited by VM stack and GAS available for RPC invocations.
|
||||
func (c *ContractReader) {{.Name}}Expanded({{range $index, $arg := .Arguments}}{{.Name}} {{.Type}}, {{end}}_numOfIteratorItems int) ([]stackitem.Item, error) {
|
||||
return unwrap.Array(c.invoker.CallAndExpandIterator(Hash, "{{.NameABI}}", _numOfIteratorItems{{range $arg := .Arguments}}, {{.Name}}{{end}}))
|
||||
}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- define "METHOD" -}}
|
||||
{{- if eq .ReturnType "bool"}}func scriptFor{{.Name}}({{range $index, $arg := .Arguments -}}
|
||||
|
@ -93,9 +104,15 @@ var Hash = {{ .Hash }}
|
|||
{{if .HasReader}}// Invoker is used by ContractReader to call various safe methods.
|
||||
type Invoker interface {
|
||||
{{if or .IsNep11D .IsNep11ND}} nep11.Invoker
|
||||
{{else if .IsNep17}} nep17.Invoker
|
||||
{{else -}}
|
||||
{{ if .IsNep17}} nep17.Invoker
|
||||
{{else if len .SafeMethods}} Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error)
|
||||
{{end -}}
|
||||
{{if .HasIterator}} CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...interface{}) (*result.Invoke, error)
|
||||
TerminateSession(sessionID uuid.UUID) error
|
||||
TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
|
||||
{{end -}}
|
||||
{{end -}}
|
||||
}
|
||||
|
||||
{{end -}}
|
||||
|
@ -196,8 +213,9 @@ type (
|
|||
IsNep11ND bool
|
||||
IsNep17 bool
|
||||
|
||||
HasReader bool
|
||||
HasWriter bool
|
||||
HasReader bool
|
||||
HasWriter bool
|
||||
HasIterator bool
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -337,9 +355,11 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
|
|||
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/vm/stackitem"] = 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"
|
||||
ctr.HasIterator = true
|
||||
} else {
|
||||
imports["github.com/nspcc-dev/neo-go/pkg/vm/stackitem"] = struct{}{}
|
||||
ctr.SafeMethods[i].ReturnType = "stackitem.Item"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue