2022-10-26 20:27:24 +00:00
|
|
|
package rpcbinding
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/binding"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest/standard"
|
|
|
|
)
|
|
|
|
|
|
|
|
const srcTmpl = `
|
2022-10-27 13:20:35 +00:00
|
|
|
{{- define "SAFEMETHOD" -}}
|
2022-10-26 20:27:24 +00:00
|
|
|
// {{.Name}} {{.Comment}}
|
|
|
|
func (c *ContractReader) {{.Name}}({{range $index, $arg := .Arguments -}}
|
|
|
|
{{- if ne $index 0}}, {{end}}
|
|
|
|
{{- .Name}} {{.Type}}
|
|
|
|
{{- end}}) {{if .ReturnType }}({{ .ReturnType }}, error) {
|
|
|
|
return unwrap.{{.CallFlag}}(c.invoker.Call(Hash, "{{ .NameABI }}"{{/* CallFlag field is used for function name */}}
|
|
|
|
{{- range $arg := .Arguments -}}, {{.Name}}{{end}}))
|
|
|
|
{{- else -}} (*result.Invoke, error) {
|
|
|
|
c.invoker.Call(Hash, "{{ .NameABI }}"
|
|
|
|
{{- range $arg := .Arguments -}}, {{.Name}}{{end}})
|
|
|
|
{{- end}}
|
|
|
|
}
|
|
|
|
{{- end -}}
|
2022-10-27 13:20:35 +00:00
|
|
|
{{- define "METHOD" -}}
|
2022-11-07 19:13:47 +00:00
|
|
|
{{- if eq .ReturnType "bool"}}func scriptFor{{.Name}}({{range $index, $arg := .Arguments -}}
|
|
|
|
{{- if ne $index 0}}, {{end}}
|
|
|
|
{{- .Name}} {{.Type}}
|
|
|
|
{{- end}}) ([]byte, error) {
|
|
|
|
return smartcontract.CreateCallWithAssertScript(Hash, "{{ .NameABI }}"{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}})
|
|
|
|
}
|
|
|
|
|
|
|
|
{{end}}// {{.Name}} {{.Comment}}
|
2022-10-27 13:20:35 +00:00
|
|
|
// This transaction is signed and immediately sent to the network.
|
|
|
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
|
|
|
func (c *Contract) {{.Name}}({{range $index, $arg := .Arguments -}}
|
|
|
|
{{- if ne $index 0}}, {{end}}
|
|
|
|
{{- .Name}} {{.Type}}
|
|
|
|
{{- end}}) (util.Uint256, uint32, error) {
|
2022-11-07 19:13:47 +00:00
|
|
|
{{if ne .ReturnType "bool"}}return c.actor.SendCall(Hash, "{{ .NameABI }}"
|
|
|
|
{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}})
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint256{}, 0, err
|
|
|
|
}
|
|
|
|
return c.actor.SendRun(script){{end}}
|
2022-10-27 13:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// {{.Name}}Transaction {{.Comment}}
|
|
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
|
|
// returned to the caller.
|
|
|
|
func (c *Contract) {{.Name}}Transaction({{range $index, $arg := .Arguments -}}
|
|
|
|
{{- if ne $index 0}}, {{end}}
|
|
|
|
{{- .Name}} {{.Type}}
|
|
|
|
{{- end}}) (*transaction.Transaction, error) {
|
2022-11-07 19:13:47 +00:00
|
|
|
{{if ne .ReturnType "bool"}}return c.actor.MakeCall(Hash, "{{ .NameABI }}"
|
|
|
|
{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return c.actor.MakeRun(script){{end}}
|
2022-10-27 13:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// {{.Name}}Unsigned {{.Comment}}
|
|
|
|
// This transaction is not signed, it's simply returned to the caller.
|
|
|
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
|
|
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
|
|
|
func (c *Contract) {{.Name}}Unsigned({{range $index, $arg := .Arguments -}}
|
|
|
|
{{- if ne $index 0}}, {{end}}
|
|
|
|
{{- .Name}} {{.Type}}
|
|
|
|
{{- end}}) (*transaction.Transaction, error) {
|
2022-11-07 19:13:47 +00:00
|
|
|
{{if ne .ReturnType "bool"}}return c.actor.MakeUnsignedCall(Hash, "{{ .NameABI }}", nil
|
|
|
|
{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return c.actor.MakeUnsignedRun(script, nil){{end}}
|
2022-10-27 13:20:35 +00:00
|
|
|
}
|
|
|
|
{{- end -}}
|
2022-10-26 20:27:24 +00:00
|
|
|
// Package {{.PackageName}} contains RPC wrappers for {{.ContractName}} contract.
|
|
|
|
package {{.PackageName}}
|
|
|
|
|
|
|
|
import (
|
|
|
|
{{range $m := .Imports}} "{{ $m }}"
|
|
|
|
{{end}})
|
|
|
|
|
|
|
|
// Hash contains contract hash.
|
|
|
|
var Hash = {{ .Hash }}
|
|
|
|
|
2022-11-08 13:36:38 +00:00
|
|
|
{{if .HasReader}}// Invoker is used by ContractReader to call various safe methods.
|
2022-10-26 20:27:24 +00:00
|
|
|
type Invoker interface {
|
2022-11-08 12:43:32 +00:00
|
|
|
{{if or .IsNep11D .IsNep11ND}} nep11.Invoker
|
|
|
|
{{else if .IsNep17}} nep17.Invoker
|
|
|
|
{{else if len .SafeMethods}} Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error)
|
|
|
|
{{end -}}
|
2022-10-26 20:27:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 13:36:38 +00:00
|
|
|
{{end -}}
|
2022-10-27 13:20:35 +00:00
|
|
|
{{if .HasWriter}}// Actor is used by Contract to call state-changing methods.
|
|
|
|
type Actor interface {
|
2022-11-08 13:36:38 +00:00
|
|
|
{{- if .HasReader}}
|
2022-10-27 13:20:35 +00:00
|
|
|
Invoker
|
2022-11-08 13:36:38 +00:00
|
|
|
{{end}}
|
|
|
|
{{- if or .IsNep11D .IsNep11ND}}
|
|
|
|
nep11.Actor
|
|
|
|
{{else if .IsNep17}}
|
|
|
|
nep17.Actor
|
|
|
|
{{end}}
|
|
|
|
{{- if len .Methods}}
|
|
|
|
MakeCall(contract util.Uint160, method string, params ...interface{}) (*transaction.Transaction, error)
|
2022-10-27 13:20:35 +00:00
|
|
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
|
|
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...interface{}) (*transaction.Transaction, error)
|
|
|
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
|
|
|
SendCall(contract util.Uint160, method string, params ...interface{}) (util.Uint256, uint32, error)
|
|
|
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
|
|
|
{{end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{end -}}
|
2022-11-08 13:36:38 +00:00
|
|
|
{{if .HasReader}}// ContractReader implements safe contract methods.
|
2022-10-26 20:27:24 +00:00
|
|
|
type ContractReader struct {
|
|
|
|
{{if .IsNep11D}}nep11.DivisibleReader
|
|
|
|
{{end -}}
|
|
|
|
{{if .IsNep11ND}}nep11.NonDivisibleReader
|
|
|
|
{{end -}}
|
|
|
|
{{if .IsNep17}}nep17.TokenReader
|
|
|
|
{{end -}}
|
|
|
|
invoker Invoker
|
|
|
|
}
|
|
|
|
|
2022-11-08 13:36:38 +00:00
|
|
|
{{end -}}
|
2022-10-27 13:20:35 +00:00
|
|
|
{{if .HasWriter}}// Contract implements all contract methods.
|
|
|
|
type Contract struct {
|
2022-11-08 13:36:38 +00:00
|
|
|
{{if .HasReader}}ContractReader
|
|
|
|
{{end -}}
|
2022-10-27 13:20:35 +00:00
|
|
|
{{if .IsNep11D}}nep11.DivisibleWriter
|
|
|
|
{{end -}}
|
|
|
|
{{if .IsNep11ND}}nep11.BaseWriter
|
|
|
|
{{end -}}
|
|
|
|
{{if .IsNep17}}nep17.TokenWriter
|
|
|
|
{{end -}}
|
|
|
|
actor Actor
|
|
|
|
}
|
|
|
|
|
|
|
|
{{end -}}
|
2022-11-08 13:36:38 +00:00
|
|
|
{{if .HasReader}}// NewReader creates an instance of ContractReader using Hash and the given Invoker.
|
2022-10-26 20:27:24 +00:00
|
|
|
func NewReader(invoker Invoker) *ContractReader {
|
|
|
|
return &ContractReader{
|
|
|
|
{{- if .IsNep11D}}*nep11.NewDivisibleReader(invoker, Hash), {{end}}
|
|
|
|
{{- if .IsNep11ND}}*nep11.NewNonDivisibleReader(invoker, Hash), {{end}}
|
|
|
|
{{- if .IsNep17}}*nep17.NewReader(invoker, Hash), {{end -}}
|
|
|
|
invoker}
|
|
|
|
}
|
|
|
|
|
2022-11-08 13:36:38 +00:00
|
|
|
{{end -}}
|
2022-10-27 13:20:35 +00:00
|
|
|
{{if .HasWriter}}// New creates an instance of Contract using Hash and the given Actor.
|
|
|
|
func New(actor Actor) *Contract {
|
|
|
|
{{if .IsNep11D}}var nep11dt = nep11.NewDivisible(actor, Hash)
|
|
|
|
{{end -}}
|
|
|
|
{{if .IsNep11ND}}var nep11ndt = nep11.NewNonDivisible(actor, Hash)
|
|
|
|
{{end -}}
|
|
|
|
{{if .IsNep17}}var nep17t = nep17.New(actor, Hash)
|
|
|
|
{{end -}}
|
2022-11-08 13:36:38 +00:00
|
|
|
return &Contract{
|
|
|
|
{{- if .HasReader}}ContractReader{
|
2022-10-27 13:20:35 +00:00
|
|
|
{{- if .IsNep11D}}nep11dt.DivisibleReader, {{end -}}
|
|
|
|
{{- if .IsNep11ND}}nep11ndt.NonDivisibleReader, {{end -}}
|
|
|
|
{{- if .IsNep17}}nep17t.TokenReader, {{end -}}
|
2022-11-08 13:36:38 +00:00
|
|
|
actor}, {{end -}}
|
2022-10-27 13:20:35 +00:00
|
|
|
{{- if .IsNep11D}}nep11dt.DivisibleWriter, {{end -}}
|
|
|
|
{{- if .IsNep11ND}}nep11ndt.BaseWriter, {{end -}}
|
|
|
|
{{- if .IsNep17}}nep17t.TokenWriter, {{end -}}
|
|
|
|
actor}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{end -}}
|
|
|
|
{{range $m := .SafeMethods}}
|
|
|
|
{{template "SAFEMETHOD" $m }}
|
|
|
|
{{end}}
|
|
|
|
{{- range $m := .Methods}}
|
2022-10-26 20:27:24 +00:00
|
|
|
{{template "METHOD" $m }}
|
|
|
|
{{end}}`
|
|
|
|
|
|
|
|
var srcTemplate = template.Must(template.New("generate").Parse(srcTmpl))
|
|
|
|
|
|
|
|
type (
|
|
|
|
ContractTmpl struct {
|
|
|
|
binding.ContractTmpl
|
2022-10-27 13:20:35 +00:00
|
|
|
|
|
|
|
SafeMethods []binding.MethodTmpl
|
|
|
|
|
2022-10-26 20:27:24 +00:00
|
|
|
IsNep11D bool
|
|
|
|
IsNep11ND bool
|
|
|
|
IsNep17 bool
|
2022-10-27 13:20:35 +00:00
|
|
|
|
2022-11-08 13:36:38 +00:00
|
|
|
HasReader bool
|
2022-10-27 13:20:35 +00:00
|
|
|
HasWriter bool
|
2022-10-26 20:27:24 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewConfig initializes and returns a new config instance.
|
|
|
|
func NewConfig() binding.Config {
|
|
|
|
return binding.NewConfig()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate writes Go file containing smartcontract bindings to the `cfg.Output`.
|
|
|
|
func Generate(cfg binding.Config) error {
|
2022-11-08 12:43:32 +00:00
|
|
|
// Avoid changing *cfg.Manifest.
|
|
|
|
mfst := *cfg.Manifest
|
|
|
|
mfst.ABI.Methods = make([]manifest.Method, len(mfst.ABI.Methods))
|
|
|
|
copy(mfst.ABI.Methods, cfg.Manifest.ABI.Methods)
|
|
|
|
cfg.Manifest = &mfst
|
|
|
|
|
|
|
|
var imports = make(map[string]struct{})
|
|
|
|
var ctr ContractTmpl
|
|
|
|
|
|
|
|
// Strip standard methods from NEP-XX packages.
|
|
|
|
for _, std := range cfg.Manifest.SupportedStandards {
|
|
|
|
if std == manifest.NEP11StandardName {
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"] = struct{}{}
|
|
|
|
if standard.ComplyABI(cfg.Manifest, standard.Nep11Divisible) == nil {
|
|
|
|
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep11Divisible)
|
|
|
|
ctr.IsNep11D = true
|
|
|
|
} else if standard.ComplyABI(cfg.Manifest, standard.Nep11NonDivisible) == nil {
|
|
|
|
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep11NonDivisible)
|
|
|
|
ctr.IsNep11ND = true
|
|
|
|
}
|
|
|
|
break // Can't be NEP-17 at the same time.
|
|
|
|
}
|
|
|
|
if std == manifest.NEP17StandardName && standard.ComplyABI(cfg.Manifest, standard.Nep17) == nil {
|
|
|
|
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep17)
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"] = struct{}{}
|
|
|
|
ctr.IsNep17 = true
|
|
|
|
break // Can't be NEP-11 at the same time.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 14:00:26 +00:00
|
|
|
// OnNepXXPayment handlers normally can't be called directly.
|
|
|
|
if standard.ComplyABI(cfg.Manifest, standard.Nep11Payable) == nil {
|
|
|
|
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep11Payable)
|
|
|
|
}
|
|
|
|
if standard.ComplyABI(cfg.Manifest, standard.Nep17Payable) == nil {
|
|
|
|
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep17Payable)
|
|
|
|
}
|
|
|
|
|
2022-10-26 20:27:24 +00:00
|
|
|
bctr, err := binding.TemplateFromManifest(cfg, scTypeToGo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-08 12:43:32 +00:00
|
|
|
ctr.ContractTmpl = bctr
|
|
|
|
ctr = scTemplateToRPC(cfg, ctr, imports)
|
2022-10-26 20:27:24 +00:00
|
|
|
|
|
|
|
return srcTemplate.Execute(cfg.Output, ctr)
|
|
|
|
}
|
|
|
|
|
2022-11-08 12:43:32 +00:00
|
|
|
func dropManifestMethods(meths []manifest.Method, manifested []manifest.Method) []manifest.Method {
|
2022-10-26 20:27:24 +00:00
|
|
|
for _, m := range manifested {
|
|
|
|
for i := 0; i < len(meths); i++ {
|
2022-11-08 12:43:32 +00:00
|
|
|
if meths[i].Name == m.Name && len(meths[i].Parameters) == len(m.Parameters) {
|
2022-10-26 20:27:24 +00:00
|
|
|
meths = append(meths[:i], meths[i+1:]...)
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return meths
|
|
|
|
}
|
|
|
|
|
2022-11-08 12:43:32 +00:00
|
|
|
func dropStdMethods(meths []manifest.Method, std *standard.Standard) []manifest.Method {
|
2022-10-26 20:27:24 +00:00
|
|
|
meths = dropManifestMethods(meths, std.Manifest.ABI.Methods)
|
|
|
|
if std.Optional != nil {
|
|
|
|
meths = dropManifestMethods(meths, std.Optional)
|
|
|
|
}
|
|
|
|
if std.Base != nil {
|
|
|
|
return dropStdMethods(meths, std.Base)
|
|
|
|
}
|
|
|
|
return meths
|
|
|
|
}
|
|
|
|
|
|
|
|
func scTypeToGo(name string, typ smartcontract.ParamType, overrides map[string]binding.Override) (string, string) {
|
|
|
|
switch typ {
|
|
|
|
case smartcontract.AnyType:
|
|
|
|
return "interface{}", ""
|
|
|
|
case smartcontract.BoolType:
|
|
|
|
return "bool", ""
|
|
|
|
case smartcontract.IntegerType:
|
|
|
|
return "*big.Int", "math/big"
|
|
|
|
case smartcontract.ByteArrayType:
|
|
|
|
return "[]byte", ""
|
|
|
|
case smartcontract.StringType:
|
|
|
|
return "string", ""
|
|
|
|
case smartcontract.Hash160Type:
|
|
|
|
return "util.Uint160", "github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
case smartcontract.Hash256Type:
|
|
|
|
return "util.Uint256", "github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
case smartcontract.PublicKeyType:
|
|
|
|
return "*keys.PublicKey", "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
case smartcontract.SignatureType:
|
|
|
|
return "[]byte", ""
|
|
|
|
case smartcontract.ArrayType:
|
|
|
|
return "[]interface{}", ""
|
|
|
|
case smartcontract.MapType:
|
|
|
|
return "*stackitem.Map", "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
case smartcontract.InteropInterfaceType:
|
|
|
|
return "interface{}", ""
|
|
|
|
case smartcontract.VoidType:
|
|
|
|
return "", ""
|
|
|
|
default:
|
|
|
|
panic("unreachable")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 12:43:32 +00:00
|
|
|
func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]struct{}) ContractTmpl {
|
2022-10-26 20:27:24 +00:00
|
|
|
for i := range ctr.Imports {
|
|
|
|
imports[ctr.Imports[i]] = struct{}{}
|
|
|
|
}
|
|
|
|
ctr.Hash = fmt.Sprintf("%#v", cfg.Hash)
|
|
|
|
for i := 0; i < len(ctr.Methods); i++ {
|
|
|
|
abim := cfg.Manifest.ABI.GetMethod(ctr.Methods[i].NameABI, len(ctr.Methods[i].Arguments))
|
2022-10-27 13:20:35 +00:00
|
|
|
if abim.Safe {
|
|
|
|
ctr.SafeMethods = append(ctr.SafeMethods, ctr.Methods[i])
|
2022-10-26 20:27:24 +00:00
|
|
|
ctr.Methods = append(ctr.Methods[:i], ctr.Methods[i+1:]...)
|
|
|
|
i--
|
2022-10-27 13:20:35 +00:00
|
|
|
} else {
|
|
|
|
ctr.Methods[i].Comment = fmt.Sprintf("creates a transaction invoking `%s` method of the contract.", ctr.Methods[i].NameABI)
|
2022-11-07 19:13:47 +00:00
|
|
|
if ctr.Methods[i].ReturnType == "bool" {
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/smartcontract"] = struct{}{}
|
|
|
|
}
|
2022-10-26 20:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// We're misusing CallFlag field for function name here.
|
2022-10-27 13:20:35 +00:00
|
|
|
for i := range ctr.SafeMethods {
|
|
|
|
switch ctr.SafeMethods[i].ReturnType {
|
2022-10-26 20:27:24 +00:00
|
|
|
case "interface{}":
|
2022-11-09 07:20:44 +00:00
|
|
|
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{}{}
|
|
|
|
ctr.SafeMethods[i].ReturnType = "stackitem.Item"
|
|
|
|
ctr.SafeMethods[i].CallFlag = "Item"
|
|
|
|
}
|
2022-10-26 20:27:24 +00:00
|
|
|
case "bool":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "Bool"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "*big.Int":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "BigInt"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "string":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "UTF8String"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "util.Uint160":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "Uint160"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "util.Uint256":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "Uint256"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "*keys.PublicKey":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "PublicKey"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "[]byte":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "Bytes"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "[]interface{}":
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/vm/stackitem"] = struct{}{}
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].ReturnType = "[]stackitem.Item"
|
|
|
|
ctr.SafeMethods[i].CallFlag = "Array"
|
2022-10-26 20:27:24 +00:00
|
|
|
case "*stackitem.Map":
|
2022-10-27 13:20:35 +00:00
|
|
|
ctr.SafeMethods[i].CallFlag = "Map"
|
2022-10-26 20:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 12:43:32 +00:00
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/util"] = struct{}{}
|
2022-10-27 13:20:35 +00:00
|
|
|
if len(ctr.SafeMethods) > 0 {
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"] = struct{}{}
|
2022-11-08 12:43:32 +00:00
|
|
|
if !(ctr.IsNep17 || ctr.IsNep11D || ctr.IsNep11ND) {
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/neorpc/result"] = struct{}{}
|
|
|
|
}
|
2022-10-27 13:20:35 +00:00
|
|
|
}
|
|
|
|
if len(ctr.Methods) > 0 {
|
|
|
|
imports["github.com/nspcc-dev/neo-go/pkg/core/transaction"] = struct{}{}
|
|
|
|
}
|
|
|
|
if len(ctr.Methods) > 0 || ctr.IsNep17 || ctr.IsNep11D || ctr.IsNep11ND {
|
|
|
|
ctr.HasWriter = true
|
|
|
|
}
|
2022-11-08 13:36:38 +00:00
|
|
|
if len(ctr.SafeMethods) > 0 || ctr.IsNep17 || ctr.IsNep11D || ctr.IsNep11ND {
|
|
|
|
ctr.HasReader = true
|
|
|
|
}
|
2022-10-26 20:27:24 +00:00
|
|
|
ctr.Imports = ctr.Imports[:0]
|
|
|
|
for imp := range imports {
|
|
|
|
ctr.Imports = append(ctr.Imports, imp)
|
|
|
|
}
|
|
|
|
sort.Strings(ctr.Imports)
|
|
|
|
return ctr
|
|
|
|
}
|