Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: errors with EIP712 signature #70

Merged
merged 2 commits into from
Dec 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions x/auth/tx/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,23 @@ func traverseFields(
fieldType := t.Field(i).Type
fieldName := jsonNameFromTag(t.Field(i).Tag)

// TODO will add another limitation: only if the type is anyOf.
if fieldName == "" {
fieldName = t.Field(i).Name
anyWrapper := &cosmosAnyWrapper{
Type: fmt.Sprint(reflect.TypeOf(field.Interface())),
Value: field.Interface(),
// For protobuf one_of interface, there's no json tag.
// So we need to wrap it first.
if isProtobufOneOf(t.Field(i).Tag) {
fieldName = t.Field(i).Name
anyWrapper := &cosmosAnyWrapper{
Type: fmt.Sprint(reflect.TypeOf(field.Interface())),
Value: field.Interface(),
}
field = reflect.ValueOf(anyWrapper)
fieldType = reflect.TypeOf(anyWrapper)
} else {
panic("empty json tag")
}
field = reflect.ValueOf(anyWrapper)
fieldType = reflect.TypeOf(anyWrapper)
}

// Unpack any type into the wrapper to keep align between the structs' json tag and field name
if fieldType == cosmosAnyType {
typeAny, ok := field.Interface().(*codectypes.Any)
if !ok {
Expand All @@ -350,11 +356,9 @@ func traverseFields(

fieldType = reflect.TypeOf(anyWrapper)
field = reflect.ValueOf(anyWrapper)

// then continue as normal
}

// If it's a nil pointer, do not include in types
// If it's a nil pointer or empty string, do not include in types
if fieldType.Kind() == reflect.Ptr && field.IsNil() {
continue
}
Expand Down Expand Up @@ -395,7 +399,8 @@ func traverseFields(

fieldType = fieldType.Elem()
field = field.Index(0)
// Unpack the field into cosmosAnyWrapper rather than the Any type

// Unpack any type into the wrapper to keep align between the structs' json tag and field name
if fieldType == cosmosAnyType {
typeAny, ok := field.Interface().(*codectypes.Any)
if !ok {
Expand All @@ -412,9 +417,8 @@ func traverseFields(

fieldType = reflect.TypeOf(anyWrapper.Value)
field = reflect.ValueOf(anyWrapper.Value)

// then continue as normal
}

isCollection = true
}

Expand Down Expand Up @@ -506,6 +510,10 @@ func jsonNameFromTag(tag reflect.StructTag) string {
return parts[0]
}

func isProtobufOneOf(tag reflect.StructTag) bool {
return tag.Get("protobuf_oneof") != ""
}

// _.foo_bar.baz -> TypeFooBarBaz
//
// this is needed for Geth's own signing code which doesn't
Expand Down