Merge pull request #3164 from nspcc-dev/pretty-generator

Apply `gofmt` to autogenerated bindings
This commit is contained in:
Roman Khimov 2023-10-18 18:41:32 +03:00 committed by GitHub
commit ef2bc7ca04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 784 additions and 757 deletions

View file

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

View file

@ -25,7 +25,7 @@ type Actor interface {
type ContractReader struct {
nep17.TokenReader
invoker Invoker
hash util.Uint160
hash util.Uint160
}
// Contract implements all contract methods.
@ -33,7 +33,7 @@ type Contract struct {
ContractReader
nep17.TokenWriter
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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.
type SetAdminEvent struct {
Name string
Name string
OldAdmin util.Uint160
NewAdmin util.Uint160
}
// RenewEvent represents "Renew" event emitted by the contract.
type RenewEvent struct {
Name string
Name string
OldExpiration *big.Int
NewExpiration *big.Int
}
@ -56,7 +56,7 @@ type Actor interface {
type ContractReader struct {
nep11.NonDivisibleReader
invoker Invoker
hash util.Uint160
hash util.Uint160
}
// Contract implements all contract methods.
@ -64,7 +64,7 @@ type Contract struct {
ContractReader
nep11.BaseWriter
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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 (
index = -1
err error
err error
)
index++
e.Name, err = func (item stackitem.Item) (string, error) {
e.Name, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -395,13 +395,13 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Name: %w", err)
}
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()
if err != nil {
return util.Uint160{}, err
@ -411,13 +411,13 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field OldAdmin: %w", err)
}
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()
if err != nil {
return util.Uint160{}, err
@ -427,7 +427,7 @@ func (e *SetAdminEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NewAdmin: %w", err)
}
@ -476,10 +476,10 @@ func (e *RenewEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
e.Name, err = func (item stackitem.Item) (string, error) {
e.Name, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -488,7 +488,7 @@ func (e *RenewEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[index])
}(arr[index])
if err != nil {
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.
type OnMintEvent struct {
From util.Uint160
To util.Uint160
From util.Uint160
To util.Uint160
Amount *big.Int
SwapId *big.Int
}
@ -48,7 +48,7 @@ type Actor interface {
type ContractReader struct {
nep17.TokenReader
invoker Invoker
hash util.Uint160
hash util.Uint160
}
// Contract implements all contract methods.
@ -56,7 +56,7 @@ type Contract struct {
ContractReader
nep17.TokenWriter
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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 (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint160{}, err
@ -300,13 +300,13 @@ func (e *OnMintEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field From: %w", err)
}
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()
if err != nil {
return util.Uint160{}, err
@ -316,7 +316,7 @@ func (e *OnMintEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field To: %w", err)
}

View file

@ -23,7 +23,7 @@ type Invoker interface {
// ContractReader implements safe contract methods.
type ContractReader struct {
invoker Invoker
hash util.Uint160
hash util.Uint160
}
// 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.
type LedgerBlock struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
}
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct {
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
ValidUntilBlock *big.Int
Script []byte
Script []byte
}
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Action *big.Int
Condition *LedgerWitnessCondition
}
@ -115,7 +115,7 @@ type Actor interface {
// Contract implements all contract methods.
type Contract struct {
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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 (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -270,7 +270,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -282,7 +282,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -292,13 +292,13 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevHash: %w", err)
}
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()
if err != nil {
return util.Uint256{}, err
@ -308,7 +308,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err)
}
@ -332,7 +332,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -342,7 +342,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NextConsensus: %w", err)
}
@ -379,10 +379,10 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -392,7 +392,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -404,7 +404,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -414,13 +414,13 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevHash: %w", err)
}
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()
if err != nil {
return util.Uint256{}, err
@ -430,7 +430,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err)
}
@ -454,7 +454,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -464,7 +464,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NextConsensus: %w", err)
}
@ -476,7 +476,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -486,7 +486,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevStateRoot: %w", err)
}
@ -517,10 +517,10 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -530,7 +530,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -548,7 +548,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -558,7 +558,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Sender: %w", err)
}
@ -613,10 +613,10 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint160{}, err
@ -626,7 +626,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Account: %w", err)
}
@ -638,14 +638,14 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
}
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
@ -655,26 +655,26 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
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)
if !ok {
return nil, errors.New("not an array")
}
res := make(keys.PublicKeys, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (*keys.PublicKey, error) {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes()
if err != nil {
return nil, err
@ -684,19 +684,19 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return nil, err
}
return k, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
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)
if !ok {
return nil, errors.New("not an array")
@ -709,7 +709,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Rules: %w", err)
}
@ -740,7 +740,7 @@ func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.Type, err = arr[index].TryInteger()
@ -780,7 +780,7 @@ func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.Action, err = arr[index].TryInteger()
@ -838,10 +838,10 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
e.ComplicatedParam, err = func (item stackitem.Item) (string, error) {
e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -850,7 +850,7 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field ComplicatedParam: %w", err)
}
@ -899,10 +899,10 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
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
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field M: %w", err)
}
@ -969,10 +969,10 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
return nil, errors.New("not an array")
@ -985,7 +985,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field S: %w", err)
}
@ -1034,10 +1034,10 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
return nil, errors.New("not an array")
@ -1050,7 +1050,7 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field A: %w", err)
}
@ -1099,10 +1099,10 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
return nil, errors.New("not an array")
@ -1115,7 +1115,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
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.
type LedgerBlock struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
}
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct {
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
ValidUntilBlock *big.Int
Script []byte
Script []byte
}
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Action *big.Int
Condition *LedgerWitnessCondition
}
@ -126,7 +126,7 @@ type Actor interface {
// Contract implements all contract methods.
type Contract struct {
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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 (
index = -1
err error
err error
)
index++
res.I, err = arr[index].TryInteger()
@ -308,10 +308,10 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -321,7 +321,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -333,7 +333,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -343,13 +343,13 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevHash: %w", err)
}
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()
if err != nil {
return util.Uint256{}, err
@ -359,7 +359,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err)
}
@ -383,7 +383,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -393,7 +393,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NextConsensus: %w", err)
}
@ -430,10 +430,10 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -443,7 +443,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -455,7 +455,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -465,13 +465,13 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevHash: %w", err)
}
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()
if err != nil {
return util.Uint256{}, err
@ -481,7 +481,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err)
}
@ -505,7 +505,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -515,7 +515,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NextConsensus: %w", err)
}
@ -527,7 +527,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -537,7 +537,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevStateRoot: %w", err)
}
@ -568,10 +568,10 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -581,7 +581,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -599,7 +599,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -609,7 +609,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Sender: %w", err)
}
@ -664,10 +664,10 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint160{}, err
@ -677,7 +677,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Account: %w", err)
}
@ -689,14 +689,14 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
}
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
@ -706,26 +706,26 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
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)
if !ok {
return nil, errors.New("not an array")
}
res := make(keys.PublicKeys, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (*keys.PublicKey, error) {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes()
if err != nil {
return nil, err
@ -735,19 +735,19 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return nil, err
}
return k, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
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)
if !ok {
return nil, errors.New("not an array")
@ -760,7 +760,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Rules: %w", err)
}
@ -791,7 +791,7 @@ func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.Type, err = arr[index].TryInteger()
@ -831,7 +831,7 @@ func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.Action, err = arr[index].TryInteger()
@ -871,7 +871,7 @@ func (res *SimpleStruct) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.I, err = arr[index].TryInteger()
@ -923,10 +923,10 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
e.ComplicatedParam, err = func (item stackitem.Item) (string, error) {
e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -935,7 +935,7 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field ComplicatedParam: %w", err)
}
@ -984,10 +984,10 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
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 {
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)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string][]util.Uint160)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -1014,18 +1014,18 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (m[i].Key)
}(m[i].Key)
if err != nil {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
@ -1035,27 +1035,27 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err
}
return u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field M: %w", err)
}
@ -1104,7 +1104,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
e.S, err = itemToCrazyStruct(arr[index], nil)
@ -1156,17 +1156,17 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([][]*big.Int, len(arr))
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)
if !ok {
return nil, errors.New("not an array")
@ -1179,13 +1179,13 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
}
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field A: %w", err)
}
@ -1234,7 +1234,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
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.
type LedgerBlock struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
}
// LedgerBlockSR is a contract-specific ledger.BlockSR type used by its methods.
type LedgerBlockSR struct {
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
Hash util.Uint256
Version *big.Int
PrevHash util.Uint256
MerkleRoot util.Uint256
Timestamp *big.Int
Nonce *big.Int
Index *big.Int
NextConsensus util.Uint160
TransactionsLength *big.Int
PrevStateRoot util.Uint256
PrevStateRoot util.Uint256
}
// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods.
type LedgerTransaction struct {
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
Hash util.Uint256
Version *big.Int
Nonce *big.Int
Sender util.Uint160
SysFee *big.Int
NetFee *big.Int
ValidUntilBlock *big.Int
Script []byte
Script []byte
}
// LedgerTransactionSigner is a contract-specific ledger.TransactionSigner type used by its methods.
type LedgerTransactionSigner struct {
Account util.Uint160
Scopes *big.Int
Account util.Uint160
Scopes *big.Int
AllowedContracts []util.Uint160
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
AllowedGroups keys.PublicKeys
Rules []*LedgerWitnessRule
}
// LedgerWitnessCondition is a contract-specific ledger.WitnessCondition type used by its methods.
type LedgerWitnessCondition struct {
Type *big.Int
Type *big.Int
Value any
}
// LedgerWitnessRule is a contract-specific ledger.WitnessRule type used by its methods.
type LedgerWitnessRule struct {
Action *big.Int
Action *big.Int
Condition *LedgerWitnessCondition
}
@ -121,7 +121,7 @@ type Actor interface {
// Contract implements all contract methods.
type Contract struct {
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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 (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -276,7 +276,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -288,7 +288,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -298,13 +298,13 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevHash: %w", err)
}
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()
if err != nil {
return util.Uint256{}, err
@ -314,7 +314,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err)
}
@ -338,7 +338,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -348,7 +348,7 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NextConsensus: %w", err)
}
@ -385,10 +385,10 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -398,7 +398,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -410,7 +410,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -420,13 +420,13 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevHash: %w", err)
}
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()
if err != nil {
return util.Uint256{}, err
@ -436,7 +436,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field MerkleRoot: %w", err)
}
@ -460,7 +460,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -470,7 +470,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field NextConsensus: %w", err)
}
@ -482,7 +482,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint256{}, err
@ -492,7 +492,7 @@ func (res *LedgerBlockSR) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field PrevStateRoot: %w", err)
}
@ -523,10 +523,10 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint256{}, err
@ -536,7 +536,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint256{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Hash: %w", err)
}
@ -554,7 +554,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
}
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()
if err != nil {
return util.Uint160{}, err
@ -564,7 +564,7 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Sender: %w", err)
}
@ -619,10 +619,10 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
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()
if err != nil {
return util.Uint160{}, err
@ -632,7 +632,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Account: %w", err)
}
@ -644,14 +644,14 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
}
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
@ -661,26 +661,26 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return util.Uint160{}, err
}
return u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedContracts: %w", err)
}
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)
if !ok {
return nil, errors.New("not an array")
}
res := make(keys.PublicKeys, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (*keys.PublicKey, error) {
res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes()
if err != nil {
return nil, err
@ -690,19 +690,19 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
return nil, err
}
return k, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field AllowedGroups: %w", err)
}
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)
if !ok {
return nil, errors.New("not an array")
@ -715,7 +715,7 @@ func (res *LedgerTransactionSigner) FromStackItem(item stackitem.Item) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Rules: %w", err)
}
@ -746,7 +746,7 @@ func (res *LedgerWitnessCondition) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.Type, err = arr[index].TryInteger()
@ -786,7 +786,7 @@ func (res *LedgerWitnessRule) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.Action, err = arr[index].TryInteger()
@ -826,7 +826,7 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error {
var (
index = -1
err error
err error
)
index++
res.I, err = arr[index].TryInteger()
@ -884,10 +884,10 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
e.ComplicatedParam, err = func (item stackitem.Item) (string, error) {
e.ComplicatedParam, err = func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -896,7 +896,7 @@ func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field ComplicatedParam: %w", err)
}
@ -945,10 +945,10 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
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 {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]map[string][]util.Uint160, len(arr))
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)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string][]util.Uint160)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -982,18 +982,18 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (m[i].Key)
}(m[i].Key)
if err != nil {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
@ -1003,33 +1003,33 @@ func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error {
return util.Uint160{}, err
}
return u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field M: %w", err)
}
@ -1078,7 +1078,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
e.S, err = itemToUnnamed(arr[index], nil)
@ -1130,17 +1130,17 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([][]*big.Int, len(arr))
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)
if !ok {
return nil, errors.New("not an array")
@ -1153,13 +1153,13 @@ func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error {
}
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field A: %w", err)
}
@ -1208,7 +1208,7 @@ func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error {
var (
index = -1
err error
err error
)
index++
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.
type ContractReader struct {
invoker Invoker
hash util.Uint160
hash util.Uint160
}
// 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.
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 {
return nil, err
}
return func (item stackitem.Item) ([][][]string, error) {
return func(item stackitem.Item) ([][][]string, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([][][]string, len(arr))
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([][]string, len(arr))
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]string, len(arr))
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()
if err != nil {
return "", err
@ -69,45 +69,45 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
}
// Any invokes `any` method of contract.
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 {
return nil, err
}
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.
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 {
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)
if !ok {
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
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
}
// Bool invokes `bool` method of contract.
@ -151,11 +151,11 @@ func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) {
// 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) {
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 {
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)
if !ok {
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 {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]map[string][]util.Uint160, len(arr))
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)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string][]util.Uint160)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
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 string(b), nil
} (m[i].Key)
}(m[i].Key)
if err != nil {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
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 u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
}
// 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.
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 {
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)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string]string)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
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 string(b), nil
} (m[i].Key)
}(m[i].Key)
if err != nil {
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()
if err != nil {
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 string(b), nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
}
// PublicKey invokes `publicKey` method of contract.

View file

@ -21,7 +21,7 @@ type Invoker interface {
// ContractReader implements safe contract methods.
type ContractReader struct {
invoker Invoker
hash util.Uint160
hash util.Uint160
}
// 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.
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 {
return nil, err
}
return func (item stackitem.Item) ([][][]string, error) {
return func(item stackitem.Item) ([][][]string, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([][][]string, len(arr))
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([][]string, len(arr))
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]string, len(arr))
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()
if err != nil {
return "", err
@ -65,45 +65,45 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
}
// Any invokes `any` method of contract.
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 {
return nil, err
}
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.
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 {
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)
if !ok {
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
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
}
// Bool invokes `bool` method of contract.
@ -147,11 +147,11 @@ func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) {
// 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) {
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 {
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)
if !ok {
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 {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]map[string][]util.Uint160, len(arr))
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)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string][]util.Uint160)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
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 string(b), nil
} (m[i].Key)
}(m[i].Key)
if err != nil {
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)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (util.Uint160, error) {
res[i], err = func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
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 u, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (arr[i])
}(arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
}
// 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.
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 {
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)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string]string)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
k, err := func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
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 string(b), nil
} (m[i].Key)
}(m[i].Key)
if err != nil {
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()
if err != nil {
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 string(b), nil
} (m[i].Value)
}(m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
}(item)
}(unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
}
// PublicKey invokes `publicKey` method of contract.

View file

@ -32,7 +32,7 @@ type Actor interface {
// Contract implements all contract methods.
type Contract struct {
actor Actor
hash util.Uint160
hash util.Uint160
}
// 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 (
index = -1
err error
err error
)
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)
if !ok {
return nil, errors.New("not an array")
@ -136,7 +136,7 @@ func (e *HelloWorldEvent) FromStackItem(item *stackitem.Array) error {
}
}
return res, nil
} (arr[index])
}(arr[index])
if err != nil {
return fmt.Errorf("field Args: %w", err)
}

View file

@ -3,6 +3,7 @@ package binding
import (
"bytes"
"fmt"
"go/format"
"go/token"
"io"
"sort"
@ -127,7 +128,32 @@ func Generate(cfg Config) error {
ctr.Imports = append(ctr.Imports, "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal")
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) {

View file

@ -34,7 +34,7 @@ func (c *ContractReader) {{.Name}}({{range $index, $arg := .Arguments -}}
{{- if ne $index 0}}, {{end}}
{{- .Name}} {{.Type}}
{{- end}}) {{if .ReturnType }}({{ .ReturnType }}, error) {
return {{if and (not .ItemTo) (eq .Unwrapper "Item")}}func (item stackitem.Item, err error) ({{ .ReturnType }}, error) {
return {{if and (not .ItemTo) (eq .Unwrapper "Item")}}func(item stackitem.Item, err error) ({{ .ReturnType }}, error) {
if err != nil {
return nil, err
}
@ -258,7 +258,7 @@ func (res *{{toTypeName $name}}) FromStackItem(item stackitem.Item) error {
{{if len .Fields}}
var (
index = -1
err error
err error
)
{{- range $m := $typ.Fields}}
index++
@ -313,7 +313,7 @@ func (e *{{$e.Name}}) FromStackItem(item *stackitem.Array) error {
{{if len $e.Parameters}}var (
index = -1
err error
err error
)
{{- range $p := $e.Parameters}}
index++
@ -464,7 +464,7 @@ func Generate(cfg binding.Config) error {
"upperFirst": upperFirst,
}).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 {
@ -570,7 +570,7 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
case smartcontract.ByteArrayType, smartcontract.SignatureType:
return v + ".TryBytes()"
case smartcontract.StringType:
return `func (item stackitem.Item) (string, error) {
return `func(item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
@ -579,9 +579,9 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (` + v + `)`
}(` + v + `)`
case smartcontract.Hash160Type:
return `func (item stackitem.Item) (util.Uint160, error) {
return `func(item stackitem.Item) (util.Uint160, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint160{}, err
@ -591,9 +591,9 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
return util.Uint160{}, err
}
return u, nil
} (` + v + `)`
}(` + v + `)`
case smartcontract.Hash256Type:
return `func (item stackitem.Item) (util.Uint256, error) {
return `func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint256{}, err
@ -603,9 +603,9 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
return util.Uint256{}, err
}
return u, nil
} (` + v + `)`
}(` + v + `)`
case smartcontract.PublicKeyType:
return `func (item stackitem.Item) (*keys.PublicKey, error) {
return `func(item stackitem.Item) (*keys.PublicKey, error) {
b, err := item.TryBytes()
if err != nil {
return nil, err
@ -615,13 +615,13 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
return nil, err
}
return k, nil
} (` + v + `)`
}(` + v + `)`
case smartcontract.ArrayType:
if len(et.Name) > 0 {
return "itemTo" + toTypeName(et.Name) + "(" + v + ", nil)"
} else if et.Value != nil {
at, _ := extendedTypeToGo(et, nil)
return `func (item stackitem.Item) (` + at + `, error) {
return `func(item stackitem.Item) (` + at + `, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
@ -634,7 +634,7 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
}
}
return res, nil
} (` + v + `)`
}(` + v + `)`
}
return etTypeConverter(binding.ExtendedType{
Base: smartcontract.ArrayType,
@ -646,7 +646,7 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
case smartcontract.MapType:
if et.Value != nil {
at, _ := extendedTypeToGo(et, nil)
return `func (item stackitem.Item) (` + at + `, error) {
return `func(item stackitem.Item) (` + at + `, error) {
m, ok := item.Value().([]stackitem.MapElement)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
@ -664,7 +664,7 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
res[k] = v
}
return res, nil
} (` + v + `)`
}(` + v + `)`
}
return etTypeConverter(binding.ExtendedType{
Base: smartcontract.MapType,

View file

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