Skip to content

Commit da591ba

Browse files
authored
feat(receipts): add block_timestamp to transaction_receipts table (#397)
- Add block_timestamp field to transaction_receipts schema - Create index on block_timestamp for efficient time-based queries - Update store_transaction_receipt to accept and store block_timestamp - Pass block_timestamp from engine to storage layer This enables temporal analysis of transaction receipts and fee trends.
1 parent 06feb03 commit da591ba

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

crates/indexer/engine/src/engine.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ impl<P: Provider + Send + Sync + Clone + std::fmt::Debug + 'static> Engine<P> {
477477

478478
// Store receipt if available
479479
if let Some(receipt) = receipt {
480-
self.storage.store_transaction_receipt(receipt).await?;
480+
self.storage
481+
.store_transaction_receipt(receipt, block_timestamp)
482+
.await?;
481483
}
482484

483485
Ok(())

crates/migrations/20251124215151_transaction_receipts.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ CREATE TABLE transaction_receipts (
1212
execution_resources TEXT NOT NULL,
1313
block_hash TEXT,
1414
block_number INTEGER NOT NULL,
15+
block_timestamp INTEGER NOT NULL,
1516
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
1617
UNIQUE (transaction_hash)
1718
);
1819

19-
CREATE INDEX idx_transaction_receipts_block_number ON transaction_receipts(block_number);
20+
CREATE INDEX idx_transaction_receipts_block_number ON transaction_receipts(block_number);
21+
CREATE INDEX idx_transaction_receipts_block_timestamp ON transaction_receipts(block_timestamp);

crates/sqlite/sqlite/src/storage.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,7 @@ impl Storage for Sql {
22052205
async fn store_transaction_receipt(
22062206
&self,
22072207
receipt_with_block: &starknet::core::types::TransactionReceiptWithBlockInfo,
2208+
block_timestamp: u64,
22082209
) -> Result<(), StorageError> {
22092210
use starknet::core::types::{ExecutionResult, ReceiptBlock, TransactionReceipt};
22102211

@@ -2275,8 +2276,8 @@ impl Storage for Sql {
22752276
self.executor
22762277
.send(QueryMessage::other(
22772278
"INSERT INTO transaction_receipts (id, transaction_hash, actual_fee_amount, actual_fee_unit, \
2278-
execution_status, finality_status, revert_reason, execution_resources, block_hash, block_number) \
2279-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) \
2279+
execution_status, finality_status, revert_reason, execution_resources, block_hash, block_number, block_timestamp) \
2280+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) \
22802281
ON CONFLICT(transaction_hash) DO UPDATE SET \
22812282
actual_fee_amount=excluded.actual_fee_amount, \
22822283
actual_fee_unit=excluded.actual_fee_unit, \
@@ -2285,7 +2286,8 @@ impl Storage for Sql {
22852286
revert_reason=excluded.revert_reason, \
22862287
execution_resources=excluded.execution_resources, \
22872288
block_hash=excluded.block_hash, \
2288-
block_number=excluded.block_number \
2289+
block_number=excluded.block_number, \
2290+
block_timestamp=excluded.block_timestamp \
22892291
RETURNING *"
22902292
.to_string(),
22912293
vec![
@@ -2299,6 +2301,7 @@ impl Storage for Sql {
22992301
Argument::String(execution_resources_json),
23002302
Argument::String(block_hash.unwrap_or_default()),
23012303
Argument::String(block_number.to_string()),
2304+
Argument::String(block_timestamp.to_string()),
23022305
],
23032306
))
23042307
.map_err(|e| {

crates/storage/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub trait Storage: ReadOnlyStorage + Send + Sync + Debug {
249249
async fn store_transaction_receipt(
250250
&self,
251251
receipt: &starknet::core::types::TransactionReceiptWithBlockInfo,
252+
block_timestamp: u64,
252253
) -> Result<(), StorageError>;
253254

254255
/// Stores an event with the storage.

0 commit comments

Comments
 (0)