Skip to content

Commit

Permalink
Merge pull request #1 from fenghaojiang/main
Browse files Browse the repository at this point in the history
feat: support eth_getBlockReceipts
  • Loading branch information
tonyke-bot authored Jan 25, 2024
2 parents fdec0f4 + 00932dd commit 7aad1cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
25 changes: 25 additions & 0 deletions src/rpc_cache_handler/eth_get_block_receipts.rs
Original file line number Diff line number Diff line change
@@ -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<Option<String>> {
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)))
}
}
3 changes: 3 additions & 0 deletions src/rpc_cache_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -44,6 +46,7 @@ pub fn all_factories() -> Vec<RpcCacheHandlerFactory> {
|| Box::new(EthChainId) as Box<dyn RpcCacheHandler>,
|| Box::new(EthGetBalance) as Box<dyn RpcCacheHandler>,
|| Box::new(EthGetBlockByNumber) as Box<dyn RpcCacheHandler>,
|| Box::new(EthGetBlockReceipts) as Box<dyn RpcCacheHandler>,
|| Box::new(EthGetCode) as Box<dyn RpcCacheHandler>,
|| Box::new(EthGetStorageAt) as Box<dyn RpcCacheHandler>,
|| Box::new(EthGetTransactionByBlockHashAndIndex) as Box<dyn RpcCacheHandler>,
Expand Down

0 comments on commit 7aad1cd

Please sign in to comment.