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

Add EIP1559 support for eth_maxPriorityFeePerGas and eth_feeHistory #127

Merged
merged 4 commits into from
May 10, 2022
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
11 changes: 11 additions & 0 deletions lib/ethereumex/client/base_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ defmodule Ethereumex.Client.BaseClient do
request("eth_gasPrice", [], opts)
end

@impl true
def eth_max_priority_fee_per_gas(opts \\ []) do
request("eth_maxPriorityFeePerGas", [], opts)
end

@impl true
def eth_fee_history(block_count, newestblock, reward_percentiles, opts \\ []) do
params = [block_count, newestblock, reward_percentiles]
request("eth_feeHistory", params, opts)
end

@impl true
def eth_accounts(opts \\ []) do
request("eth_accounts", [], opts)
Expand Down
2 changes: 2 additions & 0 deletions lib/ethereumex/client/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ defmodule Ethereumex.Client.Behaviour do
@callback eth_mining(keyword()) :: {:ok, boolean()} | error
@callback eth_hashrate(keyword()) :: {:ok, binary()} | error
@callback eth_gas_price(keyword()) :: {:ok, binary()} | error
@callback eth_max_priority_fee_per_gas(keyword()) :: {:ok, binary()} | error
@callback eth_fee_history(binary(), binary(), list(binary()), keyword()) :: {:ok, map()} | error
@callback eth_accounts(keyword()) :: {:ok, [binary()]} | error
@callback eth_block_number(keyword()) :: {:ok, binary} | error
@callback eth_get_balance(binary(), binary(), keyword()) :: {:ok, binary()} | error
Expand Down
2 changes: 2 additions & 0 deletions test/ethereumex/client/base_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ defmodule Ethereumex.Client.BaseClientTest do
test ".eth_mining/0", do: Helpers.check("eth_mining")
test ".eth_hashrate/0", do: Helpers.check("eth_hashrate")
test ".eth_gas_price/0", do: Helpers.check("eth_gas_price")
test ".eth_max_priority_fee_per_gas/0", do: Helpers.check("eth_max_priority_fee_per_gas")
test ".eth_fee_history/3", do: Helpers.check("eth_fee_history", [1, "latest", [25, 75]])
test ".eth_accounts/0", do: Helpers.check("eth_accounts")
test ".eth_block_number/0", do: Helpers.check("eth_block_number")
test ".eth_get_compilers/0", do: Helpers.check("eth_get_compilers")
Expand Down
18 changes: 18 additions & 0 deletions test/ethereumex/http_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ defmodule Ethereumex.HttpClientTest do
end
end

@tag :eth
describe "HttpClient.eth_max_priority_fee_per_gas/1" do
test "returns current max priority fee per gas" do
result = HttpClient.eth_max_priority_fee_per_gas()

{:ok, <<_::binary>>} = result
end
end

@tag :eth
describe "HttpClient.eth_fee_history/3" do
test "returns a collection of historical gas information" do
result = HttpClient.eth_fee_history(1, "latest", [25, 75])

assert is_map(result)
end
end

@tag :eth
describe "HttpClient.eth_accounts/1" do
test "returns addresses owned by client" do
Expand Down
18 changes: 18 additions & 0 deletions test/ethereumex/ipc_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ defmodule Ethereumex.IpcClientTest do
end
end

@tag :eth
describe "IpcClient.eth_max_priority_fee_per_gas/1" do
test "returns current max priority fee per gas" do
result = IpcClient.eth_max_priority_fee_per_gas()

{:ok, <<_::binary>>} = result
end
end

@tag :eth
describe "IpcClient.eth_fee_history/3" do
test "returns a collection of historical gas information" do
result = IpcClient.eth_fee_history(1, "latest", [25, 75])

assert is_map(result)
end
end

@tag :eth
describe "IpcClient.eth_accounts/1" do
test "returns addresses owned by client" do
Expand Down