Skip to content

Commit cdf90f3

Browse files
committed
chain: Modernize EthereumAdapter.load_full_block
1 parent 716c456 commit cdf90f3

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,13 +1118,11 @@ pub trait EthereumAdapter: Send + Sync + 'static {
11181118
) -> Result<Option<LightEthereumBlock>, Error>;
11191119

11201120
/// Load full information for the specified `block` (in particular, transaction receipts).
1121-
fn load_full_block(
1121+
async fn load_full_block(
11221122
&self,
11231123
logger: &Logger,
11241124
block: LightEthereumBlock,
1125-
) -> Pin<
1126-
Box<dyn std::future::Future<Output = Result<EthereumBlock, bc::IngestorError>> + Send + '_>,
1127-
>;
1125+
) -> Result<EthereumBlock, bc::IngestorError>;
11281126

11291127
/// Find a block by its number, according to the Ethereum node.
11301128
///

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,12 +1394,11 @@ impl EthereumAdapterTrait for EthereumAdapter {
13941394
.await
13951395
}
13961396

1397-
fn load_full_block(
1397+
async fn load_full_block(
13981398
&self,
13991399
logger: &Logger,
14001400
block: LightEthereumBlock,
1401-
) -> Pin<Box<dyn std::future::Future<Output = Result<EthereumBlock, IngestorError>> + Send + '_>>
1402-
{
1401+
) -> Result<EthereumBlock, IngestorError> {
14031402
let web3 = Arc::clone(&self.web3);
14041403
let logger = logger.clone();
14051404
let block_hash = block.hash.expect("block is missing block hash");
@@ -1408,36 +1407,29 @@ impl EthereumAdapterTrait for EthereumAdapter {
14081407
// request an empty batch which is not valid in JSON-RPC.
14091408
if block.transactions.is_empty() {
14101409
trace!(logger, "Block {} contains no transactions", block_hash);
1411-
return Box::pin(std::future::ready(Ok(EthereumBlock {
1410+
return Ok(EthereumBlock {
14121411
block: Arc::new(block),
14131412
transaction_receipts: Vec::new(),
1414-
})));
1413+
});
14151414
}
14161415
let hashes: Vec<_> = block.transactions.iter().map(|txn| txn.hash).collect();
14171416

1418-
let supports_block_receipts_future = self.check_block_receipt_support_and_update_cache(
1419-
web3.clone(),
1420-
block_hash,
1421-
self.supports_eip_1898,
1422-
self.call_only,
1423-
logger.clone(),
1424-
);
1417+
let supports_block_receipts = self
1418+
.check_block_receipt_support_and_update_cache(
1419+
web3.clone(),
1420+
block_hash,
1421+
self.supports_eip_1898,
1422+
self.call_only,
1423+
logger.clone(),
1424+
)
1425+
.await;
14251426

1426-
let receipts_future = supports_block_receipts_future
1427-
.then(move |supports_block_receipts| {
1428-
fetch_receipts_with_retry(web3, hashes, block_hash, logger, supports_block_receipts)
1427+
fetch_receipts_with_retry(web3, hashes, block_hash, logger, supports_block_receipts)
1428+
.await
1429+
.map(|transaction_receipts| EthereumBlock {
1430+
block: Arc::new(block),
1431+
transaction_receipts,
14291432
})
1430-
.boxed();
1431-
1432-
let block_future =
1433-
futures03::TryFutureExt::map_ok(receipts_future, move |transaction_receipts| {
1434-
EthereumBlock {
1435-
block: Arc::new(block),
1436-
transaction_receipts,
1437-
}
1438-
});
1439-
1440-
Box::pin(block_future)
14411433
}
14421434

14431435
fn block_hash_by_block_number(

0 commit comments

Comments
 (0)