2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2019-11-13 13:55:20 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2020-02-26 13:44:54 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/smartcontract/trigger"
|
2019-11-13 13:55:20 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
Stack string // JSON
|
|
|
|
Events []NotificationEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Serializable interface.
|
2019-12-09 15:25:15 +00:00
|
|
|
func (ne *NotificationEvent) EncodeBinary(w *io.BinWriter) {
|
2019-12-06 15:22:21 +00:00
|
|
|
w.WriteBytes(ne.ScriptHash[:])
|
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) {
|
2019-12-06 15:37:46 +00:00
|
|
|
r.ReadBytes(ne.ScriptHash[:])
|
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)
|
2019-11-26 15:24:54 +00:00
|
|
|
w.WriteString(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)
|
2019-11-26 15:24:54 +00:00
|
|
|
aer.Stack = r.ReadString()
|
2019-11-13 13:55:20 +00:00
|
|
|
r.ReadArray(&aer.Events)
|
|
|
|
}
|