aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMats Julian Olsen <mats@plysjbyen.net>2019-03-28 21:32:09 +0800
committerGuillaume Ballet <gballet@gmail.com>2019-03-28 21:32:09 +0800
commit5b0d3fa39359c027882705c221b6ddb5cd73f3d9 (patch)
tree2dad20b04a5ed21c97d3fe22d71937c55580069d
parent67fc0377e13416d9a1f8ea32e7d1b0ca89374bf3 (diff)
downloadgo-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.tar
go-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.tar.gz
go-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.tar.bz2
go-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.tar.lz
go-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.tar.xz
go-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.tar.zst
go-tangerine-5b0d3fa39359c027882705c221b6ddb5cd73f3d9.zip
accounts/abi: Add the original name as json-structtag for tuples.
-rw-r--r--accounts/abi/type.go1
-rw-r--r--accounts/abi/type_test.go8
2 files changed, 8 insertions, 1 deletions
diff --git a/accounts/abi/type.go b/accounts/abi/type.go
index 26151dbd3..1a3718235 100644
--- a/accounts/abi/type.go
+++ b/accounts/abi/type.go
@@ -188,6 +188,7 @@ func NewType(t string, components []ArgumentMarshaling) (typ Type, err error) {
fields = append(fields, reflect.StructField{
Name: ToCamelCase(c.Name), // reflect.StructOf will panic for any exported field.
Type: cType.Type,
+ Tag: reflect.StructTag("json:\"" + c.Name + "\""),
})
elems = append(elems, &cType)
names = append(names, c.Name)
diff --git a/accounts/abi/type_test.go b/accounts/abi/type_test.go
index 7ef47330d..5023456ae 100644
--- a/accounts/abi/type_test.go
+++ b/accounts/abi/type_test.go
@@ -95,8 +95,14 @@ func TestTypeRegexp(t *testing.T) {
// {"fixed[2]", nil, Type{}},
// {"fixed128x128[]", nil, Type{}},
// {"fixed128x128[2]", nil, Type{}},
- {"tuple", []ArgumentMarshaling{{Name: "a", Type: "int64"}}, Type{Kind: reflect.Struct, T: TupleTy, Type: reflect.TypeOf(struct{ A int64 }{}), stringKind: "(int64)",
+ {"tuple", []ArgumentMarshaling{{Name: "a", Type: "int64"}}, Type{Kind: reflect.Struct, T: TupleTy, Type: reflect.TypeOf(struct {
+ A int64 `json:"a"`
+ }{}), stringKind: "(int64)",
TupleElems: []*Type{{Kind: reflect.Int64, T: IntTy, Type: reflect.TypeOf(int64(0)), Size: 64, stringKind: "int64"}}, TupleRawNames: []string{"a"}}},
+ {"tuple with long name", []ArgumentMarshaling{{Name: "aTypicalParamName", Type: "int64"}}, Type{Kind: reflect.Struct, T: TupleTy, Type: reflect.TypeOf(struct {
+ ATypicalParamName int64 `json:"aTypicalParamName"`
+ }{}), stringKind: "(int64)",
+ TupleElems: []*Type{{Kind: reflect.Int64, T: IntTy, Type: reflect.TypeOf(int64(0)), Size: 64, stringKind: "int64"}}, TupleRawNames: []string{"aTypicalParamName"}}},
}
for _, tt := range tests {