diff --git a/jsonrpc/types.go b/jsonrpc/types.go index 2e2a5e3f57..eb4f710845 100644 --- a/jsonrpc/types.go +++ b/jsonrpc/types.go @@ -18,7 +18,7 @@ type transactionOrHash interface { type transaction struct { Nonce argUint64 `json:"nonce"` - GasPrice argBig `json:"gasPrice"` + GasPrice *argBig `json:"gasPrice,omitempty"` GasTipCap *argBig `json:"gasTipCap,omitempty"` GasFeeCap *argBig `json:"gasFeeCap,omitempty"` Gas argUint64 `json:"gas"` @@ -58,18 +58,22 @@ func toTransaction( txIndex *int, ) *transaction { res := &transaction{ - Nonce: argUint64(t.Nonce), - GasPrice: argBig(*t.GasPrice), - Gas: argUint64(t.Gas), - To: t.To, - Value: argBig(*t.Value), - Input: t.Input, - V: argBig(*t.V), - R: argBig(*t.R), - S: argBig(*t.S), - Hash: t.Hash, - From: t.From, - Type: argUint64(t.Type), + Nonce: argUint64(t.Nonce), + Gas: argUint64(t.Gas), + To: t.To, + Value: argBig(*t.Value), + Input: t.Input, + V: argBig(*t.V), + R: argBig(*t.R), + S: argBig(*t.S), + Hash: t.Hash, + From: t.From, + Type: argUint64(t.Type), + } + + if t.GasPrice != nil { + gasPrice := argBig(*t.GasPrice) + res.GasPrice = &gasPrice } if t.GasTipCap != nil { diff --git a/jsonrpc/types_test.go b/jsonrpc/types_test.go index 3f2ef341ee..aac6899692 100644 --- a/jsonrpc/types_test.go +++ b/jsonrpc/types_test.go @@ -128,6 +128,39 @@ func TestToTransaction_Returns_V_R_S_ValuesWithoutLeading0(t *testing.T) { assert.Equal(t, hexWithoutLeading0, string(jsonS)) } +func TestToTransaction_EIP1559(t *testing.T) { + hexWithLeading0 := "0x0ba93811466694b3b3cb8853cb8227b7c9f49db10bf6e7db59d20ac904961565" + hexWithoutLeading0 := "0xba93811466694b3b3cb8853cb8227b7c9f49db10bf6e7db59d20ac904961565" + v, _ := hex.DecodeHex(hexWithLeading0) + r, _ := hex.DecodeHex(hexWithLeading0) + s, _ := hex.DecodeHex(hexWithLeading0) + txn := types.Transaction{ + Nonce: 0, + GasPrice: nil, + GasTipCap: big.NewInt(10), + GasFeeCap: big.NewInt(10), + Gas: 0, + To: nil, + Value: big.NewInt(0), + Input: nil, + V: new(big.Int).SetBytes(v), + R: new(big.Int).SetBytes(r), + S: new(big.Int).SetBytes(s), + Hash: types.Hash{}, + From: types.Address{}, + } + + jsonTx := toTransaction(&txn, nil, nil, nil) + + jsonV, _ := jsonTx.V.MarshalText() + jsonR, _ := jsonTx.R.MarshalText() + jsonS, _ := jsonTx.S.MarshalText() + + assert.Equal(t, hexWithoutLeading0, string(jsonV)) + assert.Equal(t, hexWithoutLeading0, string(jsonR)) + assert.Equal(t, hexWithoutLeading0, string(jsonS)) +} + func TestBlock_Copy(t *testing.T) { b := &block{ ExtraData: []byte{0x1}, @@ -206,7 +239,7 @@ func mockTxn() *transaction { tt := &transaction{ Nonce: 1, - GasPrice: argBig(*big.NewInt(10)), + GasPrice: argBigPtr(big.NewInt(10)), Gas: 100, To: &to, Value: argBig(*big.NewInt(1000)),