2023-10-18 17:32:51 +00:00
|
|
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
2023-12-25 10:01:36 +00:00
|
|
|
|
|
|
|
// Package structs contains RPC wrappers for Notifications contract.
|
2023-05-25 15:39:27 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
"math/big"
|
|
|
|
"unicode/utf8"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hash contains contract hash.
|
|
|
|
var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0}
|
|
|
|
|
|
|
|
// Unnamed is a contract-specific unnamed type used by its methods.
|
|
|
|
type Unnamed struct {
|
|
|
|
I *big.Int
|
2023-11-21 15:41:58 +00:00
|
|
|
B bool
|
2023-11-21 15:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnnamedX is a contract-specific unnamedX type used by its methods.
|
|
|
|
type UnnamedX struct {
|
|
|
|
I *big.Int
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract.
|
|
|
|
type ComplicatedNameEvent struct {
|
|
|
|
ComplicatedParam string
|
|
|
|
}
|
|
|
|
|
|
|
|
// SomeMapEvent represents "SomeMap" event emitted by the contract.
|
|
|
|
type SomeMapEvent struct {
|
|
|
|
M map[*big.Int][]map[string][]util.Uint160
|
|
|
|
}
|
|
|
|
|
|
|
|
// SomeStructEvent represents "SomeStruct" event emitted by the contract.
|
|
|
|
type SomeStructEvent struct {
|
2023-11-21 15:41:58 +00:00
|
|
|
S *Unnamed
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SomeArrayEvent represents "SomeArray" event emitted by the contract.
|
|
|
|
type SomeArrayEvent struct {
|
|
|
|
A [][]*big.Int
|
|
|
|
}
|
|
|
|
|
2023-08-10 17:23:54 +00:00
|
|
|
// SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract.
|
|
|
|
type SomeUnexportedFieldEvent struct {
|
2023-11-21 15:41:58 +00:00
|
|
|
S *UnnamedX
|
2023-08-10 17:23:54 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 15:39:27 +00:00
|
|
|
// Actor is used by Contract to call state-changing methods.
|
|
|
|
type Actor interface {
|
|
|
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
|
|
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
|
|
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
|
|
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
|
|
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
|
|
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Contract implements all contract methods.
|
|
|
|
type Contract struct {
|
|
|
|
actor Actor
|
2023-10-18 14:58:39 +00:00
|
|
|
hash util.Uint160
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates an instance of Contract using Hash and the given Actor.
|
|
|
|
func New(actor Actor) *Contract {
|
2023-05-11 10:25:45 +00:00
|
|
|
var hash = Hash
|
|
|
|
return &Contract{actor, hash}
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Array creates a transaction invoking `array` method of the contract.
|
|
|
|
// This transaction is signed and immediately sent to the network.
|
|
|
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
|
|
|
func (c *Contract) Array() (util.Uint256, uint32, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.SendCall(c.hash, "array")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ArrayTransaction creates a transaction invoking `array` method of the contract.
|
|
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
|
|
// returned to the caller.
|
|
|
|
func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeCall(c.hash, "array")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ArrayUnsigned creates a transaction invoking `array` method of the contract.
|
|
|
|
// This transaction is not signed, it's simply returned to the caller.
|
|
|
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
|
|
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
|
|
|
func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeUnsignedCall(c.hash, "array", nil)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CrazyMap creates a transaction invoking `crazyMap` method of the contract.
|
|
|
|
// This transaction is signed and immediately sent to the network.
|
|
|
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
|
|
|
func (c *Contract) CrazyMap() (util.Uint256, uint32, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.SendCall(c.hash, "crazyMap")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract.
|
|
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
|
|
// returned to the caller.
|
|
|
|
func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeCall(c.hash, "crazyMap")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract.
|
|
|
|
// This transaction is not signed, it's simply returned to the caller.
|
|
|
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
|
|
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
|
|
|
func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Main creates a transaction invoking `main` method of the contract.
|
|
|
|
// This transaction is signed and immediately sent to the network.
|
|
|
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
|
|
|
func (c *Contract) Main() (util.Uint256, uint32, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.SendCall(c.hash, "main")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MainTransaction creates a transaction invoking `main` method of the contract.
|
|
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
|
|
// returned to the caller.
|
|
|
|
func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeCall(c.hash, "main")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MainUnsigned creates a transaction invoking `main` method of the contract.
|
|
|
|
// This transaction is not signed, it's simply returned to the caller.
|
|
|
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
|
|
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
|
|
|
func (c *Contract) MainUnsigned() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeUnsignedCall(c.hash, "main", nil)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Struct creates a transaction invoking `struct` method of the contract.
|
|
|
|
// This transaction is signed and immediately sent to the network.
|
|
|
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
|
|
|
func (c *Contract) Struct() (util.Uint256, uint32, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.SendCall(c.hash, "struct")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StructTransaction creates a transaction invoking `struct` method of the contract.
|
|
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
|
|
// returned to the caller.
|
|
|
|
func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeCall(c.hash, "struct")
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StructUnsigned creates a transaction invoking `struct` method of the contract.
|
|
|
|
// This transaction is not signed, it's simply returned to the caller.
|
|
|
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
|
|
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
|
|
|
func (c *Contract) StructUnsigned() (*transaction.Transaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return c.actor.MakeUnsignedCall(c.hash, "struct", nil)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
2023-08-10 17:23:54 +00:00
|
|
|
// UnexportedField creates a transaction invoking `unexportedField` method of the contract.
|
|
|
|
// This transaction is signed and immediately sent to the network.
|
|
|
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
|
|
|
func (c *Contract) UnexportedField() (util.Uint256, uint32, error) {
|
|
|
|
return c.actor.SendCall(c.hash, "unexportedField")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract.
|
|
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
|
|
// returned to the caller.
|
|
|
|
func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) {
|
|
|
|
return c.actor.MakeCall(c.hash, "unexportedField")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract.
|
|
|
|
// This transaction is not signed, it's simply returned to the caller.
|
|
|
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
|
|
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
|
|
|
func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) {
|
|
|
|
return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil)
|
|
|
|
}
|
|
|
|
|
2023-05-25 15:39:27 +00:00
|
|
|
// itemToUnnamed converts stack item into *Unnamed.
|
|
|
|
func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var res = new(Unnamed)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of Unnamed from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-25 15:39:27 +00:00
|
|
|
func (res *Unnamed) FromStackItem(item stackitem.Item) error {
|
2023-11-21 15:26:35 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
2023-11-21 15:41:58 +00:00
|
|
|
if len(arr) != 2 {
|
2023-11-21 15:26:35 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
index++
|
|
|
|
res.I, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field I: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-11-21 15:41:58 +00:00
|
|
|
index++
|
|
|
|
res.B, err = arr[index].TryBool()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field B: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-11-21 15:26:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// itemToUnnamedX converts stack item into *UnnamedX.
|
|
|
|
func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var res = new(UnnamedX)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromStackItem retrieves fields of UnnamedX from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
|
|
|
func (res *UnnamedX) FromStackItem(item stackitem.Item) error {
|
2023-05-25 15:39:27 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
2023-11-21 15:41:58 +00:00
|
|
|
if len(arr) != 1 {
|
2023-05-25 15:39:27 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-25 15:39:27 +00:00
|
|
|
)
|
|
|
|
index++
|
|
|
|
res.I, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field I: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events
|
2023-05-31 12:47:10 +00:00
|
|
|
// with "! complicated name %$#" name from the provided [result.ApplicationLog].
|
2023-05-25 15:39:27 +00:00
|
|
|
func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) {
|
|
|
|
if log == nil {
|
|
|
|
return nil, errors.New("nil application log")
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []*ComplicatedNameEvent
|
|
|
|
for i, ex := range log.Executions {
|
|
|
|
for j, e := range ex.Events {
|
|
|
|
if e.Name != "! complicated name %$#" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
event := new(ComplicatedNameEvent)
|
|
|
|
err := event.FromStackItem(e.Item)
|
|
|
|
if err != nil {
|
2023-05-30 08:59:16 +00:00
|
|
|
return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
res = append(res, event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or
|
2023-05-30 14:34:51 +00:00
|
|
|
// returns an error if it's not possible to do to so.
|
2023-05-25 15:39:27 +00:00
|
|
|
func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
|
|
|
|
if item == nil {
|
|
|
|
return errors.New("nil item")
|
|
|
|
}
|
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
|
|
|
if len(arr) != 1 {
|
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-25 15:39:27 +00:00
|
|
|
)
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if !utf8.Valid(b) {
|
|
|
|
return "", errors.New("not a UTF-8 string")
|
|
|
|
}
|
|
|
|
return string(b), nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field ComplicatedParam: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SomeMapEventsFromApplicationLog retrieves a set of all emitted events
|
2023-05-31 12:47:10 +00:00
|
|
|
// with "SomeMap" name from the provided [result.ApplicationLog].
|
2023-05-25 15:39:27 +00:00
|
|
|
func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) {
|
|
|
|
if log == nil {
|
|
|
|
return nil, errors.New("nil application log")
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []*SomeMapEvent
|
|
|
|
for i, ex := range log.Executions {
|
|
|
|
for j, e := range ex.Events {
|
|
|
|
if e.Name != "SomeMap" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
event := new(SomeMapEvent)
|
|
|
|
err := event.FromStackItem(e.Item)
|
|
|
|
if err != nil {
|
2023-05-30 08:59:16 +00:00
|
|
|
return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
res = append(res, event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem converts provided [stackitem.Array] to SomeMapEvent or
|
2023-05-30 14:34:51 +00:00
|
|
|
// returns an error if it's not possible to do to so.
|
2023-05-25 15:39:27 +00:00
|
|
|
func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
|
|
|
|
if item == nil {
|
|
|
|
return errors.New("nil item")
|
|
|
|
}
|
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
|
|
|
if len(arr) != 1 {
|
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-25 15:39:27 +00:00
|
|
|
)
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
e.M, err = func(item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
m, ok := item.Value().([]stackitem.MapElement)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("%s is not a map", item.Type().String())
|
|
|
|
}
|
|
|
|
res := make(map[*big.Int][]map[string][]util.Uint160)
|
|
|
|
for i := range m {
|
|
|
|
k, err := m[i].Key.TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("key %d: %w", i, err)
|
|
|
|
}
|
2023-10-18 14:58:39 +00:00
|
|
|
v, err := func(item stackitem.Item) ([]map[string][]util.Uint160, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]map[string][]util.Uint160, len(arr))
|
|
|
|
for i := range res {
|
2023-10-18 14:58:39 +00:00
|
|
|
res[i], err = func(item stackitem.Item) (map[string][]util.Uint160, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
m, ok := item.Value().([]stackitem.MapElement)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("%s is not a map", item.Type().String())
|
|
|
|
}
|
|
|
|
res := make(map[string][]util.Uint160)
|
|
|
|
for i := range m {
|
2023-10-18 14:58:39 +00:00
|
|
|
k, err := func(item stackitem.Item) (string, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if !utf8.Valid(b) {
|
|
|
|
return "", errors.New("not a UTF-8 string")
|
|
|
|
}
|
|
|
|
return string(b), nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(m[i].Key)
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("key %d: %w", i, err)
|
|
|
|
}
|
2023-10-18 14:58:39 +00:00
|
|
|
v, err := func(item stackitem.Item) ([]util.Uint160, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]util.Uint160, len(arr))
|
|
|
|
for i := range res {
|
2023-10-18 14:58:39 +00:00
|
|
|
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint160{}, err
|
|
|
|
}
|
|
|
|
u, err := util.Uint160DecodeBytesBE(b)
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint160{}, err
|
|
|
|
}
|
|
|
|
return u, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[i])
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(m[i].Value)
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("value %d: %w", i, err)
|
|
|
|
}
|
|
|
|
res[k] = v
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[i])
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(m[i].Value)
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("value %d: %w", i, err)
|
|
|
|
}
|
|
|
|
res[k] = v
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field M: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SomeStructEventsFromApplicationLog retrieves a set of all emitted events
|
2023-05-31 12:47:10 +00:00
|
|
|
// with "SomeStruct" name from the provided [result.ApplicationLog].
|
2023-05-25 15:39:27 +00:00
|
|
|
func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) {
|
|
|
|
if log == nil {
|
|
|
|
return nil, errors.New("nil application log")
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []*SomeStructEvent
|
|
|
|
for i, ex := range log.Executions {
|
|
|
|
for j, e := range ex.Events {
|
|
|
|
if e.Name != "SomeStruct" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
event := new(SomeStructEvent)
|
|
|
|
err := event.FromStackItem(e.Item)
|
|
|
|
if err != nil {
|
2023-05-30 08:59:16 +00:00
|
|
|
return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
res = append(res, event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem converts provided [stackitem.Array] to SomeStructEvent or
|
2023-05-30 14:34:51 +00:00
|
|
|
// returns an error if it's not possible to do to so.
|
2023-05-25 15:39:27 +00:00
|
|
|
func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
|
|
|
|
if item == nil {
|
|
|
|
return errors.New("nil item")
|
|
|
|
}
|
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
|
|
|
if len(arr) != 1 {
|
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-25 15:39:27 +00:00
|
|
|
)
|
|
|
|
index++
|
2023-11-21 15:41:58 +00:00
|
|
|
e.S, err = itemToUnnamed(arr[index], nil)
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field S: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SomeArrayEventsFromApplicationLog retrieves a set of all emitted events
|
2023-05-31 12:47:10 +00:00
|
|
|
// with "SomeArray" name from the provided [result.ApplicationLog].
|
2023-05-25 15:39:27 +00:00
|
|
|
func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) {
|
|
|
|
if log == nil {
|
|
|
|
return nil, errors.New("nil application log")
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []*SomeArrayEvent
|
|
|
|
for i, ex := range log.Executions {
|
|
|
|
for j, e := range ex.Events {
|
|
|
|
if e.Name != "SomeArray" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
event := new(SomeArrayEvent)
|
|
|
|
err := event.FromStackItem(e.Item)
|
|
|
|
if err != nil {
|
2023-05-30 08:59:16 +00:00
|
|
|
return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
2023-05-25 15:39:27 +00:00
|
|
|
}
|
|
|
|
res = append(res, event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or
|
2023-05-30 14:34:51 +00:00
|
|
|
// returns an error if it's not possible to do to so.
|
2023-05-25 15:39:27 +00:00
|
|
|
func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
|
|
|
|
if item == nil {
|
|
|
|
return errors.New("nil item")
|
|
|
|
}
|
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
|
|
|
if len(arr) != 1 {
|
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-25 15:39:27 +00:00
|
|
|
)
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
e.A, err = func(item stackitem.Item) ([][]*big.Int, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([][]*big.Int, len(arr))
|
|
|
|
for i := range res {
|
2023-10-18 14:58:39 +00:00
|
|
|
res[i], err = func(item stackitem.Item) ([]*big.Int, error) {
|
2023-05-25 15:39:27 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*big.Int, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = arr[i].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[i])
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2023-05-25 15:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field A: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-10 17:23:54 +00:00
|
|
|
|
|
|
|
// SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events
|
|
|
|
// with "SomeUnexportedField" name from the provided [result.ApplicationLog].
|
|
|
|
func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) {
|
|
|
|
if log == nil {
|
|
|
|
return nil, errors.New("nil application log")
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []*SomeUnexportedFieldEvent
|
|
|
|
for i, ex := range log.Executions {
|
|
|
|
for j, e := range ex.Events {
|
|
|
|
if e.Name != "SomeUnexportedField" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
event := new(SomeUnexportedFieldEvent)
|
|
|
|
err := event.FromStackItem(e.Item)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
|
|
}
|
|
|
|
res = append(res, event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or
|
|
|
|
// returns an error if it's not possible to do to so.
|
|
|
|
func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
|
|
|
|
if item == nil {
|
|
|
|
return errors.New("nil item")
|
|
|
|
}
|
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an array")
|
|
|
|
}
|
|
|
|
if len(arr) != 1 {
|
|
|
|
return errors.New("wrong number of structure elements")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-08-10 17:23:54 +00:00
|
|
|
)
|
|
|
|
index++
|
2023-11-21 15:41:58 +00:00
|
|
|
e.S, err = itemToUnnamedX(arr[index], nil)
|
2023-08-10 17:23:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field S: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|