Skip to content

Commit

Permalink
feat(storage): add receipts_for_block getter
Browse files Browse the repository at this point in the history
  • Loading branch information
kkovaacs committed Jan 22, 2024
1 parent e7a70e9 commit ce71db7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
7 changes: 7 additions & 0 deletions crates/storage/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ impl<'inner> Transaction<'inner> {
transaction::transactions_for_block(self, block)
}

pub fn receipts_for_block(
&self,
block: BlockId,
) -> anyhow::Result<Option<Vec<gateway::Receipt>>> {
transaction::receipts_for_block(self, block)
}

pub fn transaction_hashes_for_block(
&self,
block: BlockId,
Expand Down
14 changes: 7 additions & 7 deletions crates/storage/src/connection/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use pathfinder_common::{

pub const PAGE_SIZE_LIMIT: usize = 1_024;
pub const KEY_FILTER_LIMIT: usize = 16;
const MAX_BLOCKS_TO_SCAN: usize = 200;
const MAX_BLOCKS_TO_SCAN: usize = 300;

#[derive(Debug)]
pub struct EventFilter {
Expand Down Expand Up @@ -148,10 +148,10 @@ pub(super) fn get_events(
return Err(EventFilterError::TooManyMatches);
}

let transaction_data = tx.transaction_data_for_block(crate::BlockId::Number(
BlockNumber::new_or_panic(block_number),
))?;
let Some(transaction_data) = transaction_data else {
let receipts = tx.receipts_for_block(crate::BlockId::Number(BlockNumber::new_or_panic(
block_number,
)))?;
let Some(receipts) = receipts else {
break;
};

Expand All @@ -161,9 +161,9 @@ pub(super) fn get_events(
.map(|keys| keys.iter().collect())
.collect();

let events = transaction_data
let events = receipts
.into_iter()
.flat_map(|(_, receipt)| {
.flat_map(|receipt| {
receipt
.events
.into_iter()
Expand Down
32 changes: 32 additions & 0 deletions crates/storage/src/connection/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,38 @@ pub(super) fn transactions_for_block(
Ok(Some(data))
}

pub(super) fn receipts_for_block(
tx: &Transaction<'_>,
block: BlockId,
) -> anyhow::Result<Option<Vec<gateway::Receipt>>> {
let Some((_, block_hash)) = tx.block_id(block)? else {
return Ok(None);
};

let mut stmt = tx
.inner()
.prepare("SELECT receipt FROM starknet_transactions WHERE block_hash = ? ORDER BY idx ASC")
.context("Preparing statement")?;

let mut rows = stmt
.query(params![&block_hash])
.context("Executing query")?;

let mut data = Vec::new();
while let Some(row) = rows.next()? {
let receipt = row
.get_ref_unwrap("receipt")
.as_blob_or_null()?
.context("Transaction data missing")?;
let receipt = zstd::decode_all(receipt).context("Decompressing receipt")?;
let receipt = serde_json::from_slice(&receipt).context("Deserializing receipt")?;

data.push(receipt);
}

Ok(Some(data))
}

pub(super) fn transaction_hashes_for_block(
tx: &Transaction<'_>,
block: BlockId,
Expand Down

0 comments on commit ce71db7

Please sign in to comment.