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"
|
2020-06-03 12:55:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2019-11-13 13:55:20 +00:00
|
|
|
)
|
|
|
|
|
2020-06-03 12:55:06 +00:00
|
|
|
// NotificationEvent is a tuple of scripthash that emitted the Item as a
|
2019-11-13 13:55:20 +00:00
|
|
|
// notification and that item itself.
|
|
|
|
type NotificationEvent struct {
|
|
|
|
ScriptHash util.Uint160
|
2020-06-03 12:55:06 +00:00
|
|
|
Item stackitem.Item
|
2019-11-13 13:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2020-06-23 14:15:35 +00:00
|
|
|
GasConsumed int64
|
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)
|
2020-06-03 12:55:06 +00:00
|
|
|
stackitem.EncodeBinaryStackItem(ne.Item, w)
|
2019-11-13 13:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Serializable interface.
|
|
|
|
func (ne *NotificationEvent) DecodeBinary(r *io.BinReader) {
|
2020-05-04 07:35:56 +00:00
|
|
|
ne.ScriptHash.DecodeBinary(r)
|
2020-06-03 12:55:06 +00:00
|
|
|
ne.Item = stackitem.DecodeBinaryStackItem(r)
|
2019-11-13 13:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2020-06-23 14:15:35 +00:00
|
|
|
w.WriteU64LE(uint64(aer.GasConsumed))
|
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()
|
2020-06-23 14:15:35 +00:00
|
|
|
aer.GasConsumed = int64(r.ReadU64LE())
|
2020-03-23 12:03:37 +00:00
|
|
|
r.ReadArray(&aer.Stack)
|
2019-11-13 13:55:20 +00:00
|
|
|
r.ReadArray(&aer.Events)
|
|
|
|
}
|