forked from TrueCloudLab/neoneo-go
compiler: deduplicate autoguessed event names, fix #3088
Make them stable wrt parameter order and use proper names in event structures as well. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
a5d041a1ac
commit
5370034955
2 changed files with 50 additions and 8 deletions
|
@ -20,6 +20,11 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa
|
||||||
// Unnamed is a contract-specific unnamed type used by its methods.
|
// Unnamed is a contract-specific unnamed type used by its methods.
|
||||||
type Unnamed struct {
|
type Unnamed struct {
|
||||||
I *big.Int
|
I *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnnamedX is a contract-specific unnamedX type used by its methods.
|
||||||
|
type UnnamedX struct {
|
||||||
|
I *big.Int
|
||||||
B bool
|
B bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +40,7 @@ type SomeMapEvent struct {
|
||||||
|
|
||||||
// SomeStructEvent represents "SomeStruct" event emitted by the contract.
|
// SomeStructEvent represents "SomeStruct" event emitted by the contract.
|
||||||
type SomeStructEvent struct {
|
type SomeStructEvent struct {
|
||||||
S *Unnamed
|
S *UnnamedX
|
||||||
}
|
}
|
||||||
|
|
||||||
// SomeArrayEvent represents "SomeArray" event emitted by the contract.
|
// SomeArrayEvent represents "SomeArray" event emitted by the contract.
|
||||||
|
@ -193,6 +198,40 @@ func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) {
|
||||||
// FromStackItem retrieves fields of Unnamed from the given
|
// FromStackItem retrieves fields of Unnamed from the given
|
||||||
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
||||||
func (res *Unnamed) FromStackItem(item stackitem.Item) error {
|
func (res *Unnamed) FromStackItem(item stackitem.Item) error {
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
res.I, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field I: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// itemToUnnamedX converts stack item into *UnnamedX.
|
||||||
|
func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var res = new(UnnamedX)
|
||||||
|
err = res.FromStackItem(item)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem retrieves fields of UnnamedX from the given
|
||||||
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
||||||
|
func (res *UnnamedX) FromStackItem(item stackitem.Item) error {
|
||||||
arr, ok := item.Value().([]stackitem.Item)
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("not an array")
|
return errors.New("not an array")
|
||||||
|
@ -458,7 +497,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
index++
|
index++
|
||||||
e.S, err = itemToUnnamed(arr[index], nil)
|
e.S, err = itemToUnnamedX(arr[index], nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("field S: %w", err)
|
return fmt.Errorf("field S: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,12 +388,6 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eBindingName := rpcbinding.ToEventBindingName(eventName)
|
eBindingName := rpcbinding.ToEventBindingName(eventName)
|
||||||
for typeName, extType := range exampleUsage.ExtTypes {
|
|
||||||
if _, ok := cfg.NamedTypes[typeName]; !ok {
|
|
||||||
cfg.NamedTypes[typeName] = extType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range exampleUsage.Params {
|
for _, p := range exampleUsage.Params {
|
||||||
pBindingName := rpcbinding.ToParameterBindingName(p.Name)
|
pBindingName := rpcbinding.ToParameterBindingName(p.Name)
|
||||||
pname := eBindingName + "." + pBindingName
|
pname := eBindingName + "." + pBindingName
|
||||||
|
@ -403,6 +397,15 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p.ExtendedType != nil {
|
if p.ExtendedType != nil {
|
||||||
|
typeName := p.ExtendedType.Name
|
||||||
|
if extType, ok := exampleUsage.ExtTypes[typeName]; ok {
|
||||||
|
for _, ok := cfg.NamedTypes[typeName]; ok; _, ok = cfg.NamedTypes[typeName] {
|
||||||
|
typeName = typeName + "X"
|
||||||
|
}
|
||||||
|
extType.Name = typeName
|
||||||
|
p.ExtendedType.Name = typeName
|
||||||
|
cfg.NamedTypes[typeName] = extType
|
||||||
|
}
|
||||||
if _, ok := cfg.Types[pname]; !ok {
|
if _, ok := cfg.Types[pname]; !ok {
|
||||||
cfg.Types[pname] = *p.ExtendedType
|
cfg.Types[pname] = *p.ExtendedType
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue