rpcbinding: fix formatting of binding template

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-10-18 18:09:58 +03:00
parent c42486587d
commit 6a706d5c5a

View file

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