2020-02-21 14:56:28 +00:00
|
|
|
package result
|
|
|
|
|
|
|
|
import (
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
2020-02-21 14:56:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ApplicationLog wrapper used for the representation of the
|
|
|
|
// state.AppExecResult based on the specific tx on the RPC Server.
|
|
|
|
type ApplicationLog struct {
|
|
|
|
TxHash util.Uint256 `json:"txid"`
|
|
|
|
Executions []Execution `json:"executions"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execution response wrapper
|
|
|
|
type Execution struct {
|
2020-03-23 12:03:37 +00:00
|
|
|
Trigger string `json:"trigger"`
|
|
|
|
ScriptHash util.Uint160 `json:"contract"`
|
|
|
|
VMState string `json:"vmstate"`
|
|
|
|
GasConsumed util.Fixed8 `json:"gas_consumed"`
|
|
|
|
Stack []smartcontract.Parameter `json:"stack"`
|
|
|
|
Events []NotificationEvent `json:"notifications"`
|
2020-02-21 14:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NotificationEvent response wrapper
|
|
|
|
type NotificationEvent struct {
|
|
|
|
Contract util.Uint160 `json:"contract"`
|
|
|
|
Item smartcontract.Parameter `json:"state"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewApplicationLog creates a new ApplicationLog wrapper.
|
|
|
|
func NewApplicationLog(appExecRes *state.AppExecResult, scriptHash util.Uint160) ApplicationLog {
|
|
|
|
events := make([]NotificationEvent, 0, len(appExecRes.Events))
|
|
|
|
for _, e := range appExecRes.Events {
|
2020-03-03 09:52:56 +00:00
|
|
|
seen := make(map[vm.StackItem]bool)
|
|
|
|
item := e.Item.ToContractParameter(seen)
|
2020-02-21 14:56:28 +00:00
|
|
|
events = append(events, NotificationEvent{
|
|
|
|
Contract: e.ScriptHash,
|
|
|
|
Item: item,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerString := appExecRes.Trigger.String()
|
|
|
|
|
|
|
|
executions := []Execution{{
|
|
|
|
Trigger: triggerString,
|
|
|
|
ScriptHash: scriptHash,
|
|
|
|
VMState: appExecRes.VMState,
|
|
|
|
GasConsumed: appExecRes.GasConsumed,
|
2020-03-23 12:03:37 +00:00
|
|
|
Stack: appExecRes.Stack,
|
2020-02-21 14:56:28 +00:00
|
|
|
Events: events,
|
|
|
|
}}
|
|
|
|
|
|
|
|
return ApplicationLog{
|
|
|
|
TxHash: appExecRes.TxHash,
|
|
|
|
Executions: executions,
|
|
|
|
}
|
|
|
|
}
|