From 37af2031bb9fa299b5fc99834d7486f121fce586 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 23 May 2023 18:20:51 +0300 Subject: [PATCH] rpcbinding: properly add imports for simple types of event parameters There are two ways of doing this: first one is to emit all notifications parameter data into rpcbindings configuration on compile time (event if the parameter has a simple type), and the second one is to fetch parameter type from the manifest on rpcbinding file generation if needed (we always have manifest at this stage, thus it's not a problem to retrieve necessary information). The latter case is chosen to reduce the bindings configuration file size. Signed-off-by: Anna Shaleva --- cli/smartcontract/testdata/nameservice/nns.go | 1 + cli/smartcontract/testdata/notifications/rpcbindings.out | 1 + pkg/compiler/compiler.go | 2 -- pkg/smartcontract/rpcbinding/binding.go | 3 ++- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/smartcontract/testdata/nameservice/nns.go b/cli/smartcontract/testdata/nameservice/nns.go index 2b19af793..4c3a76d6f 100644 --- a/cli/smartcontract/testdata/nameservice/nns.go +++ b/cli/smartcontract/testdata/nameservice/nns.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "math/big" + "unicode/utf8" ) // Hash contains contract hash. diff --git a/cli/smartcontract/testdata/notifications/rpcbindings.out b/cli/smartcontract/testdata/notifications/rpcbindings.out index aeeb3ccd7..a3717edd8 100644 --- a/cli/smartcontract/testdata/notifications/rpcbindings.out +++ b/cli/smartcontract/testdata/notifications/rpcbindings.out @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "math/big" + "unicode/utf8" ) // Hash contains contract hash. diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 6a711921a..eac2bdced 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -347,8 +347,6 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { eStructName := rpcbinding.ToEventBindingName(e.Name) for _, p := range e.Parameters { pStructName := rpcbinding.ToParameterBindingName(p.Name) - // TODO: proper imports handling during bindings generation (see utf8 example). - // Probably, we should always add p type to the list of types. if p.ExtendedType != nil { pName := eStructName + "." + pStructName cfg.Types[pName] = *p.ExtendedType diff --git a/pkg/smartcontract/rpcbinding/binding.go b/pkg/smartcontract/rpcbinding/binding.go index 074b41c49..a3eab9576 100644 --- a/pkg/smartcontract/rpcbinding/binding.go +++ b/pkg/smartcontract/rpcbinding/binding.go @@ -693,8 +693,9 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st ) if extType, ok = cfg.Types[fullPName]; !ok { extType = binding.ExtendedType{ - Base: abiEvent.Parameters[i].Type, // TODO: properly handle imports for this case (see utf8 example) + Base: abiEvent.Parameters[i].Type, } + addETImports(extType, ctr.NamedTypes, imports) } eTmp.Parameters = append(eTmp.Parameters, EventParamTmpl{ ParamTmpl: binding.ParamTmpl{