smartcontract: apply gofmt to the resulting bindings

Close #3133.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-10-18 17:58:39 +03:00
parent d24579748e
commit c42486587d
16 changed files with 769 additions and 742 deletions

View file

@ -310,7 +310,7 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.

View file

@ -25,7 +25,7 @@ type Actor interface {
type ContractReader struct { type ContractReader struct {
nep17.TokenReader nep17.TokenReader
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// Contract implements all contract methods. // Contract implements all contract methods.
@ -33,7 +33,7 @@ type Contract struct {
ContractReader ContractReader
nep17.TokenWriter nep17.TokenWriter
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.

View file

@ -21,14 +21,14 @@ var Hash = util.Uint160{0xde, 0x46, 0x5f, 0x5d, 0x50, 0x57, 0xcf, 0x33, 0x28, 0x
// SetAdminEvent represents "SetAdmin" event emitted by the contract. // SetAdminEvent represents "SetAdmin" event emitted by the contract.
type SetAdminEvent struct { type SetAdminEvent struct {
Name string Name string
OldAdmin util.Uint160 OldAdmin util.Uint160
NewAdmin util.Uint160 NewAdmin util.Uint160
} }
// RenewEvent represents "Renew" event emitted by the contract. // RenewEvent represents "Renew" event emitted by the contract.
type RenewEvent struct { type RenewEvent struct {
Name string Name string
OldExpiration *big.Int OldExpiration *big.Int
NewExpiration *big.Int NewExpiration *big.Int
} }
@ -56,7 +56,7 @@ type Actor interface {
type ContractReader struct { type ContractReader struct {
nep11.NonDivisibleReader nep11.NonDivisibleReader
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// Contract implements all contract methods. // Contract implements all contract methods.
@ -64,7 +64,7 @@ type Contract struct {
ContractReader ContractReader
nep11.BaseWriter nep11.BaseWriter
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
@ -383,10 +383,10 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.Name, err = func (item stackitem.Item) (string, error) { e.Name, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -395,13 +395,13 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Name: %w", err) return fmt.Errorf("field Name: %w", err)
} }
index++ index++
e.OldAdmin, err = func (item stackitem.Item) (util.Uint160, error) { e.OldAdmin, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -411,13 +411,13 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field OldAdmin: %w", err) return fmt.Errorf("field OldAdmin: %w", err)
} }
index++ index++
e.NewAdmin, err = func (item stackitem.Item) (util.Uint160, error) { e.NewAdmin, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -427,7 +427,7 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NewAdmin: %w", err) return fmt.Errorf("field NewAdmin: %w", err)
} }
@ -476,10 +476,10 @@ func (e *RenewEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.Name, err = func (item stackitem.Item) (string, error) { e.Name, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -488,7 +488,7 @@ func (e *RenewEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Name: %w", err) return fmt.Errorf("field Name: %w", err)
} }

View file

@ -19,8 +19,8 @@ var Hash = util.Uint160{0xa8, 0x1a, 0xa1, 0xf0, 0x4b, 0xf, 0xdc, 0x4a, 0xa2, 0xc
// OnMintEvent represents "OnMint" event emitted by the contract. // OnMintEvent represents "OnMint" event emitted by the contract.
type OnMintEvent struct { type OnMintEvent struct {
From util.Uint160 From util.Uint160
To util.Uint160 To util.Uint160
Amount *big.Int Amount *big.Int
SwapId *big.Int SwapId *big.Int
} }
@ -48,7 +48,7 @@ type Actor interface {
type ContractReader struct { type ContractReader struct {
nep17.TokenReader nep17.TokenReader
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// Contract implements all contract methods. // Contract implements all contract methods.
@ -56,7 +56,7 @@ type Contract struct {
ContractReader ContractReader
nep17.TokenWriter nep17.TokenWriter
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
@ -287,10 +287,10 @@ func (e *OnMintEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.From, err = func (item stackitem.Item) (util.Uint160, error) { e.From, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -300,13 +300,13 @@ func (e *OnMintEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field From: %w", err) return fmt.Errorf("field From: %w", err)
} }
index++ index++
e.To, err = func (item stackitem.Item) (util.Uint160, error) { e.To, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -316,7 +316,7 @@ func (e *OnMintEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field To: %w", err) return fmt.Errorf("field To: %w", err)
} }

View file

@ -23,7 +23,7 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.

View file

@ -19,61 +19,61 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa
// LedgerBlock is a contract-specific ledger.Block type used by its methods. // LedgerBlock is a contract-specific ledger.Block type used by its methods.
type LedgerBlock struct { type LedgerBlock struct {
Hash util.Uint256 Hash util.Uint256
Version *big.Int Version *big.Int
PrevHash util.Uint256 PrevHash util.Uint256
MerkleRoot util.Uint256 MerkleRoot util.Uint256
Timestamp *big.Int Timestamp *big.Int
Nonce *big.Int Nonce *big.Int
Index *big.Int Index *big.Int
NextConsensus util.Uint160 NextConsensus util.Uint160
TransactionsLength *big.Int TransactionsLength *big.Int
} }
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods. // LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct { type LedgerBlockSR struct {
Hash util.Uint256 Hash util.Uint256
Version *big.Int Version *big.Int
PrevHash util.Uint256 PrevHash util.Uint256
MerkleRoot util.Uint256 MerkleRoot util.Uint256
Timestamp *big.Int Timestamp *big.Int
Nonce *big.Int Nonce *big.Int
Index *big.Int Index *big.Int
NextConsensus util.Uint160 NextConsensus util.Uint160
TransactionsLength *big.Int TransactionsLength *big.Int
PrevStateRoot util.Uint256 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
Version *big.Int Version *big.Int
Nonce *big.Int Nonce *big.Int
Sender util.Uint160 Sender util.Uint160
SysFee *big.Int SysFee *big.Int
NetFee *big.Int NetFee *big.Int
ValidUntilBlock *big.Int ValidUntilBlock *big.Int
Script []byte Script []byte
} }
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods. // LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct { type LedgerTransactionSigner struct {
Account util.Uint160 Account util.Uint160
Scopes *big.Int Scopes *big.Int
AllowedContracts []util.Uint160 AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule Rules []*LedgerWitnessRule
} }
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods. // LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct { type LedgerWitnessCondition struct {
Type *big.Int Type *big.Int
Value any Value any
} }
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods. // LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct { type LedgerWitnessRule struct {
Action *big.Int Action *big.Int
Condition *LedgerWitnessCondition Condition *LedgerWitnessCondition
} }
@ -115,7 +115,7 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
@ -257,10 +257,10 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -270,7 +270,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -282,7 +282,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevHash, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -292,13 +292,13 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevHash: %w", err) return fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
res.MerkleRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -308,7 +308,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err) return fmt.Errorf("field MerkleRoot: %w", err)
} }
@ -332,7 +332,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.NextConsensus, err = func (item stackitem.Item) (util.Uint160, error) { res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -342,7 +342,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NextConsensus: %w", err) return fmt.Errorf("field NextConsensus: %w", err)
} }
@ -379,10 +379,10 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -392,7 +392,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -404,7 +404,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevHash, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -414,13 +414,13 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevHash: %w", err) return fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
res.MerkleRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -430,7 +430,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err) return fmt.Errorf("field MerkleRoot: %w", err)
} }
@ -454,7 +454,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.NextConsensus, err = func (item stackitem.Item) (util.Uint160, error) { res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -464,7 +464,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NextConsensus: %w", err) return fmt.Errorf("field NextConsensus: %w", err)
} }
@ -476,7 +476,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevStateRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevStateRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -486,7 +486,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevStateRoot: %w", err) return fmt.Errorf("field PrevStateRoot: %w", err)
} }
@ -517,10 +517,10 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -530,7 +530,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -548,7 +548,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.Sender, err = func (item stackitem.Item) (util.Uint160, error) { res.Sender, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -558,7 +558,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Sender: %w", err) return fmt.Errorf("field Sender: %w", err)
} }
@ -613,10 +613,10 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Account, err = func (item stackitem.Item) (util.Uint160, error) { res.Account, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -626,7 +626,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Account: %w", err) return fmt.Errorf("field Account: %w", err)
} }
@ -638,14 +638,14 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.AllowedContracts, err = func (item stackitem.Item) ([]util.Uint160, error) { res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -655,26 +655,26 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err) return fmt.Errorf("field AllowedContracts: %w", err)
} }
index++ index++
res.AllowedGroups, err = func (item stackitem.Item) (keys.PublicKeys, error) { res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make(keys.PublicKeys, len(arr)) res := make(keys.PublicKeys, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (*keys.PublicKey, error) { res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return nil, err return nil, err
@ -684,19 +684,19 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return nil, err return nil, err
} }
return k, nil return k, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err) return fmt.Errorf("field AllowedGroups: %w", err)
} }
index++ index++
res.Rules, err = func (item stackitem.Item) ([]*LedgerWitnessRule, error) { res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -709,7 +709,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Rules: %w", err) return fmt.Errorf("field Rules: %w", err)
} }
@ -740,7 +740,7 @@ func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Type, err = arr[index].TryInteger() res.Type, err = arr[index].TryInteger()
@ -780,7 +780,7 @@ func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Action, err = arr[index].TryInteger() res.Action, err = arr[index].TryInteger()
@ -838,10 +838,10 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.ComplicatedParam, err = func (item stackitem.Item) (string, error) { e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -850,7 +850,7 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field ComplicatedParam: %w", err) return fmt.Errorf("field ComplicatedParam: %w", err)
} }
@ -899,10 +899,10 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.M, err = func (item stackitem.Item) (map[any]any, error) { e.M, err = func(item stackitem.Item) (map[any]any, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -920,7 +920,7 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field M: %w", err) return fmt.Errorf("field M: %w", err)
} }
@ -969,10 +969,10 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.S, err = func (item stackitem.Item) ([]any, error) { e.S, err = func(item stackitem.Item) ([]any, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -985,7 +985,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field S: %w", err) return fmt.Errorf("field S: %w", err)
} }
@ -1034,10 +1034,10 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.A, err = func (item stackitem.Item) ([]any, error) { e.A, err = func(item stackitem.Item) ([]any, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -1050,7 +1050,7 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field A: %w", err) return fmt.Errorf("field A: %w", err)
} }
@ -1099,10 +1099,10 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.S, err = func (item stackitem.Item) ([]any, error) { e.S, err = func(item stackitem.Item) ([]any, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -1115,7 +1115,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field S: %w", err) return fmt.Errorf("field S: %w", err)
} }

View file

@ -25,61 +25,61 @@ type CrazyStruct struct {
// LedgerBlock is a contract-specific ledger.Block type used by its methods. // LedgerBlock is a contract-specific ledger.Block type used by its methods.
type LedgerBlock struct { type LedgerBlock struct {
Hash util.Uint256 Hash util.Uint256
Version *big.Int Version *big.Int
PrevHash util.Uint256 PrevHash util.Uint256
MerkleRoot util.Uint256 MerkleRoot util.Uint256
Timestamp *big.Int Timestamp *big.Int
Nonce *big.Int Nonce *big.Int
Index *big.Int Index *big.Int
NextConsensus util.Uint160 NextConsensus util.Uint160
TransactionsLength *big.Int TransactionsLength *big.Int
} }
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods. // LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct { type LedgerBlockSR struct {
Hash util.Uint256 Hash util.Uint256
Version *big.Int Version *big.Int
PrevHash util.Uint256 PrevHash util.Uint256
MerkleRoot util.Uint256 MerkleRoot util.Uint256
Timestamp *big.Int Timestamp *big.Int
Nonce *big.Int Nonce *big.Int
Index *big.Int Index *big.Int
NextConsensus util.Uint160 NextConsensus util.Uint160
TransactionsLength *big.Int TransactionsLength *big.Int
PrevStateRoot util.Uint256 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
Version *big.Int Version *big.Int
Nonce *big.Int Nonce *big.Int
Sender util.Uint160 Sender util.Uint160
SysFee *big.Int SysFee *big.Int
NetFee *big.Int NetFee *big.Int
ValidUntilBlock *big.Int ValidUntilBlock *big.Int
Script []byte Script []byte
} }
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods. // LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct { type LedgerTransactionSigner struct {
Account util.Uint160 Account util.Uint160
Scopes *big.Int Scopes *big.Int
AllowedContracts []util.Uint160 AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule Rules []*LedgerWitnessRule
} }
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods. // LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct { type LedgerWitnessCondition struct {
Type *big.Int Type *big.Int
Value any Value any
} }
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods. // LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct { type LedgerWitnessRule struct {
Action *big.Int Action *big.Int
Condition *LedgerWitnessCondition Condition *LedgerWitnessCondition
} }
@ -126,7 +126,7 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
@ -268,7 +268,7 @@ func (res *CrazyStruct) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.I, err = arr[index].TryInteger() res.I, err = arr[index].TryInteger()
@ -308,10 +308,10 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -321,7 +321,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -333,7 +333,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevHash, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -343,13 +343,13 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevHash: %w", err) return fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
res.MerkleRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -359,7 +359,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err) return fmt.Errorf("field MerkleRoot: %w", err)
} }
@ -383,7 +383,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.NextConsensus, err = func (item stackitem.Item) (util.Uint160, error) { res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -393,7 +393,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NextConsensus: %w", err) return fmt.Errorf("field NextConsensus: %w", err)
} }
@ -430,10 +430,10 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -443,7 +443,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -455,7 +455,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevHash, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -465,13 +465,13 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevHash: %w", err) return fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
res.MerkleRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -481,7 +481,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err) return fmt.Errorf("field MerkleRoot: %w", err)
} }
@ -505,7 +505,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.NextConsensus, err = func (item stackitem.Item) (util.Uint160, error) { res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -515,7 +515,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NextConsensus: %w", err) return fmt.Errorf("field NextConsensus: %w", err)
} }
@ -527,7 +527,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevStateRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevStateRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -537,7 +537,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevStateRoot: %w", err) return fmt.Errorf("field PrevStateRoot: %w", err)
} }
@ -568,10 +568,10 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -581,7 +581,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -599,7 +599,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.Sender, err = func (item stackitem.Item) (util.Uint160, error) { res.Sender, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -609,7 +609,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Sender: %w", err) return fmt.Errorf("field Sender: %w", err)
} }
@ -664,10 +664,10 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Account, err = func (item stackitem.Item) (util.Uint160, error) { res.Account, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -677,7 +677,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Account: %w", err) return fmt.Errorf("field Account: %w", err)
} }
@ -689,14 +689,14 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.AllowedContracts, err = func (item stackitem.Item) ([]util.Uint160, error) { res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -706,26 +706,26 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err) return fmt.Errorf("field AllowedContracts: %w", err)
} }
index++ index++
res.AllowedGroups, err = func (item stackitem.Item) (keys.PublicKeys, error) { res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make(keys.PublicKeys, len(arr)) res := make(keys.PublicKeys, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (*keys.PublicKey, error) { res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return nil, err return nil, err
@ -735,19 +735,19 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return nil, err return nil, err
} }
return k, nil return k, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err) return fmt.Errorf("field AllowedGroups: %w", err)
} }
index++ index++
res.Rules, err = func (item stackitem.Item) ([]*LedgerWitnessRule, error) { res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -760,7 +760,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Rules: %w", err) return fmt.Errorf("field Rules: %w", err)
} }
@ -791,7 +791,7 @@ func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Type, err = arr[index].TryInteger() res.Type, err = arr[index].TryInteger()
@ -831,7 +831,7 @@ func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Action, err = arr[index].TryInteger() res.Action, err = arr[index].TryInteger()
@ -871,7 +871,7 @@ func (res *SimpleStruct) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.I, err = arr[index].TryInteger() res.I, err = arr[index].TryInteger()
@ -923,10 +923,10 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.ComplicatedParam, err = func (item stackitem.Item) (string, error) { e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -935,7 +935,7 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field ComplicatedParam: %w", err) return fmt.Errorf("field ComplicatedParam: %w", err)
} }
@ -984,10 +984,10 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.M, err = func (item stackitem.Item) (map[*big.Int]map[string][]util.Uint160, error) { e.M, err = func(item stackitem.Item) (map[*big.Int]map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -998,14 +998,14 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) (map[string][]util.Uint160, error) { v, err := func(item stackitem.Item) (map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
} }
res := make(map[string][]util.Uint160) res := make(map[string][]util.Uint160)
for i := range m { for i := range m {
k, err := func (item stackitem.Item) (string, error) { k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -1014,18 +1014,18 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Key) }(m[i].Key)
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]util.Uint160, error) { v, err := func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -1035,27 +1035,27 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field M: %w", err) return fmt.Errorf("field M: %w", err)
} }
@ -1104,7 +1104,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.S, err = itemToCrazyStruct(arr[index], nil) e.S, err = itemToCrazyStruct(arr[index], nil)
@ -1156,17 +1156,17 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.A, err = func (item stackitem.Item) ([][]*big.Int, error) { e.A, err = func(item stackitem.Item) ([][]*big.Int, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([][]*big.Int, len(arr)) res := make([][]*big.Int, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) ([]*big.Int, error) { res[i], err = func(item stackitem.Item) ([]*big.Int, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -1179,13 +1179,13 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
} }
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field A: %w", err) return fmt.Errorf("field A: %w", err)
} }
@ -1234,7 +1234,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.S, err = itemToSimpleStruct(arr[index], nil) e.S, err = itemToSimpleStruct(arr[index], nil)

View file

@ -19,61 +19,61 @@ var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xa
// LedgerBlock is a contract-specific ledger.Block type used by its methods. // LedgerBlock is a contract-specific ledger.Block type used by its methods.
type LedgerBlock struct { type LedgerBlock struct {
Hash util.Uint256 Hash util.Uint256
Version *big.Int Version *big.Int
PrevHash util.Uint256 PrevHash util.Uint256
MerkleRoot util.Uint256 MerkleRoot util.Uint256
Timestamp *big.Int Timestamp *big.Int
Nonce *big.Int Nonce *big.Int
Index *big.Int Index *big.Int
NextConsensus util.Uint160 NextConsensus util.Uint160
TransactionsLength *big.Int TransactionsLength *big.Int
} }
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods. // LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct { type LedgerBlockSR struct {
Hash util.Uint256 Hash util.Uint256
Version *big.Int Version *big.Int
PrevHash util.Uint256 PrevHash util.Uint256
MerkleRoot util.Uint256 MerkleRoot util.Uint256
Timestamp *big.Int Timestamp *big.Int
Nonce *big.Int Nonce *big.Int
Index *big.Int Index *big.Int
NextConsensus util.Uint160 NextConsensus util.Uint160
TransactionsLength *big.Int TransactionsLength *big.Int
PrevStateRoot util.Uint256 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
Version *big.Int Version *big.Int
Nonce *big.Int Nonce *big.Int
Sender util.Uint160 Sender util.Uint160
SysFee *big.Int SysFee *big.Int
NetFee *big.Int NetFee *big.Int
ValidUntilBlock *big.Int ValidUntilBlock *big.Int
Script []byte Script []byte
} }
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods. // LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct { type LedgerTransactionSigner struct {
Account util.Uint160 Account util.Uint160
Scopes *big.Int Scopes *big.Int
AllowedContracts []util.Uint160 AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule Rules []*LedgerWitnessRule
} }
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods. // LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct { type LedgerWitnessCondition struct {
Type *big.Int Type *big.Int
Value any Value any
} }
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods. // LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct { type LedgerWitnessRule struct {
Action *big.Int Action *big.Int
Condition *LedgerWitnessCondition Condition *LedgerWitnessCondition
} }
@ -121,7 +121,7 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
@ -263,10 +263,10 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -276,7 +276,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -288,7 +288,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevHash, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -298,13 +298,13 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevHash: %w", err) return fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
res.MerkleRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -314,7 +314,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err) return fmt.Errorf("field MerkleRoot: %w", err)
} }
@ -338,7 +338,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.NextConsensus, err = func (item stackitem.Item) (util.Uint160, error) { res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -348,7 +348,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NextConsensus: %w", err) return fmt.Errorf("field NextConsensus: %w", err)
} }
@ -385,10 +385,10 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -398,7 +398,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -410,7 +410,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevHash, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -420,13 +420,13 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevHash: %w", err) return fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
res.MerkleRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -436,7 +436,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err) return fmt.Errorf("field MerkleRoot: %w", err)
} }
@ -460,7 +460,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.NextConsensus, err = func (item stackitem.Item) (util.Uint160, error) { res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -470,7 +470,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field NextConsensus: %w", err) return fmt.Errorf("field NextConsensus: %w", err)
} }
@ -482,7 +482,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.PrevStateRoot, err = func (item stackitem.Item) (util.Uint256, error) { res.PrevStateRoot, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -492,7 +492,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field PrevStateRoot: %w", err) return fmt.Errorf("field PrevStateRoot: %w", err)
} }
@ -523,10 +523,10 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Hash, err = func (item stackitem.Item) (util.Uint256, error) { res.Hash, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint256{}, err return util.Uint256{}, err
@ -536,7 +536,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err return util.Uint256{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Hash: %w", err) return fmt.Errorf("field Hash: %w", err)
} }
@ -554,7 +554,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.Sender, err = func (item stackitem.Item) (util.Uint160, error) { res.Sender, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -564,7 +564,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Sender: %w", err) return fmt.Errorf("field Sender: %w", err)
} }
@ -619,10 +619,10 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Account, err = func (item stackitem.Item) (util.Uint160, error) { res.Account, err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -632,7 +632,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Account: %w", err) return fmt.Errorf("field Account: %w", err)
} }
@ -644,14 +644,14 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
} }
index++ index++
res.AllowedContracts, err = func (item stackitem.Item) ([]util.Uint160, error) { res.AllowedContracts, err = func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -661,26 +661,26 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err) return fmt.Errorf("field AllowedContracts: %w", err)
} }
index++ index++
res.AllowedGroups, err = func (item stackitem.Item) (keys.PublicKeys, error) { res.AllowedGroups, err = func(item stackitem.Item) (keys.PublicKeys, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make(keys.PublicKeys, len(arr)) res := make(keys.PublicKeys, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (*keys.PublicKey, error) { res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return nil, err return nil, err
@ -690,19 +690,19 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return nil, err return nil, err
} }
return k, nil return k, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err) return fmt.Errorf("field AllowedGroups: %w", err)
} }
index++ index++
res.Rules, err = func (item stackitem.Item) ([]*LedgerWitnessRule, error) { res.Rules, err = func(item stackitem.Item) ([]*LedgerWitnessRule, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -715,7 +715,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Rules: %w", err) return fmt.Errorf("field Rules: %w", err)
} }
@ -746,7 +746,7 @@ func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Type, err = arr[index].TryInteger() res.Type, err = arr[index].TryInteger()
@ -786,7 +786,7 @@ func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.Action, err = arr[index].TryInteger() res.Action, err = arr[index].TryInteger()
@ -826,7 +826,7 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
res.I, err = arr[index].TryInteger() res.I, err = arr[index].TryInteger()
@ -884,10 +884,10 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.ComplicatedParam, err = func (item stackitem.Item) (string, error) { e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -896,7 +896,7 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field ComplicatedParam: %w", err) return fmt.Errorf("field ComplicatedParam: %w", err)
} }
@ -945,10 +945,10 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.M, err = func (item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) { e.M, err = func(item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -959,21 +959,21 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]map[string][]util.Uint160, error) { v, err := func(item stackitem.Item) ([]map[string][]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]map[string][]util.Uint160, len(arr)) res := make([]map[string][]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (map[string][]util.Uint160, error) { res[i], err = func(item stackitem.Item) (map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
} }
res := make(map[string][]util.Uint160) res := make(map[string][]util.Uint160)
for i := range m { for i := range m {
k, err := func (item stackitem.Item) (string, error) { k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -982,18 +982,18 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Key) }(m[i].Key)
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]util.Uint160, error) { v, err := func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -1003,33 +1003,33 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field M: %w", err) return fmt.Errorf("field M: %w", err)
} }
@ -1078,7 +1078,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.S, err = itemToUnnamed(arr[index], nil) e.S, err = itemToUnnamed(arr[index], nil)
@ -1130,17 +1130,17 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.A, err = func (item stackitem.Item) ([][]*big.Int, error) { e.A, err = func(item stackitem.Item) ([][]*big.Int, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([][]*big.Int, len(arr)) res := make([][]*big.Int, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) ([]*big.Int, error) { res[i], err = func(item stackitem.Item) ([]*big.Int, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -1153,13 +1153,13 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
} }
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field A: %w", err) return fmt.Errorf("field A: %w", err)
} }
@ -1208,7 +1208,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.S, err = itemToUnnamed(arr[index], nil) e.S, err = itemToUnnamed(arr[index], nil)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -24,7 +24,7 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
@ -35,32 +35,32 @@ func NewReader(invoker Invoker) *ContractReader {
// AAAStrings invokes `aAAStrings` method of contract. // AAAStrings invokes `aAAStrings` method of contract.
func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) { func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return func (item stackitem.Item, err error) ([][][]string, error) { return func(item stackitem.Item, err error) ([][][]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) ([][][]string, error) { return func(item stackitem.Item) ([][][]string, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([][][]string, len(arr)) res := make([][][]string, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) ([][]string, error) { res[i], err = func(item stackitem.Item) ([][]string, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([][]string, len(arr)) res := make([][]string, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) ([]string, error) { res[i], err = func(item stackitem.Item) ([]string, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]string, len(arr)) res := make([]string, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (string, error) { res[i], err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -69,45 +69,45 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s))) }(unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
} }
// Any invokes `any` method of contract. // Any invokes `any` method of contract.
func (c *ContractReader) Any(a any) (any, error) { func (c *ContractReader) Any(a any) (any, error) {
return func (item stackitem.Item, err error) (any, error) { return func(item stackitem.Item, err error) (any, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return item.Value(), error(nil) return item.Value(), error(nil)
} (unwrap.Item(c.invoker.Call(c.hash, "any", a))) }(unwrap.Item(c.invoker.Call(c.hash, "any", a)))
} }
// AnyMaps invokes `anyMaps` method of contract. // AnyMaps invokes `anyMaps` method of contract.
func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) { func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) {
return func (item stackitem.Item, err error) (map[*big.Int]any, error) { return func(item stackitem.Item, err error) (map[*big.Int]any, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) (map[*big.Int]any, error) { return func(item stackitem.Item) (map[*big.Int]any, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -125,8 +125,8 @@ func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) {
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m))) }(unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
} }
// Bool invokes `bool` method of contract. // Bool invokes `bool` method of contract.
@ -151,11 +151,11 @@ func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) {
// CrazyMaps invokes `crazyMaps` method of contract. // CrazyMaps invokes `crazyMaps` method of contract.
func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (map[*big.Int][]map[string][]util.Uint160, error) { func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (map[*big.Int][]map[string][]util.Uint160, error) {
return func (item stackitem.Item, err error) (map[*big.Int][]map[string][]util.Uint160, error) { return func(item stackitem.Item, err error) (map[*big.Int][]map[string][]util.Uint160, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) { return func(item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -166,21 +166,21 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]map[string][]util.Uint160, error) { v, err := func(item stackitem.Item) ([]map[string][]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]map[string][]util.Uint160, len(arr)) res := make([]map[string][]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (map[string][]util.Uint160, error) { res[i], err = func(item stackitem.Item) (map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
} }
res := make(map[string][]util.Uint160) res := make(map[string][]util.Uint160)
for i := range m { for i := range m {
k, err := func (item stackitem.Item) (string, error) { k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -189,18 +189,18 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Key) }(m[i].Key)
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]util.Uint160, error) { v, err := func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -210,34 +210,34 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m))) }(unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
} }
// Hash160 invokes `hash160` method of contract. // Hash160 invokes `hash160` method of contract.
@ -272,18 +272,18 @@ func (c *ContractReader) Ints(i []*big.Int) ([]*big.Int, error) {
// Maps invokes `maps` method of contract. // Maps invokes `maps` method of contract.
func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) { func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return func (item stackitem.Item, err error) (map[string]string, error) { return func(item stackitem.Item, err error) (map[string]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) (map[string]string, error) { return func(item stackitem.Item) (map[string]string, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
} }
res := make(map[string]string) res := make(map[string]string)
for i := range m { for i := range m {
k, err := func (item stackitem.Item) (string, error) { k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -292,11 +292,11 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Key) }(m[i].Key)
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) (string, error) { v, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -305,15 +305,15 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "maps", m))) }(unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
} }
// PublicKey invokes `publicKey` method of contract. // PublicKey invokes `publicKey` method of contract.

View file

@ -21,7 +21,7 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160 hash util.Uint160
} }
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker. // NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
@ -31,32 +31,32 @@ func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
// AAAStrings invokes `aAAStrings` method of contract. // AAAStrings invokes `aAAStrings` method of contract.
func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) { func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return func (item stackitem.Item, err error) ([][][]string, error) { return func(item stackitem.Item, err error) ([][][]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) ([][][]string, error) { return func(item stackitem.Item) ([][][]string, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([][][]string, len(arr)) res := make([][][]string, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) ([][]string, error) { res[i], err = func(item stackitem.Item) ([][]string, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([][]string, len(arr)) res := make([][]string, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) ([]string, error) { res[i], err = func(item stackitem.Item) ([]string, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]string, len(arr)) res := make([]string, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (string, error) { res[i], err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -65,45 +65,45 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s))) }(unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
} }
// Any invokes `any` method of contract. // Any invokes `any` method of contract.
func (c *ContractReader) Any(a any) (any, error) { func (c *ContractReader) Any(a any) (any, error) {
return func (item stackitem.Item, err error) (any, error) { return func(item stackitem.Item, err error) (any, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return item.Value(), error(nil) return item.Value(), error(nil)
} (unwrap.Item(c.invoker.Call(c.hash, "any", a))) }(unwrap.Item(c.invoker.Call(c.hash, "any", a)))
} }
// AnyMaps invokes `anyMaps` method of contract. // AnyMaps invokes `anyMaps` method of contract.
func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) { func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) {
return func (item stackitem.Item, err error) (map[*big.Int]any, error) { return func(item stackitem.Item, err error) (map[*big.Int]any, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) (map[*big.Int]any, error) { return func(item stackitem.Item) (map[*big.Int]any, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -121,8 +121,8 @@ func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) {
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m))) }(unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
} }
// Bool invokes `bool` method of contract. // Bool invokes `bool` method of contract.
@ -147,11 +147,11 @@ func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) {
// CrazyMaps invokes `crazyMaps` method of contract. // CrazyMaps invokes `crazyMaps` method of contract.
func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (map[*big.Int][]map[string][]util.Uint160, error) { func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (map[*big.Int][]map[string][]util.Uint160, error) {
return func (item stackitem.Item, err error) (map[*big.Int][]map[string][]util.Uint160, error) { return func(item stackitem.Item, err error) (map[*big.Int][]map[string][]util.Uint160, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) { return func(item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -162,21 +162,21 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]map[string][]util.Uint160, error) { v, err := func(item stackitem.Item) ([]map[string][]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]map[string][]util.Uint160, len(arr)) res := make([]map[string][]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (map[string][]util.Uint160, error) { res[i], err = func(item stackitem.Item) (map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
} }
res := make(map[string][]util.Uint160) res := make(map[string][]util.Uint160)
for i := range m { for i := range m {
k, err := func (item stackitem.Item) (string, error) { k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -185,18 +185,18 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Key) }(m[i].Key)
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) ([]util.Uint160, error) { v, err := func(item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
} }
res := make([]util.Uint160, len(arr)) res := make([]util.Uint160, len(arr))
for i := range res { for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) { res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
@ -206,34 +206,34 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
return util.Uint160{}, err return util.Uint160{}, err
} }
return u, nil return u, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (arr[i]) }(arr[i])
if err != nil { if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err) return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m))) }(unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
} }
// Hash160 invokes `hash160` method of contract. // Hash160 invokes `hash160` method of contract.
@ -268,18 +268,18 @@ func (c *ContractReader) Ints(i []*big.Int) ([]*big.Int, error) {
// Maps invokes `maps` method of contract. // Maps invokes `maps` method of contract.
func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) { func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return func (item stackitem.Item, err error) (map[string]string, error) { return func(item stackitem.Item, err error) (map[string]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return func (item stackitem.Item) (map[string]string, error) { return func(item stackitem.Item) (map[string]string, error) {
m, ok := item.Value().([]stackitem.MapElement) m, ok := item.Value().([]stackitem.MapElement)
if !ok { if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String()) return nil, fmt.Errorf("%s is not a map", item.Type().String())
} }
res := make(map[string]string) res := make(map[string]string)
for i := range m { for i := range m {
k, err := func (item stackitem.Item) (string, error) { k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -288,11 +288,11 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Key) }(m[i].Key)
if err != nil { if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err) return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) (string, error) { v, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes() b, err := item.TryBytes()
if err != nil { if err != nil {
return "", err return "", err
@ -301,15 +301,15 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return "", errors.New("not a UTF-8 string") return "", errors.New("not a UTF-8 string")
} }
return string(b), nil return string(b), nil
} (m[i].Value) }(m[i].Value)
if err != nil { if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err) return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
return res, nil return res, nil
} (item) }(item)
} (unwrap.Item(c.invoker.Call(c.hash, "maps", m))) }(unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
} }
// PublicKey invokes `publicKey` method of contract. // PublicKey invokes `publicKey` method of contract.

View file

@ -32,7 +32,7 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160 hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
@ -120,10 +120,10 @@ func (e *HelloWorldEvent) FromStackItem(item *stackitem.Array) error {
var ( var (
index = -1 index = -1
err error err error
) )
index++ index++
e.Args, err = func (item stackitem.Item) ([]any, error) { e.Args, err = func(item stackitem.Item) ([]any, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok { if !ok {
return nil, errors.New("not an array") return nil, errors.New("not an array")
@ -136,7 +136,7 @@ func (e *HelloWorldEvent) FromStackItem(item *stackitem.Array) error {
} }
} }
return res, nil return res, nil
} (arr[index]) }(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field Args: %w", err) return fmt.Errorf("field Args: %w", err)
} }

View file

@ -3,6 +3,7 @@ package binding
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"go/format"
"go/token" "go/token"
"io" "io"
"sort" "sort"
@ -127,7 +128,32 @@ func Generate(cfg Config) error {
ctr.Imports = append(ctr.Imports, "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal") ctr.Imports = append(ctr.Imports, "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal")
sort.Strings(ctr.Imports) sort.Strings(ctr.Imports)
return srcTemplate.Execute(cfg.Output, ctr) return FExecute(srcTemplate, cfg.Output, ctr)
}
// FExecute tries to execute given template over the data provided, apply gofmt
// rules to the result and write the result to the provided io.Writer. If a
// format error occurs while formatting the resulting binding, then the generated
// binding is written "as is" and no error is returned.
func FExecute(tmplt *template.Template, out io.Writer, data any) error {
in := bytes.NewBuffer(nil)
err := tmplt.Execute(in, data)
if err != nil {
return fmt.Errorf("failed to execute template: %w", err)
}
res := in.Bytes()
fmtRes, err := format.Source(res)
if err != nil {
// OK, still write something to the resulting file, our generator has known
// bugs that make the resulting code uncompilable.
fmtRes = res
}
_, err = out.Write(fmtRes)
if err != nil {
return fmt.Errorf("failed to write the resulting binding: %w", err)
}
return nil
} }
func scTypeToGo(name string, typ smartcontract.ParamType, cfg *Config) (string, string) { func scTypeToGo(name string, typ smartcontract.ParamType, cfg *Config) (string, string) {

View file

@ -464,7 +464,7 @@ func Generate(cfg binding.Config) error {
"upperFirst": upperFirst, "upperFirst": upperFirst,
}).Parse(srcTmpl)) }).Parse(srcTmpl))
return srcTemplate.Execute(cfg.Output, ctr) return binding.FExecute(srcTemplate, cfg.Output, ctr)
} }
func dropManifestMethods(meths []manifest.Method, manifested []manifest.Method) []manifest.Method { func dropManifestMethods(meths []manifest.Method, manifested []manifest.Method) []manifest.Method {

View file

@ -21,6 +21,7 @@ import (
"github.com/consensys/gnark/backend/groth16" "github.com/consensys/gnark/backend/groth16"
curve "github.com/consensys/gnark/backend/groth16/bls12-381" curve "github.com/consensys/gnark/backend/groth16/bls12-381"
"github.com/consensys/gnark/backend/witness" "github.com/consensys/gnark/backend/witness"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/binding"
"github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/util/slice"
) )
@ -234,7 +235,7 @@ func GenerateVerifier(cfg Config) error {
"byteSliceToStr": byteSliceToStr, "byteSliceToStr": byteSliceToStr,
}).Parse(goVerificationTmpl)) }).Parse(goVerificationTmpl))
err := tmpl.Execute(cfg.Output, tmplParams{ err := binding.FExecute(tmpl, cfg.Output, tmplParams{
Alpha: alphaG1[:], Alpha: alphaG1[:],
Beta: betaG2[:], Beta: betaG2[:],
Gamma: gammaG2[:], Gamma: gammaG2[:],
@ -242,7 +243,7 @@ func GenerateVerifier(cfg Config) error {
ICs: kvks, ICs: kvks,
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to generate template: %w", err) return err
} }
if cfg.CfgOutput != nil { if cfg.CfgOutput != nil {