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

accounts/abi: add support for fixed bytes with size > 32 #26043

Closed
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions accounts/abi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error) {
// If we have a static tuple, like (uint256, bool, uint256), these are
// coded as just like uint256,bool,uint256
virtualArgs += getTypeSize(arg.Type)/32 - 1
} else if arg.Type.T == FixedBytesTy {
// support for fixed bytes with size longer than 32
virtualArgs += getTypeSize(arg.Type)/32 - 1
}
retval = append(retval, marshalledValue)
}
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) {
if reflectValue.Kind() == reflect.Array {
reflectValue = mustArrayToByteSlice(reflectValue)
}
return common.RightPadBytes(reflectValue.Bytes(), 32), nil
return common.RightPadBytes(reflectValue.Bytes(), (len(reflectValue.Bytes())+31)/32*32), nil
default:
return []byte{}, fmt.Errorf("Could not pack element, unknown type: %v", t.T)
}
Expand Down
2 changes: 2 additions & 0 deletions accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ func getTypeSize(t Type) int {
total += getTypeSize(*elem)
}
return total
} else if t.T == FixedBytesTy {
return (t.Size + 31) / 32 * 32
}
return 32
}
Expand Down