From 145ebad90e0d32bcafe435993b429fb745aab331 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 9 Nov 2022 12:44:14 +0300 Subject: [PATCH] binding: drop the only error condition from TemplateFromManifest Simplify the interface, we do IsValid() check anyway in the CLI and it covers this condition as well. --- pkg/smartcontract/binding/generate.go | 18 +++++++----------- pkg/smartcontract/rpcbinding/binding.go | 8 +++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pkg/smartcontract/binding/generate.go b/pkg/smartcontract/binding/generate.go index e2f3aeb66..97b1fdbfb 100644 --- a/pkg/smartcontract/binding/generate.go +++ b/pkg/smartcontract/binding/generate.go @@ -90,11 +90,10 @@ func NewConfig() Config { } // Generate writes Go file containing smartcontract bindings to the `cfg.Output`. +// It doesn't check manifest from Config for validity, incorrect manifest can +// lead to unexpected results. func Generate(cfg Config) error { - ctr, err := TemplateFromManifest(cfg, scTypeToGo) - if err != nil { - return err - } + ctr := TemplateFromManifest(cfg, scTypeToGo) ctr.Imports = append(ctr.Imports, "github.com/nspcc-dev/neo-go/pkg/interop/contract") ctr.Imports = append(ctr.Imports, "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal") sort.Strings(ctr.Imports) @@ -140,8 +139,9 @@ func scTypeToGo(name string, typ smartcontract.ParamType, overrides map[string]O } // TemplateFromManifest create a contract template using the given configuration -// and type conversion function. -func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract.ParamType, map[string]Override) (string, string)) (ContractTmpl, error) { +// and type conversion function. It assumes manifest to be present in the +// configuration and assumes it to be correct (passing IsValid check). +func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract.ParamType, map[string]Override) (string, string)) ContractTmpl { hStr := "" for _, b := range cfg.Hash.BytesBE() { hStr += fmt.Sprintf("\\x%02x", b) @@ -203,10 +203,6 @@ func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract var varnames = make(map[string]bool) for i := range m.Parameters { name := m.Parameters[i].Name - if name == "" { - return ctr, fmt.Errorf("manifest ABI method %q/%d: parameter #%d is unnamed", m.Name, len(m.Parameters), i) - } - typeStr, pkg := scTypeConverter(m.Name+"."+name, m.Parameters[i].Type, cfg.Overrides) if pkg != "" { imports[pkg] = struct{}{} @@ -236,7 +232,7 @@ func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract ctr.Imports = append(ctr.Imports, imp) } - return ctr, nil + return ctr } func upperFirst(s string) string { diff --git a/pkg/smartcontract/rpcbinding/binding.go b/pkg/smartcontract/rpcbinding/binding.go index 89550646f..be121c828 100644 --- a/pkg/smartcontract/rpcbinding/binding.go +++ b/pkg/smartcontract/rpcbinding/binding.go @@ -225,6 +225,8 @@ func NewConfig() binding.Config { } // Generate writes Go file containing smartcontract bindings to the `cfg.Output`. +// It doesn't check manifest from Config for validity, incorrect manifest can +// lead to unexpected results. func Generate(cfg binding.Config) error { // Avoid changing *cfg.Manifest. mfst := *cfg.Manifest @@ -264,11 +266,7 @@ func Generate(cfg binding.Config) error { mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep17Payable) } - bctr, err := binding.TemplateFromManifest(cfg, scTypeToGo) - if err != nil { - return err - } - ctr.ContractTmpl = bctr + ctr.ContractTmpl = binding.TemplateFromManifest(cfg, scTypeToGo) ctr = scTemplateToRPC(cfg, ctr, imports) return srcTemplate.Execute(cfg.Output, ctr)