forked from TrueCloudLab/frostfs-contract
851 lines
26 KiB
Go
851 lines
26 KiB
Go
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
|
|
|
// Package frostfs contains RPC wrappers for FrostFS contract.
|
|
package frostfs
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
"math/big"
|
|
)
|
|
|
|
// DepositEvent represents "Deposit" event emitted by the contract.
|
|
type DepositEvent struct {
|
|
From util.Uint160
|
|
Amount *big.Int
|
|
Receiver util.Uint160
|
|
TxHash util.Uint256
|
|
}
|
|
|
|
// WithdrawEvent represents "Withdraw" event emitted by the contract.
|
|
type WithdrawEvent struct {
|
|
User util.Uint160
|
|
Amount *big.Int
|
|
TxHash util.Uint256
|
|
}
|
|
|
|
// ChequeEvent represents "Cheque" event emitted by the contract.
|
|
type ChequeEvent struct {
|
|
Id []byte
|
|
User util.Uint160
|
|
Amount *big.Int
|
|
LockAccount []byte
|
|
}
|
|
|
|
// BindEvent represents "Bind" event emitted by the contract.
|
|
type BindEvent struct {
|
|
User []byte
|
|
Keys []any
|
|
}
|
|
|
|
// UnbindEvent represents "Unbind" event emitted by the contract.
|
|
type UnbindEvent struct {
|
|
User []byte
|
|
Keys []any
|
|
}
|
|
|
|
// AlphabetUpdateEvent represents "AlphabetUpdate" event emitted by the contract.
|
|
type AlphabetUpdateEvent struct {
|
|
Id []byte
|
|
Alphabet []any
|
|
}
|
|
|
|
// SetConfigEvent represents "SetConfig" event emitted by the contract.
|
|
type SetConfigEvent struct {
|
|
Id []byte
|
|
Key []byte
|
|
Value []byte
|
|
}
|
|
|
|
// Invoker is used by ContractReader to call various safe methods.
|
|
type Invoker interface {
|
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
|
}
|
|
|
|
// Actor is used by Contract to call state-changing methods.
|
|
type Actor interface {
|
|
Invoker
|
|
|
|
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)
|
|
}
|
|
|
|
// ContractReader implements safe contract methods.
|
|
type ContractReader struct {
|
|
invoker Invoker
|
|
hash util.Uint160
|
|
}
|
|
|
|
// Contract implements all contract methods.
|
|
type Contract struct {
|
|
ContractReader
|
|
actor Actor
|
|
hash util.Uint160
|
|
}
|
|
|
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
|
return &ContractReader{invoker, hash}
|
|
}
|
|
|
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
|
func New(actor Actor, hash util.Uint160) *Contract {
|
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
|
}
|
|
|
|
// AlphabetAddress invokes `alphabetAddress` method of contract.
|
|
func (c *ContractReader) AlphabetAddress() (util.Uint160, error) {
|
|
return unwrap.Uint160(c.invoker.Call(c.hash, "alphabetAddress"))
|
|
}
|
|
|
|
// Config invokes `config` method of contract.
|
|
func (c *ContractReader) Config(key []byte) (any, error) {
|
|
return func(item stackitem.Item, err error) (any, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return item.Value(), error(nil)
|
|
}(unwrap.Item(c.invoker.Call(c.hash, "config", key)))
|
|
}
|
|
|
|
// InnerRingCandidates invokes `innerRingCandidates` method of contract.
|
|
func (c *ContractReader) InnerRingCandidates() ([]stackitem.Item, error) {
|
|
return unwrap.Array(c.invoker.Call(c.hash, "innerRingCandidates"))
|
|
}
|
|
|
|
// ListConfig invokes `listConfig` method of contract.
|
|
func (c *ContractReader) ListConfig() ([]stackitem.Item, error) {
|
|
return unwrap.Array(c.invoker.Call(c.hash, "listConfig"))
|
|
}
|
|
|
|
// Version invokes `version` method of contract.
|
|
func (c *ContractReader) Version() (*big.Int, error) {
|
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
|
}
|
|
|
|
// Bind creates a transaction invoking `bind` 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) Bind(user []byte, keys []any) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "bind", user, keys)
|
|
}
|
|
|
|
// BindTransaction creates a transaction invoking `bind` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) BindTransaction(user []byte, keys []any) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "bind", user, keys)
|
|
}
|
|
|
|
// BindUnsigned creates a transaction invoking `bind` 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) BindUnsigned(user []byte, keys []any) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "bind", nil, user, keys)
|
|
}
|
|
|
|
// Cheque creates a transaction invoking `cheque` 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) Cheque(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "cheque", id, user, amount, lockAcc)
|
|
}
|
|
|
|
// ChequeTransaction creates a transaction invoking `cheque` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) ChequeTransaction(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "cheque", id, user, amount, lockAcc)
|
|
}
|
|
|
|
// ChequeUnsigned creates a transaction invoking `cheque` 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) ChequeUnsigned(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "cheque", nil, id, user, amount, lockAcc)
|
|
}
|
|
|
|
// InnerRingCandidateAdd creates a transaction invoking `innerRingCandidateAdd` 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) InnerRingCandidateAdd(key *keys.PublicKey) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "innerRingCandidateAdd", key)
|
|
}
|
|
|
|
// InnerRingCandidateAddTransaction creates a transaction invoking `innerRingCandidateAdd` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) InnerRingCandidateAddTransaction(key *keys.PublicKey) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "innerRingCandidateAdd", key)
|
|
}
|
|
|
|
// InnerRingCandidateAddUnsigned creates a transaction invoking `innerRingCandidateAdd` 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) InnerRingCandidateAddUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "innerRingCandidateAdd", nil, key)
|
|
}
|
|
|
|
// InnerRingCandidateRemove creates a transaction invoking `innerRingCandidateRemove` 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) InnerRingCandidateRemove(key *keys.PublicKey) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "innerRingCandidateRemove", key)
|
|
}
|
|
|
|
// InnerRingCandidateRemoveTransaction creates a transaction invoking `innerRingCandidateRemove` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) InnerRingCandidateRemoveTransaction(key *keys.PublicKey) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "innerRingCandidateRemove", key)
|
|
}
|
|
|
|
// InnerRingCandidateRemoveUnsigned creates a transaction invoking `innerRingCandidateRemove` 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) InnerRingCandidateRemoveUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "innerRingCandidateRemove", nil, key)
|
|
}
|
|
|
|
// SetConfig creates a transaction invoking `setConfig` 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) SetConfig(id []byte, key []byte, val []byte) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "setConfig", id, key, val)
|
|
}
|
|
|
|
// SetConfigTransaction creates a transaction invoking `setConfig` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) SetConfigTransaction(id []byte, key []byte, val []byte) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "setConfig", id, key, val)
|
|
}
|
|
|
|
// SetConfigUnsigned creates a transaction invoking `setConfig` 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) SetConfigUnsigned(id []byte, key []byte, val []byte) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "setConfig", nil, id, key, val)
|
|
}
|
|
|
|
// Unbind creates a transaction invoking `unbind` 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) Unbind(user []byte, keys []any) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "unbind", user, keys)
|
|
}
|
|
|
|
// UnbindTransaction creates a transaction invoking `unbind` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) UnbindTransaction(user []byte, keys []any) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "unbind", user, keys)
|
|
}
|
|
|
|
// UnbindUnsigned creates a transaction invoking `unbind` 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) UnbindUnsigned(user []byte, keys []any) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "unbind", nil, user, keys)
|
|
}
|
|
|
|
// Update creates a transaction invoking `update` 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) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
|
}
|
|
|
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
|
}
|
|
|
|
// UpdateUnsigned creates a transaction invoking `update` 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) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
|
}
|
|
|
|
// Withdraw creates a transaction invoking `withdraw` 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) Withdraw(user util.Uint160, amount *big.Int) (util.Uint256, uint32, error) {
|
|
return c.actor.SendCall(c.hash, "withdraw", user, amount)
|
|
}
|
|
|
|
// WithdrawTransaction creates a transaction invoking `withdraw` method of the contract.
|
|
// This transaction is signed, but not sent to the network, instead it's
|
|
// returned to the caller.
|
|
func (c *Contract) WithdrawTransaction(user util.Uint160, amount *big.Int) (*transaction.Transaction, error) {
|
|
return c.actor.MakeCall(c.hash, "withdraw", user, amount)
|
|
}
|
|
|
|
// WithdrawUnsigned creates a transaction invoking `withdraw` 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) WithdrawUnsigned(user util.Uint160, amount *big.Int) (*transaction.Transaction, error) {
|
|
return c.actor.MakeUnsignedCall(c.hash, "withdraw", nil, user, amount)
|
|
}
|
|
|
|
// DepositEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "Deposit" name from the provided [result.ApplicationLog].
|
|
func DepositEventsFromApplicationLog(log *result.ApplicationLog) ([]*DepositEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*DepositEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "Deposit" {
|
|
continue
|
|
}
|
|
event := new(DepositEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize DepositEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to DepositEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *DepositEvent) 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) != 4 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.From, err = func(item stackitem.Item) (util.Uint160, error) {
|
|
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
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field From: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Amount, err = arr[index].TryInteger()
|
|
if err != nil {
|
|
return fmt.Errorf("field Amount: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Receiver, err = func(item stackitem.Item) (util.Uint160, error) {
|
|
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
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field Receiver: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.TxHash, err = func(item stackitem.Item) (util.Uint256, error) {
|
|
b, err := item.TryBytes()
|
|
if err != nil {
|
|
return util.Uint256{}, err
|
|
}
|
|
u, err := util.Uint256DecodeBytesBE(b)
|
|
if err != nil {
|
|
return util.Uint256{}, err
|
|
}
|
|
return u, nil
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field TxHash: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// WithdrawEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "Withdraw" name from the provided [result.ApplicationLog].
|
|
func WithdrawEventsFromApplicationLog(log *result.ApplicationLog) ([]*WithdrawEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*WithdrawEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "Withdraw" {
|
|
continue
|
|
}
|
|
event := new(WithdrawEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize WithdrawEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to WithdrawEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *WithdrawEvent) 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) != 3 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.User, err = func(item stackitem.Item) (util.Uint160, error) {
|
|
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
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field User: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Amount, err = arr[index].TryInteger()
|
|
if err != nil {
|
|
return fmt.Errorf("field Amount: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.TxHash, err = func(item stackitem.Item) (util.Uint256, error) {
|
|
b, err := item.TryBytes()
|
|
if err != nil {
|
|
return util.Uint256{}, err
|
|
}
|
|
u, err := util.Uint256DecodeBytesBE(b)
|
|
if err != nil {
|
|
return util.Uint256{}, err
|
|
}
|
|
return u, nil
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field TxHash: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ChequeEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "Cheque" name from the provided [result.ApplicationLog].
|
|
func ChequeEventsFromApplicationLog(log *result.ApplicationLog) ([]*ChequeEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*ChequeEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "Cheque" {
|
|
continue
|
|
}
|
|
event := new(ChequeEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize ChequeEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to ChequeEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *ChequeEvent) 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) != 4 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.Id, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field Id: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.User, err = func(item stackitem.Item) (util.Uint160, error) {
|
|
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
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field User: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Amount, err = arr[index].TryInteger()
|
|
if err != nil {
|
|
return fmt.Errorf("field Amount: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.LockAccount, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field LockAccount: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// BindEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "Bind" name from the provided [result.ApplicationLog].
|
|
func BindEventsFromApplicationLog(log *result.ApplicationLog) ([]*BindEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*BindEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "Bind" {
|
|
continue
|
|
}
|
|
event := new(BindEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize BindEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to BindEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *BindEvent) 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) != 2 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.User, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field User: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Keys, err = func(item stackitem.Item) ([]any, error) {
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
if !ok {
|
|
return nil, errors.New("not an array")
|
|
}
|
|
res := make([]any, len(arr))
|
|
for i := range res {
|
|
res[i], err = arr[i].Value(), error(nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
}
|
|
}
|
|
return res, nil
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field Keys: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UnbindEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "Unbind" name from the provided [result.ApplicationLog].
|
|
func UnbindEventsFromApplicationLog(log *result.ApplicationLog) ([]*UnbindEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*UnbindEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "Unbind" {
|
|
continue
|
|
}
|
|
event := new(UnbindEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize UnbindEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to UnbindEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *UnbindEvent) 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) != 2 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.User, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field User: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Keys, err = func(item stackitem.Item) ([]any, error) {
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
if !ok {
|
|
return nil, errors.New("not an array")
|
|
}
|
|
res := make([]any, len(arr))
|
|
for i := range res {
|
|
res[i], err = arr[i].Value(), error(nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
}
|
|
}
|
|
return res, nil
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field Keys: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// AlphabetUpdateEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "AlphabetUpdate" name from the provided [result.ApplicationLog].
|
|
func AlphabetUpdateEventsFromApplicationLog(log *result.ApplicationLog) ([]*AlphabetUpdateEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*AlphabetUpdateEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "AlphabetUpdate" {
|
|
continue
|
|
}
|
|
event := new(AlphabetUpdateEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize AlphabetUpdateEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to AlphabetUpdateEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *AlphabetUpdateEvent) 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) != 2 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.Id, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field Id: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Alphabet, err = func(item stackitem.Item) ([]any, error) {
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
if !ok {
|
|
return nil, errors.New("not an array")
|
|
}
|
|
res := make([]any, len(arr))
|
|
for i := range res {
|
|
res[i], err = arr[i].Value(), error(nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
|
}
|
|
}
|
|
return res, nil
|
|
}(arr[index])
|
|
if err != nil {
|
|
return fmt.Errorf("field Alphabet: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// SetConfigEventsFromApplicationLog retrieves a set of all emitted events
|
|
// with "SetConfig" name from the provided [result.ApplicationLog].
|
|
func SetConfigEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetConfigEvent, error) {
|
|
if log == nil {
|
|
return nil, errors.New("nil application log")
|
|
}
|
|
|
|
var res []*SetConfigEvent
|
|
for i, ex := range log.Executions {
|
|
for j, e := range ex.Events {
|
|
if e.Name != "SetConfig" {
|
|
continue
|
|
}
|
|
event := new(SetConfigEvent)
|
|
err := event.FromStackItem(e.Item)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to deserialize SetConfigEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
|
}
|
|
res = append(res, event)
|
|
}
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// FromStackItem converts provided [stackitem.Array] to SetConfigEvent or
|
|
// returns an error if it's not possible to do to so.
|
|
func (e *SetConfigEvent) 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) != 3 {
|
|
return errors.New("wrong number of structure elements")
|
|
}
|
|
|
|
var (
|
|
index = -1
|
|
err error
|
|
)
|
|
index++
|
|
e.Id, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field Id: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Key, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field Key: %w", err)
|
|
}
|
|
|
|
index++
|
|
e.Value, err = arr[index].TryBytes()
|
|
if err != nil {
|
|
return fmt.Errorf("field Value: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|