rpcbinding: handle NULL results for structures, fix #3581

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2024-09-11 18:53:26 +03:00
parent 6bbf15f305
commit 4e3f17d06f
7 changed files with 155 additions and 0 deletions

View file

@ -186,10 +186,15 @@ func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) {
} }
// itemToCrazyStruct converts stack item into *CrazyStruct. // itemToCrazyStruct converts stack item into *CrazyStruct.
// NULL item is returned as nil pointer without error.
func itemToCrazyStruct(item stackitem.Item, err error) (*CrazyStruct, error) { func itemToCrazyStruct(item stackitem.Item, err error) (*CrazyStruct, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(CrazyStruct) var res = new(CrazyStruct)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -226,10 +231,15 @@ func (res *CrazyStruct) FromStackItem(item stackitem.Item) error {
} }
// itemToSimpleStruct converts stack item into *SimpleStruct. // itemToSimpleStruct converts stack item into *SimpleStruct.
// NULL item is returned as nil pointer without error.
func itemToSimpleStruct(item stackitem.Item, err error) (*SimpleStruct, error) { func itemToSimpleStruct(item stackitem.Item, err error) (*SimpleStruct, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(SimpleStruct) var res = new(SimpleStruct)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err

View file

@ -186,10 +186,15 @@ func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) {
} }
// itemToUnnamed converts stack item into *Unnamed. // itemToUnnamed converts stack item into *Unnamed.
// NULL item is returned as nil pointer without error.
func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(Unnamed) var res = new(Unnamed)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -226,10 +231,15 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error {
} }
// itemToUnnamedX converts stack item into *UnnamedX. // itemToUnnamedX converts stack item into *UnnamedX.
// NULL item is returned as nil pointer without error.
func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(UnnamedX) var res = new(UnnamedX)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err

View file

@ -161,10 +161,15 @@ func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction,
} }
// itemToLedgerBlock converts stack item into *LedgerBlock. // itemToLedgerBlock converts stack item into *LedgerBlock.
// NULL item is returned as nil pointer without error.
func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) { func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(LedgerBlock) var res = new(LedgerBlock)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -289,10 +294,15 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
// itemToLedgerTransaction converts stack item into *LedgerTransaction. // itemToLedgerTransaction converts stack item into *LedgerTransaction.
// NULL item is returned as nil pointer without error.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) { func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(LedgerTransaction) var res = new(LedgerTransaction)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -385,10 +395,15 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementABI converts stack item into *ManagementABI. // itemToManagementABI converts stack item into *ManagementABI.
// NULL item is returned as nil pointer without error.
func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) { func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementABI) var res = new(ManagementABI)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -451,10 +466,15 @@ func (res *ManagementABI) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementContract converts stack item into *ManagementContract. // itemToManagementContract converts stack item into *ManagementContract.
// NULL item is returned as nil pointer without error.
func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) { func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementContract) var res = new(ManagementContract)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -519,10 +539,15 @@ func (res *ManagementContract) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementEvent converts stack item into *ManagementEvent. // itemToManagementEvent converts stack item into *ManagementEvent.
// NULL item is returned as nil pointer without error.
func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) { func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementEvent) var res = new(ManagementEvent)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -581,10 +606,15 @@ func (res *ManagementEvent) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementGroup converts stack item into *ManagementGroup. // itemToManagementGroup converts stack item into *ManagementGroup.
// NULL item is returned as nil pointer without error.
func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) { func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementGroup) var res = new(ManagementGroup)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -631,10 +661,15 @@ func (res *ManagementGroup) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementManifest converts stack item into *ManagementManifest. // itemToManagementManifest converts stack item into *ManagementManifest.
// NULL item is returned as nil pointer without error.
func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) { func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementManifest) var res = new(ManagementManifest)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -823,10 +858,15 @@ func (res *ManagementManifest) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementMethod converts stack item into *ManagementMethod. // itemToManagementMethod converts stack item into *ManagementMethod.
// NULL item is returned as nil pointer without error.
func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) { func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementMethod) var res = new(ManagementMethod)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -903,10 +943,15 @@ func (res *ManagementMethod) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementParameter converts stack item into *ManagementParameter. // itemToManagementParameter converts stack item into *ManagementParameter.
// NULL item is returned as nil pointer without error.
func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) { func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementParameter) var res = new(ManagementParameter)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -952,10 +997,15 @@ func (res *ManagementParameter) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementPermission converts stack item into *ManagementPermission. // itemToManagementPermission converts stack item into *ManagementPermission.
// NULL item is returned as nil pointer without error.
func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) { func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementPermission) var res = new(ManagementPermission)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -1024,10 +1074,15 @@ func (res *ManagementPermission) FromStackItem(item stackitem.Item) error {
} }
// itemToStructsInternal converts stack item into *StructsInternal. // itemToStructsInternal converts stack item into *StructsInternal.
// NULL item is returned as nil pointer without error.
func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) { func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(StructsInternal) var res = new(StructsInternal)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err

View file

@ -157,10 +157,15 @@ func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction,
} }
// itemToLedgerBlock converts stack item into *LedgerBlock. // itemToLedgerBlock converts stack item into *LedgerBlock.
// NULL item is returned as nil pointer without error.
func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) { func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(LedgerBlock) var res = new(LedgerBlock)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -285,10 +290,15 @@ func (res *LedgerBlock) FromStackItem(item stackitem.Item) error {
} }
// itemToLedgerTransaction converts stack item into *LedgerTransaction. // itemToLedgerTransaction converts stack item into *LedgerTransaction.
// NULL item is returned as nil pointer without error.
func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) { func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(LedgerTransaction) var res = new(LedgerTransaction)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -381,10 +391,15 @@ func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementABI converts stack item into *ManagementABI. // itemToManagementABI converts stack item into *ManagementABI.
// NULL item is returned as nil pointer without error.
func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) { func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementABI) var res = new(ManagementABI)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -447,10 +462,15 @@ func (res *ManagementABI) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementContract converts stack item into *ManagementContract. // itemToManagementContract converts stack item into *ManagementContract.
// NULL item is returned as nil pointer without error.
func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) { func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementContract) var res = new(ManagementContract)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -515,10 +535,15 @@ func (res *ManagementContract) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementEvent converts stack item into *ManagementEvent. // itemToManagementEvent converts stack item into *ManagementEvent.
// NULL item is returned as nil pointer without error.
func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) { func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementEvent) var res = new(ManagementEvent)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -577,10 +602,15 @@ func (res *ManagementEvent) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementGroup converts stack item into *ManagementGroup. // itemToManagementGroup converts stack item into *ManagementGroup.
// NULL item is returned as nil pointer without error.
func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) { func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementGroup) var res = new(ManagementGroup)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -627,10 +657,15 @@ func (res *ManagementGroup) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementManifest converts stack item into *ManagementManifest. // itemToManagementManifest converts stack item into *ManagementManifest.
// NULL item is returned as nil pointer without error.
func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) { func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementManifest) var res = new(ManagementManifest)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -819,10 +854,15 @@ func (res *ManagementManifest) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementMethod converts stack item into *ManagementMethod. // itemToManagementMethod converts stack item into *ManagementMethod.
// NULL item is returned as nil pointer without error.
func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) { func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementMethod) var res = new(ManagementMethod)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -899,10 +939,15 @@ func (res *ManagementMethod) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementParameter converts stack item into *ManagementParameter. // itemToManagementParameter converts stack item into *ManagementParameter.
// NULL item is returned as nil pointer without error.
func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) { func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementParameter) var res = new(ManagementParameter)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -948,10 +993,15 @@ func (res *ManagementParameter) FromStackItem(item stackitem.Item) error {
} }
// itemToManagementPermission converts stack item into *ManagementPermission. // itemToManagementPermission converts stack item into *ManagementPermission.
// NULL item is returned as nil pointer without error.
func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) { func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(ManagementPermission) var res = new(ManagementPermission)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -1020,10 +1070,15 @@ func (res *ManagementPermission) FromStackItem(item stackitem.Item) error {
} }
// itemToStructsInternal converts stack item into *StructsInternal. // itemToStructsInternal converts stack item into *StructsInternal.
// NULL item is returned as nil pointer without error.
func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) { func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(StructsInternal) var res = new(StructsInternal)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err

View file

@ -370,10 +370,15 @@ func (c *ContractReader) UnnamedStructsX() (*UnnamedX, error) {
} }
// itemToUnnamed converts stack item into *Unnamed. // itemToUnnamed converts stack item into *Unnamed.
// NULL item is returned as nil pointer without error.
func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(Unnamed) var res = new(Unnamed)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -404,10 +409,15 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error {
} }
// itemToUnnamedX converts stack item into *UnnamedX. // itemToUnnamedX converts stack item into *UnnamedX.
// NULL item is returned as nil pointer without error.
func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(UnnamedX) var res = new(UnnamedX)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err

View file

@ -366,10 +366,15 @@ func (c *ContractReader) UnnamedStructsX() (*UnnamedX, error) {
} }
// itemToUnnamed converts stack item into *Unnamed. // itemToUnnamed converts stack item into *Unnamed.
// NULL item is returned as nil pointer without error.
func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(Unnamed) var res = new(Unnamed)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err
@ -400,10 +405,15 @@ func (res *Unnamed) FromStackItem(item stackitem.Item) error {
} }
// itemToUnnamedX converts stack item into *UnnamedX. // itemToUnnamedX converts stack item into *UnnamedX.
// NULL item is returned as nil pointer without error.
func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new(UnnamedX) var res = new(UnnamedX)
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err

View file

@ -239,10 +239,15 @@ func New(actor Actor{{- if not (len .Hash) -}}, hash util.Uint160{{- end -}}) *C
{{- range $m := .Methods -}}{{template "METHOD" $m }}{{ end -}} {{- range $m := .Methods -}}{{template "METHOD" $m }}{{ end -}}
{{- range $index, $typ := .NamedTypes }} {{- range $index, $typ := .NamedTypes }}
// itemTo{{toTypeName $typ.Name}} converts stack item into *{{toTypeName $typ.Name}}. // itemTo{{toTypeName $typ.Name}} converts stack item into *{{toTypeName $typ.Name}}.
// NULL item is returned as nil pointer without error.
func itemTo{{toTypeName $typ.Name}}(item stackitem.Item, err error) (*{{toTypeName $typ.Name}}, error) { func itemTo{{toTypeName $typ.Name}}(item stackitem.Item, err error) (*{{toTypeName $typ.Name}}, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, null := item.(stackitem.Null)
if null {
return nil, nil
}
var res = new({{toTypeName $typ.Name}}) var res = new({{toTypeName $typ.Name}})
err = res.FromStackItem(item) err = res.FromStackItem(item)
return res, err return res, err