compiler: check range first, analyze funcs then

Type data is added while walking through function ins/outs even if we're to
throw this function away. But we don't need it, these types are not used, so
we can deal with the main part of #3071 by optimizing this out.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2023-11-21 17:48:53 +03:00
parent 7f9e2e5047
commit a5d041a1ac
6 changed files with 2 additions and 2638 deletions

View file

@ -4,81 +4,18 @@
package structs package structs
import ( import (
"crypto/elliptic"
"errors" "errors"
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "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/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"math/big"
"unicode/utf8" "unicode/utf8"
) )
// Hash contains contract hash. // 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} 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 {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
}
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct {
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
ValidUntilBlock *big.Int
Script []byte
}
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Condition *LedgerWitnessCondition
}
// ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. // ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract.
type ComplicatedNameEvent struct { type ComplicatedNameEvent struct {
ComplicatedParam string ComplicatedParam string
@ -236,569 +173,6 @@ func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil)
} }
// itemToLedgerBlock converts stack item into *LedgerBlock.
func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlock)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlock from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 9 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
return nil
}
// itemToLedgerBlockSR converts stack item into *LedgerBlockSR.
func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlockSR)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlockSR from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 10 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
index++
res.PrevStateRoot, 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 PrevStateRoot: %w", err)
}
return nil
}
// itemToLedgerTransaction converts stack item into *LedgerTransaction.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransaction)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransaction from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 8 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Sender, 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 Sender: %w", err)
}
index++
res.SysFee, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field SysFee: %w", err)
}
index++
res.NetFee, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field NetFee: %w", err)
}
index++
res.ValidUntilBlock, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field ValidUntilBlock: %w", err)
}
index++
res.Script, err = arr[index].TryBytes()
if err != nil {
return fmt.Errorf("field Script: %w", err)
}
return nil
}
// itemToLedgerTransactionSigner converts stack item into *LedgerTransactionSigner.
func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTransactionSigner, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransactionSigner)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransactionSigner from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 5 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Account, 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 Account: %w", err)
}
index++
res.Scopes, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Scopes: %w", err)
}
index++
res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
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 {
res[i], 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[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
index++
res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
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 {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
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
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
index++
res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]*LedgerWitnessRule, len(arr))
for i := range res {
res[i], err = itemToLedgerWitnessRule(arr[i], 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 Rules: %w", err)
}
return nil
}
// itemToLedgerWitnessCondition converts stack item into *LedgerWitnessCondition.
func itemToLedgerWitnessCondition(item stackitem.Item, err error) (*LedgerWitnessCondition, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessCondition)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessCondition from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
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++
res.Type, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Type: %w", err)
}
index++
res.Value, err = arr[index].Value(), error(nil)
if err != nil {
return fmt.Errorf("field Value: %w", err)
}
return nil
}
// itemToLedgerWitnessRule converts stack item into *LedgerWitnessRule.
func itemToLedgerWitnessRule(item stackitem.Item, err error) (*LedgerWitnessRule, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessRule)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessRule from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
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++
res.Action, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Action: %w", err)
}
index++
res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil)
if err != nil {
return fmt.Errorf("field Condition: %w", err)
}
return nil
}
// ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events // ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events
// with "! complicated name %$#" name from the provided [result.ApplicationLog]. // with "! complicated name %$#" name from the provided [result.ApplicationLog].
func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) {

View file

@ -4,11 +4,9 @@
package structs package structs
import ( import (
"crypto/elliptic"
"errors" "errors"
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "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/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
@ -25,66 +23,6 @@ type CrazyStruct struct {
B bool B bool
} }
// LedgerBlock is a contract-specific ledger.Block type used by its methods.
type LedgerBlock struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
}
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct {
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
ValidUntilBlock *big.Int
Script []byte
}
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Condition *LedgerWitnessCondition
}
// SimpleStruct is a contract-specific simpleStruct type used by its methods. // SimpleStruct is a contract-specific simpleStruct type used by its methods.
type SimpleStruct struct { type SimpleStruct struct {
I *big.Int I *big.Int
@ -287,569 +225,6 @@ func (res *CrazyStruct) FromStackItem(item stackitem.Item) error {
return nil return nil
} }
// itemToLedgerBlock converts stack item into *LedgerBlock.
func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlock)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlock from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 9 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
return nil
}
// itemToLedgerBlockSR converts stack item into *LedgerBlockSR.
func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlockSR)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlockSR from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 10 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
index++
res.PrevStateRoot, 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 PrevStateRoot: %w", err)
}
return nil
}
// itemToLedgerTransaction converts stack item into *LedgerTransaction.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransaction)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransaction from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 8 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Sender, 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 Sender: %w", err)
}
index++
res.SysFee, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field SysFee: %w", err)
}
index++
res.NetFee, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field NetFee: %w", err)
}
index++
res.ValidUntilBlock, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field ValidUntilBlock: %w", err)
}
index++
res.Script, err = arr[index].TryBytes()
if err != nil {
return fmt.Errorf("field Script: %w", err)
}
return nil
}
// itemToLedgerTransactionSigner converts stack item into *LedgerTransactionSigner.
func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTransactionSigner, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransactionSigner)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransactionSigner from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 5 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Account, 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 Account: %w", err)
}
index++
res.Scopes, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Scopes: %w", err)
}
index++
res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
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 {
res[i], 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[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
index++
res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
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 {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
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
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
index++
res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]*LedgerWitnessRule, len(arr))
for i := range res {
res[i], err = itemToLedgerWitnessRule(arr[i], 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 Rules: %w", err)
}
return nil
}
// itemToLedgerWitnessCondition converts stack item into *LedgerWitnessCondition.
func itemToLedgerWitnessCondition(item stackitem.Item, err error) (*LedgerWitnessCondition, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessCondition)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessCondition from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
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++
res.Type, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Type: %w", err)
}
index++
res.Value, err = arr[index].Value(), error(nil)
if err != nil {
return fmt.Errorf("field Value: %w", err)
}
return nil
}
// itemToLedgerWitnessRule converts stack item into *LedgerWitnessRule.
func itemToLedgerWitnessRule(item stackitem.Item, err error) (*LedgerWitnessRule, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessRule)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessRule from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
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++
res.Action, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Action: %w", err)
}
index++
res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil)
if err != nil {
return fmt.Errorf("field Condition: %w", err)
}
return nil
}
// itemToSimpleStruct converts stack item into *SimpleStruct. // itemToSimpleStruct converts stack item into *SimpleStruct.
func itemToSimpleStruct(item stackitem.Item, err error) (*SimpleStruct, error) { func itemToSimpleStruct(item stackitem.Item, err error) (*SimpleStruct, error) {
if err != nil { if err != nil {

View file

@ -4,11 +4,9 @@
package structs package structs
import ( import (
"crypto/elliptic"
"errors" "errors"
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "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/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
@ -19,66 +17,6 @@ import (
// Hash contains contract hash. // 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} 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 {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
}
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct {
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
ValidUntilBlock *big.Int
Script []byte
}
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Condition *LedgerWitnessCondition
}
// Unnamed is a contract-specific unnamed type used by its methods. // Unnamed is a contract-specific unnamed type used by its methods.
type Unnamed struct { type Unnamed struct {
I *big.Int I *big.Int
@ -242,569 +180,6 @@ func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil)
} }
// itemToLedgerBlock converts stack item into *LedgerBlock.
func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlock)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlock from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 9 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
return nil
}
// itemToLedgerBlockSR converts stack item into *LedgerBlockSR.
func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlockSR)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlockSR from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 10 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
index++
res.PrevStateRoot, 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 PrevStateRoot: %w", err)
}
return nil
}
// itemToLedgerTransaction converts stack item into *LedgerTransaction.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransaction)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransaction from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 8 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Sender, 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 Sender: %w", err)
}
index++
res.SysFee, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field SysFee: %w", err)
}
index++
res.NetFee, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field NetFee: %w", err)
}
index++
res.ValidUntilBlock, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field ValidUntilBlock: %w", err)
}
index++
res.Script, err = arr[index].TryBytes()
if err != nil {
return fmt.Errorf("field Script: %w", err)
}
return nil
}
// itemToLedgerTransactionSigner converts stack item into *LedgerTransactionSigner.
func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTransactionSigner, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransactionSigner)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransactionSigner from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 5 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Account, 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 Account: %w", err)
}
index++
res.Scopes, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Scopes: %w", err)
}
index++
res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
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 {
res[i], 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[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
index++
res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
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 {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
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
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
index++
res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]*LedgerWitnessRule, len(arr))
for i := range res {
res[i], err = itemToLedgerWitnessRule(arr[i], 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 Rules: %w", err)
}
return nil
}
// itemToLedgerWitnessCondition converts stack item into *LedgerWitnessCondition.
func itemToLedgerWitnessCondition(item stackitem.Item, err error) (*LedgerWitnessCondition, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessCondition)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessCondition from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
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++
res.Type, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Type: %w", err)
}
index++
res.Value, err = arr[index].Value(), error(nil)
if err != nil {
return fmt.Errorf("field Value: %w", err)
}
return nil
}
// itemToLedgerWitnessRule converts stack item into *LedgerWitnessRule.
func itemToLedgerWitnessRule(item stackitem.Item, err error) (*LedgerWitnessRule, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessRule)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessRule from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
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++
res.Action, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Action: %w", err)
}
index++
res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil)
if err != nil {
return fmt.Errorf("field Condition: %w", err)
}
return nil
}
// itemToUnnamed converts stack item into *Unnamed. // itemToUnnamed converts stack item into *Unnamed.
func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) {
if err != nil { if err != nil {

View file

@ -32,20 +32,6 @@ type LedgerBlock struct {
TransactionsLength *big.Int TransactionsLength *big.Int
} }
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods. // LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct { type LedgerTransaction struct {
Hash util.Uint256 Hash util.Uint256
@ -58,27 +44,6 @@ type LedgerTransaction struct {
Script []byte Script []byte
} }
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Condition *LedgerWitnessCondition
}
// ManagementABI is a contract-specific management.ABI type used by its methods. // ManagementABI is a contract-specific management.ABI type used by its methods.
type ManagementABI struct { type ManagementABI struct {
Methods []*ManagementMethod Methods []*ManagementMethod
@ -316,144 +281,6 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return nil return nil
} }
// itemToLedgerBlockSR converts stack item into *LedgerBlockSR.
func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlockSR)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlockSR from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 10 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
index++
res.PrevStateRoot, 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 PrevStateRoot: %w", err)
}
return nil
}
// itemToLedgerTransaction converts stack item into *LedgerTransaction. // itemToLedgerTransaction converts stack item into *LedgerTransaction.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) { func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil { if err != nil {
@ -550,213 +377,6 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return nil return nil
} }
// itemToLedgerTransactionSigner converts stack item into *LedgerTransactionSigner.
func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTransactionSigner, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransactionSigner)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransactionSigner from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 5 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Account, 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 Account: %w", err)
}
index++
res.Scopes, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Scopes: %w", err)
}
index++
res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
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 {
res[i], 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[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
index++
res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
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 {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
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
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
index++
res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]*LedgerWitnessRule, len(arr))
for i := range res {
res[i], err = itemToLedgerWitnessRule(arr[i], 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 Rules: %w", err)
}
return nil
}
// itemToLedgerWitnessCondition converts stack item into *LedgerWitnessCondition.
func itemToLedgerWitnessCondition(item stackitem.Item, err error) (*LedgerWitnessCondition, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessCondition)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessCondition from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
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++
res.Type, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Type: %w", err)
}
index++
res.Value, err = arr[index].Value(), error(nil)
if err != nil {
return fmt.Errorf("field Value: %w", err)
}
return nil
}
// itemToLedgerWitnessRule converts stack item into *LedgerWitnessRule.
func itemToLedgerWitnessRule(item stackitem.Item, err error) (*LedgerWitnessRule, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessRule)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessRule from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
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++
res.Action, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Action: %w", err)
}
index++
res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil)
if err != nil {
return fmt.Errorf("field Condition: %w", err)
}
return nil
}
// itemToManagementABI converts stack item into *ManagementABI. // itemToManagementABI converts stack item into *ManagementABI.
func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) { func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) {
if err != nil { if err != nil {

View file

@ -29,20 +29,6 @@ type LedgerBlock struct {
TransactionsLength *big.Int TransactionsLength *big.Int
} }
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods. // LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct { type LedgerTransaction struct {
Hash util.Uint256 Hash util.Uint256
@ -55,27 +41,6 @@ type LedgerTransaction struct {
Script []byte Script []byte
} }
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Condition *LedgerWitnessCondition
}
// ManagementABI is a contract-specific management.ABI type used by its methods. // ManagementABI is a contract-specific management.ABI type used by its methods.
type ManagementABI struct { type ManagementABI struct {
Methods []*ManagementMethod Methods []*ManagementMethod
@ -312,144 +277,6 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return nil return nil
} }
// itemToLedgerBlockSR converts stack item into *LedgerBlockSR.
func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error) {
if err != nil {
return nil, err
}
var res = new(LedgerBlockSR)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerBlockSR from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 10 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Hash, 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 Hash: %w", err)
}
index++
res.Version, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Version: %w", err)
}
index++
res.PrevHash, 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 PrevHash: %w", err)
}
index++
res.MerkleRoot, 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 MerkleRoot: %w", err)
}
index++
res.Timestamp, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Timestamp: %w", err)
}
index++
res.Nonce, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Nonce: %w", err)
}
index++
res.Index, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Index: %w", err)
}
index++
res.NextConsensus, 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 NextConsensus: %w", err)
}
index++
res.TransactionsLength, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field TransactionsLength: %w", err)
}
index++
res.PrevStateRoot, 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 PrevStateRoot: %w", err)
}
return nil
}
// itemToLedgerTransaction converts stack item into *LedgerTransaction. // itemToLedgerTransaction converts stack item into *LedgerTransaction.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) { func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil { if err != nil {
@ -546,213 +373,6 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return nil return nil
} }
// itemToLedgerTransactionSigner converts stack item into *LedgerTransactionSigner.
func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTransactionSigner, error) {
if err != nil {
return nil, err
}
var res = new(LedgerTransactionSigner)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerTransactionSigner from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return errors.New("not an array")
}
if len(arr) != 5 {
return errors.New("wrong number of structure elements")
}
var (
index = -1
err error
)
index++
res.Account, 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 Account: %w", err)
}
index++
res.Scopes, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Scopes: %w", err)
}
index++
res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
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 {
res[i], 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[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
index++
res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
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 {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
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
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
index++
res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]*LedgerWitnessRule, len(arr))
for i := range res {
res[i], err = itemToLedgerWitnessRule(arr[i], 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 Rules: %w", err)
}
return nil
}
// itemToLedgerWitnessCondition converts stack item into *LedgerWitnessCondition.
func itemToLedgerWitnessCondition(item stackitem.Item, err error) (*LedgerWitnessCondition, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessCondition)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessCondition from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
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++
res.Type, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Type: %w", err)
}
index++
res.Value, err = arr[index].Value(), error(nil)
if err != nil {
return fmt.Errorf("field Value: %w", err)
}
return nil
}
// itemToLedgerWitnessRule converts stack item into *LedgerWitnessRule.
func itemToLedgerWitnessRule(item stackitem.Item, err error) (*LedgerWitnessRule, error) {
if err != nil {
return nil, err
}
var res = new(LedgerWitnessRule)
err = res.FromStackItem(item)
return res, err
}
// FromStackItem retrieves fields of LedgerWitnessRule from the given
// [stackitem.Item] or returns an error if it's not possible to do to so.
func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
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++
res.Action, err = arr[index].TryInteger()
if err != nil {
return fmt.Errorf("field Action: %w", err)
}
index++
res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil)
if err != nil {
return fmt.Errorf("field Condition: %w", err)
}
return nil
}
// itemToManagementABI converts stack item into *ManagementABI. // itemToManagementABI converts stack item into *ManagementABI.
func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) { func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) {
if err != nil { if err != nil {

View file

@ -206,10 +206,10 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
start := len(d.Methods) start := len(d.Methods)
d.NamedTypes = make(map[string]binding.ExtendedType) d.NamedTypes = make(map[string]binding.ExtendedType)
for name, scope := range c.funcs { for name, scope := range c.funcs {
m := c.methodInfoFromScope(name, scope, d.NamedTypes) if scope.rng.Start == scope.rng.End {
if m.Range.Start == m.Range.End {
continue continue
} }
m := c.methodInfoFromScope(name, scope, d.NamedTypes)
d.Methods = append(d.Methods, *m) d.Methods = append(d.Methods, *m)
} }
sort.Slice(d.Methods[start:], func(i, j int) bool { sort.Slice(d.Methods[start:], func(i, j int) bool {