Skip to content

Commit

Permalink
properly evmMarshal evm_log_params
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed Feb 15, 2024
1 parent 30ae67c commit 53b91cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion analyzer/evmabibackfill/evm_abi_backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func marshalArgs(abiArgs abi.Arguments, argVals []interface{}) ([]*abiEncodedArg
args = append(args, &abiEncodedArg{
Name: abiArgs[i].Name,
EvmType: abiArgs[i].Type.String(),
Value: v,
Value: abiparse.EvmPreMarshal(v, abiArgs[i].Type),
})
}

Expand Down
8 changes: 4 additions & 4 deletions analyzer/runtime/abiparse/abiparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)

// evmPreMarshal converts v to a type that gives us the JSON serialization that we like:
// EvmPreMarshal converts v to a type that gives us the JSON serialization that we like:
// - large integers are JSON strings instead of JSON numbers
// - byte array types are JSON strings of base64 instead of JSON arrays of numbers
// Contrived dot for godot linter: .
func evmPreMarshal(v interface{}, t abi.Type) interface{} {
func EvmPreMarshal(v interface{}, t abi.Type) interface{} {
switch t.T {
case abi.IntTy, abi.UintTy:
if t.Size > 32 {
Expand All @@ -23,14 +23,14 @@ func evmPreMarshal(v interface{}, t abi.Type) interface{} {
rv := reflect.ValueOf(v)
slice := make([]interface{}, 0, rv.Len())
for i := 0; i < rv.Len(); i++ {
slice = append(slice, evmPreMarshal(rv.Index(i).Interface(), *t.Elem))
slice = append(slice, EvmPreMarshal(rv.Index(i).Interface(), *t.Elem))
}
return slice
case abi.TupleTy:
rv := reflect.ValueOf(v)
m := map[string]interface{}{}
for i, fieldName := range t.TupleRawNames {
m[fieldName] = evmPreMarshal(rv.Field(i).Interface(), *t.TupleElems[i])
m[fieldName] = EvmPreMarshal(rv.Field(i).Interface(), *t.TupleElems[i])
}
case abi.FixedBytesTy, abi.FunctionTy:
c := reflect.New(t.GetType()).Elem()
Expand Down
2 changes: 1 addition & 1 deletion analyzer/runtime/abiparse/abiparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestParseTypes(t *testing.T) {
"{\"n\":1,\"s\":\"a\"}", // O
}
for i, input := range method.Inputs {
transducedArg := evmPreMarshal(args[i], input.Type)
transducedArg := EvmPreMarshal(args[i], input.Type)
jsonBytesArg, err1 := json.Marshal(transducedArg)
require.NoError(t, err1)
require.Equal(t, jsonExpected[i], string(jsonBytesArg))
Expand Down

0 comments on commit 53b91cb

Please sign in to comment.