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"
|
2020-06-03 12:55:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
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 {
|
2020-06-18 19:56:42 +00:00
|
|
|
TxHash util.Uint256 `json:"txid"`
|
2020-03-23 12:03:37 +00:00
|
|
|
Trigger string `json:"trigger"`
|
|
|
|
VMState string `json:"vmstate"`
|
2020-06-23 14:15:35 +00:00
|
|
|
GasConsumed int64 `json:"gas_consumed,string"`
|
2020-03-23 12:03:37 +00:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2020-05-10 22:00:19 +00:00
|
|
|
// StateEventToResultNotification converts state.NotificationEvent to
|
|
|
|
// result.NotificationEvent.
|
|
|
|
func StateEventToResultNotification(event state.NotificationEvent) NotificationEvent {
|
2020-06-03 12:55:06 +00:00
|
|
|
seen := make(map[stackitem.Item]bool)
|
|
|
|
item := smartcontract.ParameterFromStackItem(event.Item, seen)
|
2020-05-10 22:00:19 +00:00
|
|
|
return NotificationEvent{
|
|
|
|
Contract: event.ScriptHash,
|
|
|
|
Item: item,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 14:56:28 +00:00
|
|
|
// NewApplicationLog creates a new ApplicationLog wrapper.
|
2020-06-18 19:56:42 +00:00
|
|
|
func NewApplicationLog(appExecRes *state.AppExecResult) ApplicationLog {
|
2020-02-21 14:56:28 +00:00
|
|
|
events := make([]NotificationEvent, 0, len(appExecRes.Events))
|
|
|
|
for _, e := range appExecRes.Events {
|
2020-05-10 22:00:19 +00:00
|
|
|
events = append(events, StateEventToResultNotification(e))
|
2020-02-21 14:56:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 19:56:42 +00:00
|
|
|
return ApplicationLog{
|
|
|
|
TxHash: appExecRes.TxHash,
|
|
|
|
Trigger: appExecRes.Trigger.String(),
|
2020-02-21 14:56:28 +00:00
|
|
|
VMState: appExecRes.VMState,
|
2020-06-23 14:15:35 +00:00
|
|
|
GasConsumed: appExecRes.GasConsumed,
|
2020-03-23 12:03:37 +00:00
|
|
|
Stack: appExecRes.Stack,
|
2020-02-21 14:56:28 +00:00
|
|
|
Events: events,
|
|
|
|
}
|
|
|
|
}
|