runtime: check notifications against ABI
Related to #2703, just a logged thing for now.
This commit is contained in:
parent
48567fbc61
commit
79887f9d78
7 changed files with 196 additions and 57 deletions
|
@ -73,9 +73,20 @@ func Notify(ic *interop.Context) error {
|
|||
if len(name) > MaxEventNameLen {
|
||||
return fmt.Errorf("event name must be less than %d", MaxEventNameLen)
|
||||
}
|
||||
if !ic.VM.Context().IsDeployed() {
|
||||
curHash := ic.VM.GetCurrentScriptHash()
|
||||
ctr, err := ic.GetContract(curHash)
|
||||
if err != nil {
|
||||
return errors.New("notifications are not allowed in dynamic scripts")
|
||||
}
|
||||
ev := ctr.Manifest.ABI.GetEvent(name)
|
||||
if ev == nil {
|
||||
ic.Log.Info("bad notification", zap.String("contract", curHash.StringLE()), zap.String("event", name), zap.Error(fmt.Errorf("event %s does not exist", name)))
|
||||
} else {
|
||||
err = ev.CheckCompliance(args)
|
||||
if err != nil {
|
||||
ic.Log.Info("bad notification", zap.String("contract", curHash.StringLE()), zap.String("event", name), zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// But it has to be serializable, otherwise we either have some broken
|
||||
// (recursive) structure inside or an interop item that can't be used
|
||||
|
@ -87,7 +98,7 @@ func Notify(ic *interop.Context) error {
|
|||
if len(bytes) > MaxNotificationSize {
|
||||
return fmt.Errorf("notification size shouldn't exceed %d", MaxNotificationSize)
|
||||
}
|
||||
ic.AddNotification(ic.VM.GetCurrentScriptHash(), name, stackitem.DeepCopy(stackitem.NewArray(args), true).(*stackitem.Array))
|
||||
ic.AddNotification(curHash, name, stackitem.DeepCopy(stackitem.NewArray(args), true).(*stackitem.Array))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue