Skip to content

Commit

Permalink
work around for empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Nov 25, 2024
1 parent ed99008 commit f7e8cf5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions blocks/evm/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ pub fn collect_block(block: &Block, timestamp: &BlockTimestamp) -> BlockHeader {

// blob price
let blob_gas_price = block.transaction_traces.iter().find_map(|t| t.receipt.as_ref().and_then(|r| r.blob_gas_price.clone()));
let blob_hashes: Vec<String> = block.transaction_traces.iter().flat_map(|t| t.blob_hashes.iter().map(|hash| bytes_to_hex(hash))).collect();
let mut blob_hashes: Vec<String> = block.transaction_traces.iter().flat_map(|t| t.blob_hashes.iter().map(|hash| bytes_to_hex(hash))).collect();
let total_blobs: u32 = blob_hashes.len() as u32;
let blob_transactions = block.transaction_traces.iter().filter(|t| t.r#type == 3).map(|t| bytes_to_hex(&t.hash)).collect::<Vec<String>>();
let mut blob_transactions = block.transaction_traces.iter().filter(|t| t.r#type == 3).map(|t| bytes_to_hex(&t.hash)).collect::<Vec<String>>();
let total_blob_transactions = blob_transactions.len() as u32;

// ISSUE: WORK AROUND
// Array cannot be empty
// https://github.com/streamingfast/substreams-sink-files/issues/11
if blob_hashes.is_empty() {
blob_hashes.push("".to_string());
}
if blob_transactions.is_empty() {
blob_transactions.push("".to_string());
}

BlockHeader {
// clock
time: Some(timestamp.time),
Expand Down
10 changes: 9 additions & 1 deletion blocks/evm/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ pub fn collect_transactions(block: &Block, timestamp: &BlockTimestamp) -> Vec<Tr
.iter()
.map(|transaction| {
let receipt = transaction.receipt.clone().unwrap();
let mut blob_hashes: Vec<String> = transaction.blob_hashes.iter().map(|hash| bytes_to_hex(hash)).collect();

// // ISSUE: WORK AROUND
// // Array cannot be empty
// // https://github.com/streamingfast/substreams-sink-files/issues/11
if blob_hashes.is_empty() {
blob_hashes.push("".to_string());
}
Transaction {
// block
block_time: Some(timestamp.time),
Expand Down Expand Up @@ -88,7 +96,7 @@ pub fn collect_transactions(block: &Block, timestamp: &BlockTimestamp) -> Vec<Tr
blob_gas_price_bytes: receipt.blob_gas_price.clone().unwrap_or_default().bytes,
blob_gas_used: receipt.blob_gas_used(),
blob_gas_fee_cap: transaction.clone().blob_gas_fee_cap.unwrap_or_default().bytes,
blob_hashes: transaction.blob_hashes.iter().map(|hash| bytes_to_hex(hash)).collect(),
blob_hashes,
}
})
.collect()
Expand Down

0 comments on commit f7e8cf5

Please sign in to comment.