mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
core: emit notification events in a separate method
This commit is contained in:
parent
73ef36e03e
commit
deb1f6d3d8
6 changed files with 30 additions and 50 deletions
|
@ -380,3 +380,12 @@ func (ic *Context) IsHardforkEnabled(hf config.Hardfork) bool {
|
|||
}
|
||||
return len(ic.Hardforks) == 0 // Enable each hard-fork by default.
|
||||
}
|
||||
|
||||
// AddNotification creates notification event and appends it to the notification list.
|
||||
func (ic *Context) AddNotification(hash util.Uint160, name string, item *stackitem.Array) {
|
||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
||||
ScriptHash: hash,
|
||||
Name: name,
|
||||
Item: item,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"math/big"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -69,12 +68,7 @@ func Notify(ic *interop.Context) error {
|
|||
if len(bytes) > MaxNotificationSize {
|
||||
return fmt.Errorf("notification size shouldn't exceed %d", MaxNotificationSize)
|
||||
}
|
||||
ne := state.NotificationEvent{
|
||||
ScriptHash: ic.VM.GetCurrentScriptHash(),
|
||||
Name: name,
|
||||
Item: stackitem.DeepCopy(stackitem.NewArray(args)).(*stackitem.Array),
|
||||
}
|
||||
ic.Notifications = append(ic.Notifications, ne)
|
||||
ic.AddNotification(ic.VM.GetCurrentScriptHash(), name, stackitem.DeepCopy(stackitem.NewArray(args)).(*stackitem.Array))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/stateroot"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
|
@ -386,14 +385,10 @@ func (s *Designate) DesignateAsRole(ic *interop.Context, r noderoles.Role, pubs
|
|||
return fmt.Errorf("failed to update Designation role data cache: %w", err)
|
||||
}
|
||||
|
||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
||||
ScriptHash: s.Hash,
|
||||
Name: DesignationEventName,
|
||||
Item: stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.NewBigInteger(big.NewInt(int64(r))),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(ic.Block.Index))),
|
||||
}),
|
||||
})
|
||||
ic.AddNotification(s.Hash, DesignationEventName, stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.NewBigInteger(big.NewInt(int64(r))),
|
||||
stackitem.NewBigInteger(big.NewInt(int64(ic.Block.Index))),
|
||||
}))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -607,12 +607,7 @@ func (m *Management) getNextContractID(d *dao.Simple) (int32, error) {
|
|||
}
|
||||
|
||||
func (m *Management) emitNotification(ic *interop.Context, name string, hash util.Uint160) {
|
||||
ne := state.NotificationEvent{
|
||||
ScriptHash: m.Hash,
|
||||
Name: name,
|
||||
Item: stackitem.NewArray([]stackitem.Item{addrToStackItem(&hash)}),
|
||||
}
|
||||
ic.Notifications = append(ic.Notifications, ne)
|
||||
ic.AddNotification(m.Hash, name, stackitem.NewArray([]stackitem.Item{addrToStackItem(&hash)}))
|
||||
}
|
||||
|
||||
func checkScriptAndMethods(script []byte, methods []manifest.Method) error {
|
||||
|
|
|
@ -165,16 +165,11 @@ func (c *nep17TokenNative) postTransfer(ic *interop.Context, from, to *util.Uint
|
|||
}
|
||||
|
||||
func (c *nep17TokenNative) emitTransfer(ic *interop.Context, from, to *util.Uint160, amount *big.Int) {
|
||||
ne := state.NotificationEvent{
|
||||
ScriptHash: c.Hash,
|
||||
Name: "Transfer",
|
||||
Item: stackitem.NewArray([]stackitem.Item{
|
||||
addrToStackItem(from),
|
||||
addrToStackItem(to),
|
||||
stackitem.NewBigInteger(amount),
|
||||
}),
|
||||
}
|
||||
ic.Notifications = append(ic.Notifications, ne)
|
||||
ic.AddNotification(c.Hash, "Transfer", stackitem.NewArray([]stackitem.Item{
|
||||
addrToStackItem(from),
|
||||
addrToStackItem(to),
|
||||
stackitem.NewBigInteger(amount),
|
||||
}))
|
||||
}
|
||||
|
||||
// updateAccBalance adds the specified amount to the acc's balance. If requiredBalance
|
||||
|
|
|
@ -272,15 +272,11 @@ func (o *Oracle) FinishInternal(ic *interop.Context) error {
|
|||
if err != nil {
|
||||
return ErrRequestNotFound
|
||||
}
|
||||
ic.AddNotification(o.Hash, "OracleResponse", stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.Make(resp.ID),
|
||||
stackitem.Make(req.OriginalTxID.BytesBE()),
|
||||
}))
|
||||
|
||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
||||
ScriptHash: o.Hash,
|
||||
Name: "OracleResponse",
|
||||
Item: stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.Make(resp.ID),
|
||||
stackitem.Make(req.OriginalTxID.BytesBE()),
|
||||
}),
|
||||
})
|
||||
origTx, _, err := ic.DAO.GetTransaction(req.OriginalTxID)
|
||||
if err != nil {
|
||||
return ErrRequestNotFound
|
||||
|
@ -382,16 +378,12 @@ func (o *Oracle) RequestInternal(ic *interop.Context, url string, filter *string
|
|||
} else {
|
||||
filterNotif = stackitem.Null{}
|
||||
}
|
||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
||||
ScriptHash: o.Hash,
|
||||
Name: "OracleRequest",
|
||||
Item: stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.Make(id),
|
||||
stackitem.Make(ic.VM.GetCallingScriptHash().BytesBE()),
|
||||
stackitem.Make(url),
|
||||
filterNotif,
|
||||
}),
|
||||
})
|
||||
ic.AddNotification(o.Hash, "OracleRequest", stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.Make(id),
|
||||
stackitem.Make(ic.VM.GetCallingScriptHash().BytesBE()),
|
||||
stackitem.Make(url),
|
||||
filterNotif,
|
||||
}))
|
||||
req := &state.OracleRequest{
|
||||
OriginalTxID: o.getOriginalTxID(ic.DAO, ic.Tx),
|
||||
GasForResponse: gas.Uint64(),
|
||||
|
|
Loading…
Reference in a new issue