Skip to content

Commit

Permalink
Prevent marshaling gas price in case of dynamic fee transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Aug 7, 2023
1 parent ec7ffb3 commit b504bcd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
20 changes: 11 additions & 9 deletions structs_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ func (t *Transaction) marshalJSON(a *fastjson.Arena) *fastjson.Value {
if t.Value != nil {
o.Set("value", a.NewString(fmt.Sprintf("0x%x", t.Value)))
}
o.Set("gasPrice", a.NewString(fmt.Sprintf("0x%x", t.GasPrice)))

if t.Type == TransactionDynamicFee {
if t.MaxPriorityFeePerGas != nil {
o.Set("maxPriorityFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxPriorityFeePerGas)))
}
if t.MaxFeePerGas != nil {
o.Set("maxFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxFeePerGas)))
}
} else {
o.Set("gasPrice", a.NewString(fmt.Sprintf("0x%x", t.GasPrice)))
}
// gas limit fields
if t.Gas != 0 {
o.Set("gas", a.NewString(fmt.Sprintf("0x%x", t.Gas)))
}
if t.MaxPriorityFeePerGas != nil {
o.Set("maxPriorityFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxPriorityFeePerGas)))
}
if t.MaxFeePerGas != nil {
o.Set("maxFeePerGas", a.NewString(fmt.Sprintf("0x%x", t.MaxFeePerGas)))
}

if t.Nonce != 0 {
// we can remove this once we include support for custom nonces
Expand Down Expand Up @@ -298,4 +300,4 @@ func (s StateOverride) MarshalJSON() ([]byte, error) {
defaultArena.Put(a)

return res, nil
}
}
6 changes: 4 additions & 2 deletions structs_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ func (t *Transaction) unmarshalJSON(v *fastjson.Value) error {
if err = decodeAddr(&t.From, v, "from"); err != nil {
return err
}
if t.GasPrice, err = decodeUint(v, "gasPrice"); err != nil {
return err
if typ == TransactionLegacy {
if t.GasPrice, err = decodeUint(v, "gasPrice"); err != nil {
return err
}
}
if t.Input, err = decodeBytes(t.Input[:0], v, "input"); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions testsuite/transaction-eip1159.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"from": "0x0000000000000000000000000000000000000001",
"input": "0x00",
"value": "0x0",
"gasPrice": "0x0",
"gas": "0x10",
"maxPriorityFeePerGas": "0x10",
"maxFeePerGas": "0x10",
"gas": "0x10",
"nonce": "0x10",
"to": null,
"v":"0x25",
Expand Down

0 comments on commit b504bcd

Please sign in to comment.