From 6379bcc15ac444cdc15bc968e23b235934a5f7e6 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 25 May 2023 18:45:59 +0300 Subject: [PATCH] compiler: properly set extended type name for unnamed structs After the struct was registered as "unnamed", it has the own unique name. Signed-off-by: Anna Shaleva --- .../notifications/rpcbindings_guessed.out | 17 ++--------------- pkg/compiler/debug.go | 7 ++++++- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/cli/smartcontract/testdata/notifications/rpcbindings_guessed.out b/cli/smartcontract/testdata/notifications/rpcbindings_guessed.out index 09bb03117..c9c20ae5b 100755 --- a/cli/smartcontract/testdata/notifications/rpcbindings_guessed.out +++ b/cli/smartcontract/testdata/notifications/rpcbindings_guessed.out @@ -95,7 +95,7 @@ type SomeMapEvent struct { // SomeStructEvent represents "SomeStruct" event emitted by the contract. type SomeStructEvent struct { - S []any + S *Unnamed } // SomeArrayEvent represents "SomeArray" event emitted by the contract. @@ -1052,20 +1052,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { err error ) index++ - e.S, err = func (item stackitem.Item) ([]any, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]any, len(arr)) - for i := range res { - res[i], err = arr[i].Value(), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - } (arr[index]) + e.S, err = itemToUnnamed(arr[index], nil) if err != nil { return fmt.Errorf("field S: %w", err) } diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index 0eb18bb5a..a583fc3bd 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -386,10 +386,12 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte over.TypeName = "map[" + t.Key().String() + "]" + over.TypeName return smartcontract.MapType, stackitem.MapT, over, et case *types.Struct: + var extName string if isNamed { over.Package = named.Obj().Pkg().Path() over.TypeName = named.Obj().Pkg().Name() + "." + named.Obj().Name() _ = c.genStructExtended(t, over.TypeName, exts) + extName = over.TypeName } else { name := "unnamed" if exts != nil { @@ -398,11 +400,14 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte } _ = c.genStructExtended(t, name, exts) } + // For bindings configurator this structure becomes named in fact. Its name + // is "unnamed[X...X]". + extName = name } return smartcontract.ArrayType, stackitem.StructT, over, &binding.ExtendedType{ // Value-less, refer to exts. Base: smartcontract.ArrayType, - Name: over.TypeName, + Name: extName, } case *types.Slice: