Skip to content

Commit

Permalink
fix eth_sendRawTransaction arg json
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Nov 11, 2024
1 parent 7337c4b commit 6c5c28d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rpctypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ type MevSendBundleArgs struct {

type EthSendRawTransactionArgs hexutil.Bytes

func (tx EthSendRawTransactionArgs) MarshalText() ([]byte, error) {
return hexutil.Bytes(tx).MarshalText()
}

func (tx *EthSendRawTransactionArgs) UnmarshalJSON(input []byte) error {
return (*hexutil.Bytes)(tx).UnmarshalJSON(input)
}

func (tx *EthSendRawTransactionArgs) UnmarshalText(input []byte) error {
return (*hexutil.Bytes)(tx).UnmarshalText(input)
}

// eth_cancelBundle

type EthCancelBundleArgs struct {
Expand Down Expand Up @@ -256,9 +268,9 @@ func hashMevSendBundle(level int, b *MevSendBundleArgs) (common.Hash, error) {
return common.BytesToHash(hasher.Sum(nil)), nil
}

func (b *EthSendRawTransactionArgs) UniqueKey() uuid.UUID {
func (tx *EthSendRawTransactionArgs) UniqueKey() uuid.UUID {
hash := newHash()
_, _ = hash.Write(*b)
_, _ = hash.Write(*tx)
return uuidFromHash(hash)
}

Expand Down
17 changes: 17 additions & 0 deletions rpctypes/types_tests.go → rpctypes/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -119,3 +120,19 @@ func TestMevSendBundleArgsValidate(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "0x3b1994ad123d089f978074cfa197811b644e43b2b44b4c4710614f3a30ee0744", hash.Hex())
}

func TestEthsendRawTransactionArgsJSON(t *testing.T) {
data := hexutil.MustDecode("0x1234")

rawTransaction := EthSendRawTransactionArgs(data)

out, err := json.Marshal(rawTransaction)
require.NoError(t, err)

require.Equal(t, `"0x1234"`, string(out))

var roundtripRawTransaction EthSendRawTransactionArgs
err = json.Unmarshal(out, &roundtripRawTransaction)
require.NoError(t, err)
require.Equal(t, rawTransaction, roundtripRawTransaction)
}

0 comments on commit 6c5c28d

Please sign in to comment.