Skip to content

Commit

Permalink
Adds eth_fee_history to client.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Mar 11, 2024
1 parent 4978584 commit b30b265
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/tt_eth/behaviours/chain_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule TTEth.Behaviours.ChainClient do
@type filter_params :: map
@type filter_id :: String.t()
@type tx_obj :: map()
@type error :: {:error, map() | binary() | atom()}

@callback eth_call(contract :: address, encoded_args) :: any
@callback eth_call(contract :: address, encoded_args, opts) :: any
Expand All @@ -26,8 +27,13 @@ defmodule TTEth.Behaviours.ChainClient do
@callback build_tx_data(address, abi_data, wallet, nonce) :: tx_data
@callback build_tx_data(address, abi_data, wallet, nonce, keyword) :: tx_data

@callback eth_get_transaction_count(account :: address, block_id) :: any
@callback eth_get_transaction_count(account :: address, block_id, opts) :: any
@callback eth_get_balance(account :: address, block_id) :: {:ok, binary()} | error
@callback eth_get_balance(account :: address, block_id, opts) :: {:ok, binary()} | error

@callback eth_get_transaction_count(account :: address, block_id) ::
{:ok, binary()} | error
@callback eth_get_transaction_count(account :: address, block_id, opts) ::
{:ok, binary()} | error

@callback eth_get_logs(filter_params) :: {:ok, any} | {:error, any}
@callback eth_get_logs(filter_params, opts) :: {:ok, any} | {:error, any}
Expand All @@ -47,6 +53,20 @@ defmodule TTEth.Behaviours.ChainClient do
@callback eth_estimate_gas(tx_obj) :: any
@callback eth_estimate_gas(tx_obj, opts) :: any

@callback eth_fee_history(
block_count :: integer(),
newest_block :: binary(),
reward_percentiles :: list(binary())
) ::
{:ok, map()} | error
@callback eth_fee_history(
block_count :: integer(),
newest_block :: binary(),
reward_percentiles :: list(binary()),
opts
) ::
{:ok, map()} | error

@callback eth_get_block_by_number(block_id) :: any
@callback eth_get_block_by_number(block_id, boolean) :: any
end
4 changes: 4 additions & 0 deletions lib/tt_eth/chain_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ defmodule TTEth.ChainClient do
def eth_estimate_gas(%{} = tx_obj, opts \\ []),
do: tx_obj |> HttpClient.eth_estimate_gas(opts)

@impl ChainClient
def eth_fee_history(block_count, newest_block, reward_percentiles, opts \\ []),
do: HttpClient.eth_fee_history(block_count, newest_block, reward_percentiles, opts)

@impl ChainClient
def eth_get_block_by_number("" <> block, tx_detail \\ false),
do: block |> HttpClient.eth_get_block_by_number(tx_detail)
Expand Down
35 changes: 35 additions & 0 deletions lib/tt_eth/chain_client_mock_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,41 @@ defmodule TTEth.ChainClientMockImpl do
def eth_estimate_gas(%{} = _tx_obj, _opts \\ []),
do: {:ok, "0x5208"}

@impl ChainClient
def eth_fee_history(_block_count, _newest_block, _reward_percentiles, _opts \\ []),
do:
{:ok,
[
%{
"oldestBlock" => "0x54",
"reward" => [
[
"0x174876e800",
"0x174876e800"
],
[
"0x174876e800",
"0x174876e800"
],
[
"0x174876e800",
"0x174876e800"
]
],
"baseFeePerGas" => [
"0x0",
"0x0",
"0x0",
"0x0"
],
"gasUsedRatio" => [
0.0010253063265735019,
0.006479788956353575,
0.00006763590977418037
]
}
]}

@impl ChainClient
def eth_get_block_by_number(_block, _tx_detail \\ false),
do: {:ok, %{"number" => "0x1", "baseFeePerGas" => "0x10"}}
Expand Down

0 comments on commit b30b265

Please sign in to comment.