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

Jp/hotfix optional gas price in rpc transaction type #1699

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
30 changes: 17 additions & 13 deletions jsonrpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 34 additions & 1 deletion jsonrpc/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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)),
Expand Down