From bf11e2f2f35a9826f09ec26c90c6ca2de7cf747b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Bezerra?= Date: Tue, 3 Dec 2024 13:41:13 -0300 Subject: [PATCH] enha: add endpoint for faster external importing --- src/eth/rpc/rpc_server.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/eth/rpc/rpc_server.rs b/src/eth/rpc/rpc_server.rs index 9fd74150a..65ad2f8a8 100644 --- a/src/eth/rpc/rpc_server.rs +++ b/src/eth/rpc/rpc_server.rs @@ -36,6 +36,7 @@ use tracing::Instrument; use tracing::Span; use super::rpc_method_wrapper::metrics_wrapper; +use crate::alias::EthersReceipt; use crate::alias::JsonValue; use crate::eth::executor::Executor; use crate::eth::follower::consensus::Consensus; @@ -208,6 +209,9 @@ fn register_methods(mut module: RpcModule) -> anyhow::Result, ctx: Arc, ext: &Extensions) Ok(to_json_value(block_number)) } +fn stratus_get_block_and_receipts(params: Params<'_>, ctx: Arc, ext: &Extensions) -> Result { + // enter span + let _middleware_enter = ext.enter_middleware_span(); + let _method_enter = info_span!("rpc::stratus_getBlockAndReceipts").entered(); + + // parse params + let (_, filter) = next_rpc_param::(params.sequence())?; + + // track + tracing::info!(%filter, "reading block and receipts"); + + let Some(block) = ctx.storage.read_block(filter)? else { + tracing::info!(%filter, "block not found"); + return Ok(JsonValue::Null); + }; + + tracing::info!(%filter, "block with transactions found"); + let receipts = block.transactions.iter().cloned().map(EthersReceipt::from).collect::>(); + + Ok(json!({ + "block": block.to_json_rpc_with_full_transactions(), + "receipts": receipts, + })) +} + fn eth_get_block_by_hash(params: Params<'_>, ctx: Arc, ext: &Extensions) -> Result { eth_get_block_by_selector::<'h'>(params, ctx, ext) }