From c48c605bdf116ab18e5af51f6e97dd9ca10ee8e3 Mon Sep 17 00:00:00 2001 From: jiang Date: Thu, 25 Jan 2024 14:45:18 +0800 Subject: [PATCH 1/3] feat: support `eth_getBlockReceipts` --- .../eth_get_block_receipts.rs | 25 +++++++++++++++++++ src/rpc_cache_handler/mod.rs | 3 +++ 2 files changed, 28 insertions(+) create mode 100644 src/rpc_cache_handler/eth_get_block_receipts.rs diff --git a/src/rpc_cache_handler/eth_get_block_receipts.rs b/src/rpc_cache_handler/eth_get_block_receipts.rs new file mode 100644 index 0000000..00560ad --- /dev/null +++ b/src/rpc_cache_handler/eth_get_block_receipts.rs @@ -0,0 +1,25 @@ +use anyhow::Context; +use serde_json::Value; + +use crate::rpc_cache_handler::RpcCacheHandler; + +#[derive(Default, Clone)] +pub struct EthGetBlockReceipts; + +impl RpcCacheHandler for EthGetBlockReceipts { + fn method_name(&self) -> &'static str { + "eth_getBlockReceipts" + } + + fn extract_cache_key(&self, params: &Value) -> anyhow::Result> { + let params = params + .as_array() + .context("params not found or not an array")?; + + let block_number = params[0].as_str().context("params[0] not a string")?; + let block_number = + u64::from_str_radix(&block_number[2..], 16).context("block number not a hex string")?; + + Ok(Some(format!("0x{:x}", block_number))) + } +} \ No newline at end of file diff --git a/src/rpc_cache_handler/mod.rs b/src/rpc_cache_handler/mod.rs index f0804ba..f4e9a07 100644 --- a/src/rpc_cache_handler/mod.rs +++ b/src/rpc_cache_handler/mod.rs @@ -5,6 +5,7 @@ pub use eth_call::EthCall; pub use eth_chainid::EthChainId; pub use eth_get_balance::EthGetBalance; pub use eth_get_block_by_number::EthGetBlockByNumber; +pub use eth_get_block_receipts::EthGetBlockReceipts; pub use eth_get_code::EthGetCode; pub use eth_get_storage_at::EthGetStorageAt; pub use eth_get_transaction_by_block_hash_and_index::EthGetTransactionByBlockHashAndIndex; @@ -18,6 +19,7 @@ mod eth_call; mod eth_chainid; mod eth_get_balance; mod eth_get_block_by_number; +mod eth_get_block_receipts; mod eth_get_code; mod eth_get_storage_at; mod eth_get_transaction_by_block_hash_and_index; @@ -44,6 +46,7 @@ pub fn all_factories() -> Vec { || Box::new(EthChainId) as Box, || Box::new(EthGetBalance) as Box, || Box::new(EthGetBlockByNumber) as Box, + || Box::new(EthGetBlockReceipts) as Box, || Box::new(EthGetCode) as Box, || Box::new(EthGetStorageAt) as Box, || Box::new(EthGetTransactionByBlockHashAndIndex) as Box, From 22e42d12f98cbaca2e19631bb8ed6de998374339 Mon Sep 17 00:00:00 2001 From: jiang Date: Thu, 25 Jan 2024 14:46:12 +0800 Subject: [PATCH 2/3] style: cargo +nightly fmt --- src/rpc_cache_handler/eth_get_block_receipts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc_cache_handler/eth_get_block_receipts.rs b/src/rpc_cache_handler/eth_get_block_receipts.rs index 00560ad..e45836f 100644 --- a/src/rpc_cache_handler/eth_get_block_receipts.rs +++ b/src/rpc_cache_handler/eth_get_block_receipts.rs @@ -20,6 +20,6 @@ impl RpcCacheHandler for EthGetBlockReceipts { let block_number = u64::from_str_radix(&block_number[2..], 16).context("block number not a hex string")?; - Ok(Some(format!("0x{:x}", block_number))) + Ok(Some(format!("0x{:x}", block_number))) } -} \ No newline at end of file +} From 00932ddc55d9c05580bd30fef774fce59ffc30f6 Mon Sep 17 00:00:00 2001 From: jiang Date: Thu, 25 Jan 2024 14:49:43 +0800 Subject: [PATCH 3/3] docs: update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4347d5c..8bd56ff 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Mainly supported requests with determined block number. Other methods will be di - `eth_chainId` - `eth_getBalance` - `eth_getBlockByNumber` +- `eth_getBlockReceipts` - `eth_getCode` - `eth_getStorageAt` - `eth_getTransactionByHash`