Skip to content

Commit 4702444

Browse files
committed
chain: Modernize EthereumAdapter.load_full_block
1 parent 6d6b754 commit 4702444

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
@@ -1397,12 +1397,11 @@ impl EthereumAdapterTrait for EthereumAdapter {
13971397
.await
13981398
}
13991399

1400-
fn load_full_block(
1400+
async fn load_full_block(
14011401
&self,
14021402
logger: &Logger,
14031403
block: LightEthereumBlock,
1404-
) -> Pin<Box<dyn std::future::Future<Output = Result<EthereumBlock, IngestorError>> + Send + '_>>
1405-
{
1404+
) -> Result<EthereumBlock, IngestorError> {
14061405
let web3 = Arc::clone(&self.web3);
14071406
let logger = logger.clone();
14081407
let block_hash = block.hash.expect("block is missing block hash");
@@ -1411,36 +1410,29 @@ impl EthereumAdapterTrait for EthereumAdapter {
14111410
// request an empty batch which is not valid in JSON-RPC.
14121411
if block.transactions.is_empty() {
14131412
trace!(logger, "Block {} contains no transactions", block_hash);
1414-
return Box::pin(std::future::ready(Ok(EthereumBlock {
1413+
return Ok(EthereumBlock {
14151414
block: Arc::new(block),
14161415
transaction_receipts: Vec::new(),
1417-
})));
1416+
});
14181417
}
14191418
let hashes: Vec<_> = block.transactions.iter().map(|txn| txn.hash).collect();
14201419

1421-
let supports_block_receipts_future = self.check_block_receipt_support_and_update_cache(
1422-
web3.clone(),
1423-
block_hash,
1424-
self.supports_eip_1898,
1425-
self.call_only,
1426-
logger.clone(),
1427-
);
1420+
let supports_block_receipts = self
1421+
.check_block_receipt_support_and_update_cache(
1422+
web3.clone(),
1423+
block_hash,
1424+
self.supports_eip_1898,
1425+
self.call_only,
1426+
logger.clone(),
1427+
)
1428+
.await;
14281429

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

14461438
fn block_hash_by_block_number(

0 commit comments

Comments
 (0)