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 Types contract.
|
2022-11-25 10:04:24 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/elliptic"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"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"
|
|
|
|
"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}
|
|
|
|
|
|
|
|
// LedgerBlock is a contract-specific ledger.Block type used by its methods.
|
|
|
|
type LedgerBlock struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
Hash util.Uint256
|
|
|
|
Version *big.Int
|
|
|
|
PrevHash util.Uint256
|
|
|
|
MerkleRoot util.Uint256
|
|
|
|
Timestamp *big.Int
|
|
|
|
Nonce *big.Int
|
|
|
|
Index *big.Int
|
|
|
|
NextConsensus util.Uint160
|
2022-11-25 10:04:24 +00:00
|
|
|
TransactionsLength *big.Int
|
|
|
|
}
|
|
|
|
|
|
|
|
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
|
|
|
|
type LedgerTransaction struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
Hash util.Uint256
|
|
|
|
Version *big.Int
|
|
|
|
Nonce *big.Int
|
|
|
|
Sender util.Uint160
|
|
|
|
SysFee *big.Int
|
|
|
|
NetFee *big.Int
|
2022-11-25 10:04:24 +00:00
|
|
|
ValidUntilBlock *big.Int
|
2023-10-18 14:58:39 +00:00
|
|
|
Script []byte
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementABI is a contract-specific management.ABI type used by its methods.
|
|
|
|
type ManagementABI struct {
|
|
|
|
Methods []*ManagementMethod
|
2023-10-18 14:58:39 +00:00
|
|
|
Events []*ManagementEvent
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementContract is a contract-specific management.Contract type used by its methods.
|
|
|
|
type ManagementContract struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
ID *big.Int
|
2022-11-25 10:04:24 +00:00
|
|
|
UpdateCounter *big.Int
|
2023-10-18 14:58:39 +00:00
|
|
|
Hash util.Uint160
|
|
|
|
NEF []byte
|
|
|
|
Manifest *ManagementManifest
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementEvent is a contract-specific management.Event type used by its methods.
|
|
|
|
type ManagementEvent struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
Name string
|
2022-11-25 10:04:24 +00:00
|
|
|
Params []*ManagementParameter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementGroup is a contract-specific management.Group type used by its methods.
|
|
|
|
type ManagementGroup struct {
|
|
|
|
PublicKey *keys.PublicKey
|
|
|
|
Signature []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementManifest is a contract-specific management.Manifest type used by its methods.
|
|
|
|
type ManagementManifest struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
Name string
|
|
|
|
Groups []*ManagementGroup
|
|
|
|
Features map[string]string
|
2022-11-25 10:04:24 +00:00
|
|
|
SupportedStandards []string
|
2023-10-18 14:58:39 +00:00
|
|
|
ABI *ManagementABI
|
|
|
|
Permissions []*ManagementPermission
|
|
|
|
Trusts []util.Uint160
|
|
|
|
Extra any
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementMethod is a contract-specific management.Method type used by its methods.
|
|
|
|
type ManagementMethod struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
Name string
|
|
|
|
Params []*ManagementParameter
|
2022-11-25 10:04:24 +00:00
|
|
|
ReturnType *big.Int
|
2023-10-18 14:58:39 +00:00
|
|
|
Offset *big.Int
|
|
|
|
Safe bool
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementParameter is a contract-specific management.Parameter type used by its methods.
|
|
|
|
type ManagementParameter struct {
|
|
|
|
Name string
|
|
|
|
Type *big.Int
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManagementPermission is a contract-specific management.Permission type used by its methods.
|
|
|
|
type ManagementPermission struct {
|
|
|
|
Contract util.Uint160
|
2023-10-18 14:58:39 +00:00
|
|
|
Methods []string
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StructsInternal is a contract-specific structs.Internal type used by its methods.
|
|
|
|
type StructsInternal struct {
|
2023-10-18 14:58:39 +00:00
|
|
|
Bool bool
|
|
|
|
Int *big.Int
|
|
|
|
Bytes []byte
|
|
|
|
String string
|
|
|
|
H160 util.Uint160
|
|
|
|
H256 util.Uint256
|
|
|
|
PK *keys.PublicKey
|
|
|
|
PubKey *keys.PublicKey
|
|
|
|
Sign []byte
|
|
|
|
ArrOfBytes [][]byte
|
|
|
|
ArrOfH160 []util.Uint160
|
|
|
|
Map map[*big.Int]keys.PublicKeys
|
|
|
|
Struct *StructsInternal
|
2023-08-10 17:23:54 +00:00
|
|
|
UnexportedField *big.Int
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
2023-05-24 08:44:31 +00:00
|
|
|
|
2022-11-25 10:04:24 +00:00
|
|
|
// Invoker is used by ContractReader to call various safe methods.
|
|
|
|
type Invoker interface {
|
2023-04-03 10:34:24 +00:00
|
|
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ContractReader implements safe contract methods.
|
|
|
|
type ContractReader struct {
|
|
|
|
invoker Invoker
|
2023-10-18 14:58:39 +00:00
|
|
|
hash util.Uint160
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewReader creates an instance of ContractReader using Hash and the given Invoker.
|
|
|
|
func NewReader(invoker Invoker) *ContractReader {
|
2023-05-11 10:25:45 +00:00
|
|
|
var hash = Hash
|
|
|
|
return &ContractReader{invoker, hash}
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Block invokes `block` method of contract.
|
|
|
|
func (c *ContractReader) Block(b *LedgerBlock) (*LedgerBlock, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return itemToLedgerBlock(unwrap.Item(c.invoker.Call(c.hash, "block", b)))
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Contract invokes `contract` method of contract.
|
|
|
|
func (c *ContractReader) Contract(mc *ManagementContract) (*ManagementContract, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return itemToManagementContract(unwrap.Item(c.invoker.Call(c.hash, "contract", mc)))
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Struct invokes `struct` method of contract.
|
|
|
|
func (c *ContractReader) Struct(s *StructsInternal) (*StructsInternal, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return itemToStructsInternal(unwrap.Item(c.invoker.Call(c.hash, "struct", s)))
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transaction invokes `transaction` method of contract.
|
|
|
|
func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction, error) {
|
2023-05-11 10:25:45 +00:00
|
|
|
return itemToLedgerTransaction(unwrap.Item(c.invoker.Call(c.hash, "transaction", t)))
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToLedgerBlock converts stack item into *LedgerBlock.
|
|
|
|
func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(LedgerBlock)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of LedgerBlock from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 9 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
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
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Hash: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Version, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Version: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
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
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field PrevHash: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
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
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field MerkleRoot: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Timestamp, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Timestamp: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Nonce, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Nonce: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Index, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Index: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
|
2022-11-25 10:04:24 +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[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field NextConsensus: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.TransactionsLength, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field TransactionsLength: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToLedgerTransaction converts stack item into *LedgerTransaction.
|
|
|
|
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(LedgerTransaction)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of LedgerTransaction from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 8 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
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
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Hash: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Version, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Version: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Nonce, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Nonce: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Sender, err = func(item stackitem.Item) (util.Uint160, error) {
|
2022-11-25 10:04:24 +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[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Sender: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.SysFee, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field SysFee: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.NetFee, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field NetFee: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.ValidUntilBlock, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field ValidUntilBlock: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Script, err = arr[index].TryBytes()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Script: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementABI converts stack item into *ManagementABI.
|
|
|
|
func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementABI)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementABI from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementABI) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 2 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Methods, err = func(item stackitem.Item) ([]*ManagementMethod, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*ManagementMethod, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = itemToManagementMethod(arr[i], nil)
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Methods: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Events, err = func(item stackitem.Item) ([]*ManagementEvent, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*ManagementEvent, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = itemToManagementEvent(arr[i], nil)
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Events: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementContract converts stack item into *ManagementContract.
|
|
|
|
func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementContract)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementContract from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementContract) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 5 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
|
|
|
res.ID, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field ID: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.UpdateCounter, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field UpdateCounter: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Hash, err = func(item stackitem.Item) (util.Uint160, error) {
|
2022-11-25 10:04:24 +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[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Hash: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.NEF, err = arr[index].TryBytes()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field NEF: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Manifest, err = itemToManagementManifest(arr[index], nil)
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Manifest: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementEvent converts stack item into *ManagementEvent.
|
|
|
|
func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementEvent)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementEvent from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementEvent) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 2 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Name, err = func(item stackitem.Item) (string, error) {
|
2022-11-25 10:04:24 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Name: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Params, err = func(item stackitem.Item) ([]*ManagementParameter, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*ManagementParameter, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = itemToManagementParameter(arr[i], nil)
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Params: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementGroup converts stack item into *ManagementGroup.
|
|
|
|
func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementGroup)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementGroup from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementGroup) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 2 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return k, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field PublicKey: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Signature, err = arr[index].TryBytes()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Signature: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementManifest converts stack item into *ManagementManifest.
|
|
|
|
func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementManifest)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementManifest from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementManifest) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 8 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Name, err = func(item stackitem.Item) (string, error) {
|
2022-11-25 10:04:24 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Name: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Groups, err = func(item stackitem.Item) ([]*ManagementGroup, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*ManagementGroup, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = itemToManagementGroup(arr[i], nil)
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Groups: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Features, err = func(item stackitem.Item) (map[string]string, error) {
|
2022-12-01 19:16:37 +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]string)
|
|
|
|
for i := range m {
|
2023-10-18 14:58:39 +00:00
|
|
|
k, err := func(item stackitem.Item) (string, error) {
|
2022-12-01 19:16:37 +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)
|
2022-12-01 19:16:37 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("key %d: %w", i, err)
|
2022-12-01 19:16:37 +00:00
|
|
|
}
|
2023-10-18 14:58:39 +00:00
|
|
|
v, err := func(item stackitem.Item) (string, error) {
|
2022-12-01 19:16:37 +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].Value)
|
2022-12-01 19:16:37 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("value %d: %w", i, err)
|
2022-12-01 19:16:37 +00:00
|
|
|
}
|
|
|
|
res[k] = v
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
2022-12-01 19:16:37 +00:00
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Features: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.SupportedStandards, err = func(item stackitem.Item) ([]string, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]string, len(arr))
|
|
|
|
for i := range res {
|
2023-10-18 14:58:39 +00:00
|
|
|
res[i], err = func(item stackitem.Item) (string, error) {
|
2022-12-01 18:59:28 +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[i])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field SupportedStandards: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.ABI, err = itemToManagementABI(arr[index], nil)
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field ABI: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Permissions, err = func(item stackitem.Item) ([]*ManagementPermission, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*ManagementPermission, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = itemToManagementPermission(arr[i], nil)
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Permissions: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Trusts, err = func(item stackitem.Item) ([]util.Uint160, error) {
|
2022-11-25 10:04:24 +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) {
|
2022-12-01 18:59:28 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Trusts: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-05-03 16:18:43 +00:00
|
|
|
res.Extra, err = arr[index].Value(), error(nil)
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Extra: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementMethod converts stack item into *ManagementMethod.
|
|
|
|
func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementMethod)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementMethod from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementMethod) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 5 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Name, err = func(item stackitem.Item) (string, error) {
|
2022-11-25 10:04:24 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Name: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Params, err = func(item stackitem.Item) ([]*ManagementParameter, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]*ManagementParameter, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = itemToManagementParameter(arr[i], nil)
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Params: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.ReturnType, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field ReturnType: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Offset, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Offset: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Safe, err = arr[index].TryBool()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Safe: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementParameter converts stack item into *ManagementParameter.
|
|
|
|
func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementParameter)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementParameter from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementParameter) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 2 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Name, err = func(item stackitem.Item) (string, error) {
|
2022-11-25 10:04:24 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Name: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Type, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Type: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToManagementPermission converts stack item into *ManagementPermission.
|
|
|
|
func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(ManagementPermission)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of ManagementPermission from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *ManagementPermission) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
if len(arr) != 2 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Contract, err = func(item stackitem.Item) (util.Uint160, error) {
|
2022-11-25 10:04:24 +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[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Contract: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Methods, err = func(item stackitem.Item) ([]string, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([]string, len(arr))
|
|
|
|
for i := range res {
|
2023-10-18 14:58:39 +00:00
|
|
|
res[i], err = func(item stackitem.Item) (string, error) {
|
2022-12-01 18:59:28 +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[i])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Methods: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// itemToStructsInternal converts stack item into *StructsInternal.
|
|
|
|
func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-03 11:55:02 +00:00
|
|
|
var res = new(StructsInternal)
|
|
|
|
err = res.FromStackItem(item)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2023-05-31 12:47:10 +00:00
|
|
|
// FromStackItem retrieves fields of StructsInternal from the given
|
|
|
|
// [stackitem.Item] or returns an error if it's not possible to do to so.
|
2023-05-03 11:55:02 +00:00
|
|
|
func (res *StructsInternal) FromStackItem(item stackitem.Item) error {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("not an array")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
2023-08-10 17:23:54 +00:00
|
|
|
if len(arr) != 14 {
|
2023-05-03 11:55:02 +00:00
|
|
|
return errors.New("wrong number of structure elements")
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
var (
|
|
|
|
index = -1
|
2023-10-18 14:58:39 +00:00
|
|
|
err error
|
2023-05-03 11:55:02 +00:00
|
|
|
)
|
2022-11-25 10:04:24 +00:00
|
|
|
index++
|
|
|
|
res.Bool, err = arr[index].TryBool()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Bool: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Int, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Int: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Bytes, err = arr[index].TryBytes()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Bytes: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.String, err = func(item stackitem.Item) (string, error) {
|
2022-11-25 10:04:24 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field String: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.H160, err = func(item stackitem.Item) (util.Uint160, error) {
|
2022-11-25 10:04:24 +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[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field H160: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.H256, err = func(item stackitem.Item) (util.Uint256, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
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
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field H256: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.PK, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return k, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field PK: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.PubKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return k, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field PubKey: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Sign, err = arr[index].TryBytes()
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Sign: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.ArrOfBytes, err = func(item stackitem.Item) ([][]byte, error) {
|
2022-11-25 10:04:24 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make([][]byte, len(arr))
|
|
|
|
for i := range res {
|
|
|
|
res[i], err = arr[i].TryBytes()
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field ArrOfBytes: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.ArrOfH160, err = func(item stackitem.Item) ([]util.Uint160, error) {
|
2022-11-25 10:04:24 +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) {
|
2022-12-01 18:59:28 +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])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field ArrOfH160: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
2023-10-18 14:58:39 +00:00
|
|
|
res.Map, err = func(item stackitem.Item) (map[*big.Int]keys.PublicKeys, error) {
|
2022-12-01 19:16:37 +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]keys.PublicKeys)
|
|
|
|
for i := range m {
|
|
|
|
k, err := m[i].Key.TryInteger()
|
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("key %d: %w", i, err)
|
2022-12-01 19:16:37 +00:00
|
|
|
}
|
2023-10-18 14:58:39 +00:00
|
|
|
v, err := func(item stackitem.Item) (keys.PublicKeys, error) {
|
2022-12-01 19:16:37 +00:00
|
|
|
arr, ok := item.Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("not an array")
|
|
|
|
}
|
|
|
|
res := make(keys.PublicKeys, len(arr))
|
|
|
|
for i := range res {
|
2023-10-18 14:58:39 +00:00
|
|
|
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
2022-12-01 19:16:37 +00:00
|
|
|
b, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return k, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[i])
|
2022-12-01 19:16:37 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
2022-12-01 19:16:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(m[i].Value)
|
2022-12-01 19:16:37 +00:00
|
|
|
if err != nil {
|
2022-12-02 13:12:56 +00:00
|
|
|
return nil, fmt.Errorf("value %d: %w", i, err)
|
2022-12-01 19:16:37 +00:00
|
|
|
}
|
|
|
|
res[k] = v
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
2022-12-01 19:16:37 +00:00
|
|
|
return res, nil
|
2023-10-18 14:58:39 +00:00
|
|
|
}(arr[index])
|
2022-11-25 10:04:24 +00:00
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Map: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++
|
|
|
|
res.Struct, err = itemToStructsInternal(arr[index], nil)
|
|
|
|
if err != nil {
|
2023-05-03 11:55:02 +00:00
|
|
|
return fmt.Errorf("field Struct: %w", err)
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-08-10 17:23:54 +00:00
|
|
|
index++
|
|
|
|
res.UnexportedField, err = arr[index].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("field UnexportedField: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:55:02 +00:00
|
|
|
return nil
|
2022-11-25 10:04:24 +00:00
|
|
|
}
|