rpcbinding: improve error reporting in generated code

This commit is contained in:
Roman Khimov 2022-12-02 16:12:56 +03:00
parent ec5ebc8c18
commit e5aa5ca294
3 changed files with 114 additions and 112 deletions

View file

@ -218,13 +218,13 @@ func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Hash: %w", err)
} }
index++ index++
res.Version, err = arr[index].TryInteger() res.Version, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Version: %w", err)
} }
index++ index++
@ -240,7 +240,7 @@ func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
@ -256,25 +256,25 @@ func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field MerkleRoot: %w", err)
} }
index++ index++
res.Timestamp, err = arr[index].TryInteger() res.Timestamp, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Timestamp: %w", err)
} }
index++ index++
res.Nonce, err = arr[index].TryInteger() res.Nonce, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Nonce: %w", err)
} }
index++ index++
res.Index, err = arr[index].TryInteger() res.Index, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Index: %w", err)
} }
index++ index++
@ -290,13 +290,13 @@ func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field NextConsensus: %w", err)
} }
index++ index++
res.TransactionsLength, err = arr[index].TryInteger() res.TransactionsLength, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field TransactionsLength: %w", err)
} }
@ -331,13 +331,13 @@ func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error)
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Hash: %w", err)
} }
index++ index++
res.Version, err = arr[index].TryInteger() res.Version, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Version: %w", err)
} }
index++ index++
@ -353,7 +353,7 @@ func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error)
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field PrevHash: %w", err)
} }
index++ index++
@ -369,25 +369,25 @@ func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error)
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field MerkleRoot: %w", err)
} }
index++ index++
res.Timestamp, err = arr[index].TryInteger() res.Timestamp, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Timestamp: %w", err)
} }
index++ index++
res.Nonce, err = arr[index].TryInteger() res.Nonce, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Nonce: %w", err)
} }
index++ index++
res.Index, err = arr[index].TryInteger() res.Index, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Index: %w", err)
} }
index++ index++
@ -403,13 +403,13 @@ func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error)
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field NextConsensus: %w", err)
} }
index++ index++
res.TransactionsLength, err = arr[index].TryInteger() res.TransactionsLength, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field TransactionsLength: %w", err)
} }
index++ index++
@ -425,7 +425,7 @@ func itemToLedgerBlockSR(item stackitem.Item, err error) (*LedgerBlockSR, error)
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field PrevStateRoot: %w", err)
} }
@ -460,19 +460,19 @@ func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Hash: %w", err)
} }
index++ index++
res.Version, err = arr[index].TryInteger() res.Version, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Version: %w", err)
} }
index++ index++
res.Nonce, err = arr[index].TryInteger() res.Nonce, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Nonce: %w", err)
} }
index++ index++
@ -488,31 +488,31 @@ func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Sender: %w", err)
} }
index++ index++
res.SysFee, err = arr[index].TryInteger() res.SysFee, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field SysFee: %w", err)
} }
index++ index++
res.NetFee, err = arr[index].TryInteger() res.NetFee, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field NetFee: %w", err)
} }
index++ index++
res.ValidUntilBlock, err = arr[index].TryInteger() res.ValidUntilBlock, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field ValidUntilBlock: %w", err)
} }
index++ index++
res.Script, err = arr[index].TryBytes() res.Script, err = arr[index].TryBytes()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Script: %w", err)
} }
@ -547,13 +547,13 @@ func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTrans
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Account: %w", err)
} }
index++ index++
res.Scopes, err = arr[index].TryInteger() res.Scopes, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Scopes: %w", err)
} }
index++ index++
@ -576,13 +576,13 @@ func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTrans
return u, nil return u, nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field AllowedContracts: %w", err)
} }
index++ index++
@ -605,13 +605,13 @@ func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTrans
return k, nil return k, nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field AllowedGroups: %w", err)
} }
index++ index++
@ -624,13 +624,13 @@ func itemToLedgerTransactionSigner(item stackitem.Item, err error) (*LedgerTrans
for i := range res { for i := range res {
res[i], err = itemToLedgerWitnessRule(arr[i], nil) res[i], err = itemToLedgerWitnessRule(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Rules: %w", err)
} }
@ -655,13 +655,13 @@ func itemToLedgerWitnessCondition(item stackitem.Item, err error) (*LedgerWitnes
index++ index++
res.Type, err = arr[index].TryInteger() res.Type, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Type: %w", err)
} }
index++ index++
res.Value, err = arr[index].Value(), nil res.Value, err = arr[index].Value(), nil
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Value: %w", err)
} }
@ -686,13 +686,13 @@ func itemToLedgerWitnessRule(item stackitem.Item, err error) (*LedgerWitnessRule
index++ index++
res.Action, err = arr[index].TryInteger() res.Action, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Action: %w", err)
} }
index++ index++
res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil) res.Condition, err = itemToLedgerWitnessCondition(arr[index], nil)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Condition: %w", err)
} }
@ -724,13 +724,13 @@ func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error)
for i := range res { for i := range res {
res[i], err = itemToManagementMethod(arr[i], nil) res[i], err = itemToManagementMethod(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Methods: %w", err)
} }
index++ index++
@ -743,13 +743,13 @@ func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error)
for i := range res { for i := range res {
res[i], err = itemToManagementEvent(arr[i], nil) res[i], err = itemToManagementEvent(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Events: %w", err)
} }
@ -774,13 +774,13 @@ func itemToManagementContract(item stackitem.Item, err error) (*ManagementContra
index++ index++
res.ID, err = arr[index].TryInteger() res.ID, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field ID: %w", err)
} }
index++ index++
res.UpdateCounter, err = arr[index].TryInteger() res.UpdateCounter, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field UpdateCounter: %w", err)
} }
index++ index++
@ -796,19 +796,19 @@ func itemToManagementContract(item stackitem.Item, err error) (*ManagementContra
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Hash: %w", err)
} }
index++ index++
res.NEF, err = arr[index].TryBytes() res.NEF, err = arr[index].TryBytes()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field NEF: %w", err)
} }
index++ index++
res.Manifest, err = itemToManagementManifest(arr[index], nil) res.Manifest, err = itemToManagementManifest(arr[index], nil)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Manifest: %w", err)
} }
@ -842,7 +842,7 @@ func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, er
return string(b), nil return string(b), nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Name: %w", err)
} }
index++ index++
@ -855,13 +855,13 @@ func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, er
for i := range res { for i := range res {
res[i], err = itemToManagementParameter(arr[i], nil) res[i], err = itemToManagementParameter(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Params: %w", err)
} }
@ -896,13 +896,13 @@ func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, er
return k, nil return k, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field PublicKey: %w", err)
} }
index++ index++
res.Signature, err = arr[index].TryBytes() res.Signature, err = arr[index].TryBytes()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Signature: %w", err)
} }
@ -936,7 +936,7 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
return string(b), nil return string(b), nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Name: %w", err)
} }
index++ index++
@ -949,13 +949,13 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
for i := range res { for i := range res {
res[i], err = itemToManagementGroup(arr[i], nil) res[i], err = itemToManagementGroup(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Groups: %w", err)
} }
index++ index++
@ -977,7 +977,7 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
return string(b), nil return string(b), nil
} (m[i].Key) } (m[i].Key)
if err != nil { if err != nil {
return nil, 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()
@ -990,14 +990,14 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
return string(b), nil return string(b), nil
} (m[i].Value) } (m[i].Value)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Features: %w", err)
} }
index++ index++
@ -1019,19 +1019,19 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
return string(b), nil return string(b), nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field SupportedStandards: %w", err)
} }
index++ index++
res.ABI, err = itemToManagementABI(arr[index], nil) res.ABI, err = itemToManagementABI(arr[index], nil)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field ABI: %w", err)
} }
index++ index++
@ -1044,13 +1044,13 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
for i := range res { for i := range res {
res[i], err = itemToManagementPermission(arr[i], nil) res[i], err = itemToManagementPermission(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Permissions: %w", err)
} }
index++ index++
@ -1073,19 +1073,19 @@ func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManife
return u, nil return u, nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Trusts: %w", err)
} }
index++ index++
res.Extra, err = arr[index].Value(), nil res.Extra, err = arr[index].Value(), nil
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Extra: %w", err)
} }
@ -1119,7 +1119,7 @@ func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod,
return string(b), nil return string(b), nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Name: %w", err)
} }
index++ index++
@ -1132,31 +1132,31 @@ func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod,
for i := range res { for i := range res {
res[i], err = itemToManagementParameter(arr[i], nil) res[i], err = itemToManagementParameter(arr[i], nil)
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Params: %w", err)
} }
index++ index++
res.ReturnType, err = arr[index].TryInteger() res.ReturnType, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field ReturnType: %w", err)
} }
index++ index++
res.Offset, err = arr[index].TryInteger() res.Offset, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Offset: %w", err)
} }
index++ index++
res.Safe, err = arr[index].TryBool() res.Safe, err = arr[index].TryBool()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Safe: %w", err)
} }
@ -1190,13 +1190,13 @@ func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParam
return string(b), nil return string(b), nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Name: %w", err)
} }
index++ index++
res.Type, err = arr[index].TryInteger() res.Type, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Type: %w", err)
} }
@ -1231,7 +1231,7 @@ func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPerm
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Contract: %w", err)
} }
index++ index++
@ -1253,13 +1253,13 @@ func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPerm
return string(b), nil return string(b), nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field Methods: %w", err)
} }
@ -1284,19 +1284,19 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
index++ index++
res.Bool, err = arr[index].TryBool() res.Bool, err = arr[index].TryBool()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Bool: %w", err)
} }
index++ index++
res.Int, err = arr[index].TryInteger() res.Int, err = arr[index].TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Int: %w", err)
} }
index++ index++
res.Bytes, err = arr[index].TryBytes() res.Bytes, err = arr[index].TryBytes()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Bytes: %w", err)
} }
index++ index++
@ -1311,7 +1311,7 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return string(b), nil return string(b), nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field String: %w", err)
} }
index++ index++
@ -1327,7 +1327,7 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field H160: %w", err)
} }
index++ index++
@ -1343,7 +1343,7 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return u, nil return u, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field H256: %w", err)
} }
index++ index++
@ -1359,7 +1359,7 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return k, nil return k, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field PK: %w", err)
} }
index++ index++
@ -1375,13 +1375,13 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return k, nil return k, nil
} (arr[index]) } (arr[index])
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field PubKey: %w", err)
} }
index++ index++
res.Sign, err = arr[index].TryBytes() res.Sign, err = arr[index].TryBytes()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Sign: %w", err)
} }
index++ index++
@ -1394,13 +1394,13 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
for i := range res { for i := range res {
res[i], err = arr[i].TryBytes() res[i], err = arr[i].TryBytes()
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field ArrOfBytes: %w", err)
} }
index++ index++
@ -1423,13 +1423,13 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return u, nil return u, nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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 nil, err return nil, fmt.Errorf("field ArrOfH160: %w", err)
} }
index++ index++
@ -1442,7 +1442,7 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
for i := range m { for i := range m {
k, err := m[i].Key.TryInteger() k, err := m[i].Key.TryInteger()
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := func (item stackitem.Item) (keys.PublicKeys, error) { v, err := func (item stackitem.Item) (keys.PublicKeys, error) {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
@ -1463,26 +1463,26 @@ func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, er
return k, nil return k, nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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, 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 nil, err return nil, fmt.Errorf("field Map: %w", err)
} }
index++ index++
res.Struct, err = itemToStructsInternal(arr[index], nil) res.Struct, err = itemToStructsInternal(arr[index], nil)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field Struct: %w", err)
} }

View file

@ -70,19 +70,19 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return string(b), nil return string(b), nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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, 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, err return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
@ -125,7 +125,7 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
for i := range m { for i := range m {
k, err := m[i].Key.TryInteger() k, err := m[i].Key.TryInteger()
if err != nil { if err != nil {
return nil, 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)
@ -152,7 +152,7 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
return string(b), nil return string(b), nil
} (m[i].Key) } (m[i].Key)
if err != nil { if err != nil {
return nil, 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)
@ -173,26 +173,26 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
return u, nil return u, nil
} (arr[i]) } (arr[i])
if err != nil { if err != nil {
return nil, 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, 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, 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, err return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
@ -255,7 +255,7 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return string(b), nil return string(b), nil
} (m[i].Key) } (m[i].Key)
if err != nil { if err != nil {
return nil, 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()
@ -268,7 +268,7 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return string(b), nil return string(b), nil
} (m[i].Value) } (m[i].Value)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }

View file

@ -235,7 +235,7 @@ func itemTo{{toTypeName $name}}(item stackitem.Item, err error) (*{{toTypeName $
index++ index++
res.{{.Field}}, err = {{etTypeConverter .ExtendedType "arr[index]"}} res.{{.Field}}, err = {{etTypeConverter .ExtendedType "arr[index]"}}
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("field {{.Field}}: %w", err)
} }
{{end}} {{end}}
{{end}} {{end}}
@ -470,7 +470,7 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
for i := range res { for i := range res {
res[i], err = ` + addIndent(etTypeConverter(*et.Value, "arr[i]"), "\t\t") + ` res[i], err = ` + addIndent(etTypeConverter(*et.Value, "arr[i]"), "\t\t") + `
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("item %d: %w", i, err)
} }
} }
return res, nil return res, nil
@ -494,11 +494,11 @@ func etTypeConverter(et binding.ExtendedType, v string) string {
for i := range m { for i := range m {
k, err := ` + addIndent(etTypeConverter(binding.ExtendedType{Base: et.Key}, "m[i].Key"), "\t\t") + ` k, err := ` + addIndent(etTypeConverter(binding.ExtendedType{Base: et.Key}, "m[i].Key"), "\t\t") + `
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("key %d: %w", i, err)
} }
v, err := ` + addIndent(etTypeConverter(*et.Value, "m[i].Value"), "\t\t") + ` v, err := ` + addIndent(etTypeConverter(*et.Value, "m[i].Value"), "\t\t") + `
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("value %d: %w", i, err)
} }
res[k] = v res[k] = v
} }
@ -533,7 +533,6 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
if ok { if ok {
ctr.SafeMethods[len(ctr.SafeMethods)-1].ExtendedReturn = et ctr.SafeMethods[len(ctr.SafeMethods)-1].ExtendedReturn = et
if abim.ReturnType == smartcontract.ArrayType && len(et.Name) > 0 { if abim.ReturnType == smartcontract.ArrayType && len(et.Name) > 0 {
imports["errors"] = struct{}{}
ctr.SafeMethods[len(ctr.SafeMethods)-1].ItemTo = cutPointer(ctr.Methods[i].ReturnType) ctr.SafeMethods[len(ctr.SafeMethods)-1].ItemTo = cutPointer(ctr.Methods[i].ReturnType)
} }
} }
@ -647,6 +646,9 @@ func addETImports(et binding.ExtendedType, named map[string]binding.ExtendedType
imports["crypto/elliptic"] = struct{}{} imports["crypto/elliptic"] = struct{}{}
case smartcontract.MapType: case smartcontract.MapType:
imports["fmt"] = struct{}{} imports["fmt"] = struct{}{}
case smartcontract.ArrayType:
imports["errors"] = struct{}{}
imports["fmt"] = struct{}{}
} }
if et.Value != nil { if et.Value != nil {
addETImports(*et.Value, named, imports) addETImports(*et.Value, named, imports)