From 6c5c28db697b24f83cf9d6a2d06be853357c6e34 Mon Sep 17 00:00:00 2001 From: Vitaly Drogan Date: Mon, 11 Nov 2024 17:33:59 +0100 Subject: [PATCH] fix eth_sendRawTransaction arg json --- rpctypes/types.go | 16 ++++++++++++++-- rpctypes/{types_tests.go => types_test.go} | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) rename rpctypes/{types_tests.go => types_test.go} (94%) diff --git a/rpctypes/types.go b/rpctypes/types.go index 008be8d..3c99732 100644 --- a/rpctypes/types.go +++ b/rpctypes/types.go @@ -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 { @@ -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) } diff --git a/rpctypes/types_tests.go b/rpctypes/types_test.go similarity index 94% rename from rpctypes/types_tests.go rename to rpctypes/types_test.go index 5960d2e..4cbb36f 100644 --- a/rpctypes/types_tests.go +++ b/rpctypes/types_test.go @@ -5,6 +5,7 @@ import ( "fmt" "testing" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/stretchr/testify/require" ) @@ -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) +}