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

fix eth_sendRawTransaction arg json #31

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
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)
}
Loading