diff --git a/lib/tt_eth/behaviours/chain_client.ex b/lib/tt_eth/behaviours/chain_client.ex index 939f452..7e27f04 100644 --- a/lib/tt_eth/behaviours/chain_client.ex +++ b/lib/tt_eth/behaviours/chain_client.ex @@ -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 @@ -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} @@ -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 diff --git a/lib/tt_eth/chain_client.ex b/lib/tt_eth/chain_client.ex index c41a3f8..722c3ca 100644 --- a/lib/tt_eth/chain_client.ex +++ b/lib/tt_eth/chain_client.ex @@ -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) diff --git a/lib/tt_eth/chain_client_mock_impl.ex b/lib/tt_eth/chain_client_mock_impl.ex index 1430445..d3e1cd2 100644 --- a/lib/tt_eth/chain_client_mock_impl.ex +++ b/lib/tt_eth/chain_client_mock_impl.ex @@ -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"}}