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 <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-05-23 18:20:51 +03:00
parent 19cc6c6369
commit 37af2031bb
4 changed files with 4 additions and 3 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"math/big" "math/big"
"unicode/utf8"
) )
// Hash contains contract hash. // Hash contains contract hash.

View file

@ -11,6 +11,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"math/big" "math/big"
"unicode/utf8"
) )
// Hash contains contract hash. // Hash contains contract hash.

View file

@ -347,8 +347,6 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
eStructName := rpcbinding.ToEventBindingName(e.Name) eStructName := rpcbinding.ToEventBindingName(e.Name)
for _, p := range e.Parameters { for _, p := range e.Parameters {
pStructName := rpcbinding.ToParameterBindingName(p.Name) 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 { if p.ExtendedType != nil {
pName := eStructName + "." + pStructName pName := eStructName + "." + pStructName
cfg.Types[pName] = *p.ExtendedType cfg.Types[pName] = *p.ExtendedType

View file

@ -693,8 +693,9 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
) )
if extType, ok = cfg.Types[fullPName]; !ok { if extType, ok = cfg.Types[fullPName]; !ok {
extType = binding.ExtendedType{ 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{ eTmp.Parameters = append(eTmp.Parameters, EventParamTmpl{
ParamTmpl: binding.ParamTmpl{ ParamTmpl: binding.ParamTmpl{