2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2019-11-13 13:55:20 +00:00
|
|
|
|
|
|
|
import (
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2020-03-23 12:03:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
2019-11-13 13:55:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NotificationEvent is a tuple of scripthash that emitted the StackItem as a
|
|
|
|
// notification and that item itself.
|
|
|
|
type NotificationEvent struct {
|
|
|
|
ScriptHash util.Uint160
|
|
|
|
Item vm.StackItem
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppExecResult represent the result of the script execution, gathering together
|
|
|
|
// all resulting notifications, state, stack and other metadata.
|
|
|
|
type AppExecResult struct {
|
|
|
|
TxHash util.Uint256
|
2020-02-26 13:44:54 +00:00
|
|
|
Trigger trigger.Type
|
2019-11-13 13:55:20 +00:00
|
|
|
VMState string
|
|
|
|
GasConsumed util.Fixed8
|
2020-03-23 12:03:37 +00:00
|
|
|
Stack []smartcontract.Parameter
|
2019-11-13 13:55:20 +00:00
|
|
|
Events []NotificationEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Serializable interface.
|
2019-12-09 15:25:15 +00:00
|
|
|
func (ne *NotificationEvent) EncodeBinary(w *io.BinWriter) {
|
2020-05-04 07:35:56 +00:00
|
|
|
ne.ScriptHash.EncodeBinary(w)
|
2019-11-13 13:55:20 +00:00
|
|
|
vm.EncodeBinaryStackItem(ne.Item, w)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Serializable interface.
|
|
|
|
func (ne *NotificationEvent) DecodeBinary(r *io.BinReader) {
|
2020-05-04 07:35:56 +00:00
|
|
|
ne.ScriptHash.DecodeBinary(r)
|
2019-11-13 13:55:20 +00:00
|
|
|
ne.Item = vm.DecodeBinaryStackItem(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Serializable interface.
|
|
|
|
func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) {
|
2019-12-06 15:22:21 +00:00
|
|
|
w.WriteBytes(aer.TxHash[:])
|
2020-02-26 13:44:54 +00:00
|
|
|
w.WriteB(byte(aer.Trigger))
|
2019-11-26 15:24:54 +00:00
|
|
|
w.WriteString(aer.VMState)
|
2019-12-12 15:52:23 +00:00
|
|
|
aer.GasConsumed.EncodeBinary(w)
|
2020-03-23 12:03:37 +00:00
|
|
|
w.WriteArray(aer.Stack)
|
2019-11-13 13:55:20 +00:00
|
|
|
w.WriteArray(aer.Events)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Serializable interface.
|
|
|
|
func (aer *AppExecResult) DecodeBinary(r *io.BinReader) {
|
2019-12-06 15:37:46 +00:00
|
|
|
r.ReadBytes(aer.TxHash[:])
|
2020-02-26 13:44:54 +00:00
|
|
|
aer.Trigger = trigger.Type(r.ReadB())
|
2019-11-26 15:24:54 +00:00
|
|
|
aer.VMState = r.ReadString()
|
2019-12-12 15:52:23 +00:00
|
|
|
aer.GasConsumed.DecodeBinary(r)
|
2020-03-23 12:03:37 +00:00
|
|
|
r.ReadArray(&aer.Stack)
|
2019-11-13 13:55:20 +00:00
|
|
|
r.ReadArray(&aer.Events)
|
|
|
|
}
|