From 271c82496909870dec371b82e1ba3968a5d45fc6 Mon Sep 17 00:00:00 2001 From: James Duncombe Date: Mon, 26 Feb 2024 17:44:04 +0000 Subject: [PATCH] Adds eth_get_code and fixes return for fee_history. --- lib/tt_eth/behaviours/chain_client.ex | 3 ++ lib/tt_eth/chain_client.ex | 4 ++ lib/tt_eth/chain_client_mock_impl.ex | 56 ++++++++++++++------------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/tt_eth/behaviours/chain_client.ex b/lib/tt_eth/behaviours/chain_client.ex index 7e27f04..ad50e04 100644 --- a/lib/tt_eth/behaviours/chain_client.ex +++ b/lib/tt_eth/behaviours/chain_client.ex @@ -69,4 +69,7 @@ defmodule TTEth.Behaviours.ChainClient do @callback eth_get_block_by_number(block_id) :: any @callback eth_get_block_by_number(block_id, boolean) :: any + + @callback eth_get_code(address, block :: binary(), opts) :: {:ok, any} | {:error, any} + @callback eth_get_code(address, block :: binary()) :: {:ok, any} | {:error, any} end diff --git a/lib/tt_eth/chain_client.ex b/lib/tt_eth/chain_client.ex index 722c3ca..db77755 100644 --- a/lib/tt_eth/chain_client.ex +++ b/lib/tt_eth/chain_client.ex @@ -74,6 +74,10 @@ defmodule TTEth.ChainClient do def eth_get_block_by_number("" <> block, tx_detail \\ false), do: block |> HttpClient.eth_get_block_by_number(tx_detail) + @impl ChainClient + def eth_get_code("" <> address, block \\ "latest", opts \\ []), + do: address |> HttpClient.eth_get_code(block, opts) + ## Helpers outside of the ChainClient behaviour. def eth_get_transaction_receipt("" <> tx_hash, opts \\ []), diff --git a/lib/tt_eth/chain_client_mock_impl.ex b/lib/tt_eth/chain_client_mock_impl.ex index d3e1cd2..112310a 100644 --- a/lib/tt_eth/chain_client_mock_impl.ex +++ b/lib/tt_eth/chain_client_mock_impl.ex @@ -55,38 +55,40 @@ defmodule TTEth.ChainClientMockImpl do def eth_fee_history(_block_count, _newest_block, _reward_percentiles, _opts \\ []), do: {:ok, - [ - %{ - "oldestBlock" => "0x54", - "reward" => [ - [ - "0x174876e800", - "0x174876e800" - ], - [ - "0x174876e800", - "0x174876e800" - ], - [ - "0x174876e800", - "0x174876e800" - ] + %{ + "oldestBlock" => "0x54", + "reward" => [ + [ + "0x174876e800", + "0x174876e800" ], - "baseFeePerGas" => [ - "0x0", - "0x0", - "0x0", - "0x0" + [ + "0x174876e800", + "0x174876e800" ], - "gasUsedRatio" => [ - 0.0010253063265735019, - 0.006479788956353575, - 0.00006763590977418037 + [ + "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"}} + + @impl ChainClient + def eth_get_code(_address, _block \\ "latest", _opts \\ []), + do: {:ok, "0x60806040523661000b57005b600080357fffffffff"} end