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.
|
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"
|
"math/big"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"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"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -69,12 +68,7 @@ func Notify(ic *interop.Context) error {
|
||||||
if len(bytes) > MaxNotificationSize {
|
if len(bytes) > MaxNotificationSize {
|
||||||
return fmt.Errorf("notification size shouldn't exceed %d", MaxNotificationSize)
|
return fmt.Errorf("notification size shouldn't exceed %d", MaxNotificationSize)
|
||||||
}
|
}
|
||||||
ne := state.NotificationEvent{
|
ic.AddNotification(ic.VM.GetCurrentScriptHash(), name, stackitem.DeepCopy(stackitem.NewArray(args)).(*stackitem.Array))
|
||||||
ScriptHash: ic.VM.GetCurrentScriptHash(),
|
|
||||||
Name: name,
|
|
||||||
Item: stackitem.DeepCopy(stackitem.NewArray(args)).(*stackitem.Array),
|
|
||||||
}
|
|
||||||
ic.Notifications = append(ic.Notifications, ne)
|
|
||||||
return nil
|
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/interop/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"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/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/stateroot"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"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)
|
return fmt.Errorf("failed to update Designation role data cache: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
ic.AddNotification(s.Hash, DesignationEventName, stackitem.NewArray([]stackitem.Item{
|
||||||
ScriptHash: s.Hash,
|
|
||||||
Name: DesignationEventName,
|
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
|
||||||
stackitem.NewBigInteger(big.NewInt(int64(r))),
|
stackitem.NewBigInteger(big.NewInt(int64(r))),
|
||||||
stackitem.NewBigInteger(big.NewInt(int64(ic.Block.Index))),
|
stackitem.NewBigInteger(big.NewInt(int64(ic.Block.Index))),
|
||||||
}),
|
}))
|
||||||
})
|
|
||||||
return nil
|
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) {
|
func (m *Management) emitNotification(ic *interop.Context, name string, hash util.Uint160) {
|
||||||
ne := state.NotificationEvent{
|
ic.AddNotification(m.Hash, name, stackitem.NewArray([]stackitem.Item{addrToStackItem(&hash)}))
|
||||||
ScriptHash: m.Hash,
|
|
||||||
Name: name,
|
|
||||||
Item: stackitem.NewArray([]stackitem.Item{addrToStackItem(&hash)}),
|
|
||||||
}
|
|
||||||
ic.Notifications = append(ic.Notifications, ne)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkScriptAndMethods(script []byte, methods []manifest.Method) error {
|
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) {
|
func (c *nep17TokenNative) emitTransfer(ic *interop.Context, from, to *util.Uint160, amount *big.Int) {
|
||||||
ne := state.NotificationEvent{
|
ic.AddNotification(c.Hash, "Transfer", stackitem.NewArray([]stackitem.Item{
|
||||||
ScriptHash: c.Hash,
|
|
||||||
Name: "Transfer",
|
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
|
||||||
addrToStackItem(from),
|
addrToStackItem(from),
|
||||||
addrToStackItem(to),
|
addrToStackItem(to),
|
||||||
stackitem.NewBigInteger(amount),
|
stackitem.NewBigInteger(amount),
|
||||||
}),
|
}))
|
||||||
}
|
|
||||||
ic.Notifications = append(ic.Notifications, ne)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateAccBalance adds the specified amount to the acc's balance. If requiredBalance
|
// 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 {
|
if err != nil {
|
||||||
return ErrRequestNotFound
|
return ErrRequestNotFound
|
||||||
}
|
}
|
||||||
|
ic.AddNotification(o.Hash, "OracleResponse", stackitem.NewArray([]stackitem.Item{
|
||||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
|
||||||
ScriptHash: o.Hash,
|
|
||||||
Name: "OracleResponse",
|
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
|
||||||
stackitem.Make(resp.ID),
|
stackitem.Make(resp.ID),
|
||||||
stackitem.Make(req.OriginalTxID.BytesBE()),
|
stackitem.Make(req.OriginalTxID.BytesBE()),
|
||||||
}),
|
}))
|
||||||
})
|
|
||||||
origTx, _, err := ic.DAO.GetTransaction(req.OriginalTxID)
|
origTx, _, err := ic.DAO.GetTransaction(req.OriginalTxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrRequestNotFound
|
return ErrRequestNotFound
|
||||||
|
@ -382,16 +378,12 @@ func (o *Oracle) RequestInternal(ic *interop.Context, url string, filter *string
|
||||||
} else {
|
} else {
|
||||||
filterNotif = stackitem.Null{}
|
filterNotif = stackitem.Null{}
|
||||||
}
|
}
|
||||||
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
|
ic.AddNotification(o.Hash, "OracleRequest", stackitem.NewArray([]stackitem.Item{
|
||||||
ScriptHash: o.Hash,
|
|
||||||
Name: "OracleRequest",
|
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
|
||||||
stackitem.Make(id),
|
stackitem.Make(id),
|
||||||
stackitem.Make(ic.VM.GetCallingScriptHash().BytesBE()),
|
stackitem.Make(ic.VM.GetCallingScriptHash().BytesBE()),
|
||||||
stackitem.Make(url),
|
stackitem.Make(url),
|
||||||
filterNotif,
|
filterNotif,
|
||||||
}),
|
}))
|
||||||
})
|
|
||||||
req := &state.OracleRequest{
|
req := &state.OracleRequest{
|
||||||
OriginalTxID: o.getOriginalTxID(ic.DAO, ic.Tx),
|
OriginalTxID: o.getOriginalTxID(ic.DAO, ic.Tx),
|
||||||
GasForResponse: gas.Uint64(),
|
GasForResponse: gas.Uint64(),
|
||||||
|
|
Loading…
Reference in a new issue