mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
Merge 1df93d5c6c into f0e8a3e9c8
This commit is contained in:
commit
461828c04a
2 changed files with 42 additions and 1 deletions
|
|
@ -498,8 +498,15 @@ func (typedData *TypedData) encodeArrayValue(encValue interface{}, encType strin
|
||||||
|
|
||||||
arrayBuffer := new(bytes.Buffer)
|
arrayBuffer := new(bytes.Buffer)
|
||||||
parsedType := strings.Split(encType, "[")[0]
|
parsedType := strings.Split(encType, "[")[0]
|
||||||
|
|
||||||
for _, item := range arrayValue {
|
for _, item := range arrayValue {
|
||||||
if reflect.TypeOf(item).Kind() == reflect.Slice ||
|
if parsedType == "bytes" {
|
||||||
|
bytesValue, err := typedData.EncodePrimitiveValue(parsedType, item, depth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
arrayBuffer.Write(bytesValue)
|
||||||
|
} else if reflect.TypeOf(item).Kind() == reflect.Slice ||
|
||||||
reflect.TypeOf(item).Kind() == reflect.Array {
|
reflect.TypeOf(item).Kind() == reflect.Array {
|
||||||
encodedData, err := typedData.encodeArrayValue(item, parsedType, depth+1)
|
encodedData, err := typedData.encodeArrayValue(item, parsedType, depth+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
|
|
@ -233,3 +234,36 @@ func TestType_TypeName(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEncodeNestedBytesArray(t *testing.T) {
|
||||||
|
typedData := TypedData{
|
||||||
|
Types: Types{
|
||||||
|
"EIP712Domain": []Type{
|
||||||
|
{Name: "name", Type: "string"},
|
||||||
|
{Name: "version", Type: "string"},
|
||||||
|
},
|
||||||
|
"Test": []Type{
|
||||||
|
{Name: "data", Type: "bytes[]"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PrimaryType: "Test",
|
||||||
|
Domain: TypedDataDomain{
|
||||||
|
Name: "TestDomain",
|
||||||
|
Version: "1",
|
||||||
|
},
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"data": []interface{}{
|
||||||
|
hexutil.MustDecode("0x1234"),
|
||||||
|
hexutil.MustDecode("0x5678"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
hash, _, err := TypedDataAndHash(typedData)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to hash struct with nested bytes array: %v", err)
|
||||||
|
}
|
||||||
|
if hash == nil {
|
||||||
|
t.Error("Hash is nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue