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.
This commit is contained in:
parent
be02eea7b1
commit
145ebad90e
2 changed files with 10 additions and 16 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue