Skip to content

Commit

Permalink
use eth_getBlockReceipts when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sslivkoff committed Aug 17, 2023
1 parent e3dd660 commit 50b7fa9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/freeze/src/datasets/blocks_and_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,41 @@ pub(crate) async fn fetch_blocks_and_transactions(
async fn get_txs_gas_used(
block: &Block<Transaction>,
source: Arc<Source>,
) -> Result<Vec<u32>, CollectError> {
match get_txs_gas_used_per_block(block, source.clone()).await {
Ok(value) => Ok(value),
Err(_) => get_txs_gas_used_per_tx(block, source).await,
}
}

async fn get_txs_gas_used_per_block(
block: &Block<Transaction>,
source: Arc<Source>,
) -> Result<Vec<u32>, CollectError> {
let block_number = match block.number {
Some(number) => number,
None => return Err(CollectError::CollectError("no block number".to_string())),
};
match source.provider.get_block_receipts(block_number).await {
Ok(receipts) => {
let mut gas_used: Vec<u32> = Vec::new();
for receipt in receipts {
match receipt.gas_used {
Some(value) => gas_used.push(value.as_u32()),
None => {
return Err(CollectError::CollectError("no gas_used for tx".to_string()))
}
}
}
Ok(gas_used)
}
Err(_) => Err(CollectError::CollectError("error in eth_getBlockReceipts".to_string())),
}
}

async fn get_txs_gas_used_per_tx(
block: &Block<Transaction>,
source: Arc<Source>,
) -> Result<Vec<u32>, CollectError> {
let source = Arc::new(source);
let mut tasks = Vec::new();
Expand Down

0 comments on commit 50b7fa9

Please sign in to comment.