forked from TrueCloudLab/neoneo-go
3787a8895e
Also there is no more decimal point.
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package result
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"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/stackitem"
|
|
)
|
|
|
|
// 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"`
|
|
Trigger string `json:"trigger"`
|
|
VMState string `json:"vmstate"`
|
|
GasConsumed string `json:"gas_consumed"`
|
|
Stack []smartcontract.Parameter `json:"stack"`
|
|
Events []NotificationEvent `json:"notifications"`
|
|
}
|
|
|
|
//NotificationEvent response wrapper
|
|
type NotificationEvent struct {
|
|
Contract util.Uint160 `json:"contract"`
|
|
Item smartcontract.Parameter `json:"state"`
|
|
}
|
|
|
|
// StateEventToResultNotification converts state.NotificationEvent to
|
|
// result.NotificationEvent.
|
|
func StateEventToResultNotification(event state.NotificationEvent) NotificationEvent {
|
|
seen := make(map[stackitem.Item]bool)
|
|
item := smartcontract.ParameterFromStackItem(event.Item, seen)
|
|
return NotificationEvent{
|
|
Contract: event.ScriptHash,
|
|
Item: item,
|
|
}
|
|
}
|
|
|
|
// NewApplicationLog creates a new ApplicationLog wrapper.
|
|
func NewApplicationLog(appExecRes *state.AppExecResult) ApplicationLog {
|
|
events := make([]NotificationEvent, 0, len(appExecRes.Events))
|
|
for _, e := range appExecRes.Events {
|
|
events = append(events, StateEventToResultNotification(e))
|
|
}
|
|
|
|
return ApplicationLog{
|
|
TxHash: appExecRes.TxHash,
|
|
Trigger: appExecRes.Trigger.String(),
|
|
VMState: appExecRes.VMState,
|
|
GasConsumed: strconv.FormatInt(int64(appExecRes.GasConsumed), 10),
|
|
Stack: appExecRes.Stack,
|
|
Events: events,
|
|
}
|
|
}
|