Skip to content

Commit

Permalink
use default max_priority_fee (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
wchenNL authored Apr 2, 2024
1 parent 1b03cd7 commit 62c5bf3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/ethers/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Ethers.Transaction do
gas_price: nil,
hash: nil,
max_fee_per_gas: nil,
max_priority_fee_per_gas: "0x0",
max_priority_fee_per_gas: nil,
nonce: nil,
signature_r: nil,
signature_s: nil,
Expand Down Expand Up @@ -58,7 +58,7 @@ defmodule Ethers.Transaction do
@common_fillable_params [:chain_id, :nonce]
@type_fillable_params %{
legacy: [:gas_price],
eip1559: [:max_fee_per_gas]
eip1559: [:max_fee_per_gas, :max_priority_fee_per_gas]
}
@integer_type_values [
:block_number,
Expand Down Expand Up @@ -231,6 +231,7 @@ defmodule Ethers.Transaction do
defp fill_action(:chain_id, _tx), do: :chain_id
defp fill_action(:nonce, tx), do: {:get_transaction_count, [tx.from, "latest"]}
defp fill_action(:max_fee_per_gas, _tx), do: :gas_price
defp fill_action(:max_priority_fee_per_gas, _tx), do: :max_priority_fee_per_gas
defp fill_action(:gas_price, _tx), do: :gas_price

defp post_process([], [], acc), do: {:ok, Enum.into(acc, %{})}
Expand All @@ -251,6 +252,11 @@ defmodule Ethers.Transaction do
end
end

defp do_post_process(:max_priority_fee_per_gas, {:ok, v_int}) do
# use latest max_priority_fee_per_gas from the chain as default
{:ok, {:max_priority_fee_per_gas, Utils.integer_to_hex(v_int)}}
end

defp do_post_process(key, {:ok, v_hex}) do
{:ok, {key, v_hex}}
end
Expand Down
20 changes: 19 additions & 1 deletion test/ethers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,25 @@ defmodule EthersTest do
)

assert signed ==
"0x02f8cd8205396480840756b5b38227109495ced938f7991cd0dfcb48f0a06a40fa1af46ebc80b864435ffe94000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096869207369676e65640000000000000000000000000000000000000000000000c001a002692d6fb9c645a9c16759ad577511d132c6976eacfaeca52f564771e4b80ddea075bcae22afa255d44387ef43fc6b005cc86529c6e99364e065736804f16c1bfc"
"0x02f8d182053964843b9aca00840756b5b38227109495ced938f7991cd0dfcb48f0a06a40fa1af46ebc80b864435ffe94000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096869207369676e65640000000000000000000000000000000000000000000000c001a0da576ea4a1cf5979a34056d2fde083f6567430b2286e4985ffb9ea83df69c57fa070790ded792b1e55abd3fcc13202133289dfaba0fc96b476a76f488d69b2477d"
end

test "returns signed transaction with custom max_priority_fee_per_gas" do
signed =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction!(
from: @from,
gas: 10_000,
max_fee_per_gas: 123_123_123,
max_priority_fee_per_gas: 2_000_000_000,
chain_id: 1337,
nonce: 100,
to: "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC",
signer: Ethers.Signer.JsonRPC
)

assert signed ==
"0x02f8d1820539648477359400840756b5b38227109495ced938f7991cd0dfcb48f0a06a40fa1af46ebc80b864435ffe94000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096869207369676e65640000000000000000000000000000000000000000000000c001a054c7dd5c03757b3fa7c896bfb23f6bf3cf32aa21e3e53dbca00d447a673c033aa01e81b956fe27a1757f780a12570df243fc10c3a08b8647b301b1be15b376734e"
end

test "raises in case of error" do
Expand Down

0 comments on commit 62c5bf3

Please sign in to comment.