Skip to content

Commit

Permalink
Feat/bloom filter (#710)
Browse files Browse the repository at this point in the history
* feat: add bloom filter in transaction receipt

* feat: add todo for bloom in block
  • Loading branch information
Eikix authored Jan 11, 2024
1 parent 0f02595 commit 0cfad71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/models/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl BlockWithTxHashes {
// TODO: Fetch real data
let gas_used = *GAS_USED;

// TODO: Fetch real data
// Difficulty should be 0 in a non-POW chain
let difficulty = *DIFFICULTY;

// TODO: Fetch real data
Expand All @@ -174,7 +174,9 @@ impl BlockWithTxHashes {
// TODO: Fetch real data
let size: Option<U256> = *SIZE;

// Bloom is a byte array of length 256
// TODO:
// Aggregate all the logs from the transactions
// Create a bloom filter from the logs and add it to the block
let logs_bloom = Bloom::default();
let extra_data = Bytes::default();

Expand Down
27 changes: 20 additions & 7 deletions src/models/transaction_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use reth_primitives::bloom::logs_bloom;
use reth_primitives::contract::create_address;
use reth_primitives::{Bloom, H256, U128, U256, U64, U8};
use reth_rpc_types::TransactionReceipt as EthTransactionReceipt;
use reth_primitives::{H256, U128, U256, U64, U8};
use reth_rpc_types::{Log, TransactionReceipt as EthTransactionReceipt};
use starknet::core::types::{
ExecutionResult, InvokeTransactionReceipt, MaybePendingTransactionReceipt, TransactionReceipt,
};
Expand Down Expand Up @@ -78,18 +79,30 @@ impl StarknetTransactionReceipt {
ExecutionResult::Reverted { .. } => Some(U64::from(0)),
};

let logs = events
let logs: Vec<Log> = events
.into_iter()
.map(StarknetEvent::new)
.filter_map(|event| {
event.to_eth_log(client, block_hash, block_number, transaction_hash, None, None).ok()
})
.collect();

// Reth note:
// This bloom operation is slow and should be cached if possible.
let bloom = {
let logs: Vec<reth_primitives::Log> = logs
.iter()
.map(|log| reth_primitives::Log {
data: log.data.clone(),
topics: log.topics.clone(),
address: log.address,
})
.collect();
logs_bloom(logs.iter())
};

EthTransactionReceipt {
transaction_hash,
// TODO: transition this hardcoded default out of nearing-demo-day hack and seeing how to
// properly source/translate this value
transaction_index: U64::from(0), // TODO: Fetch real data
block_hash,
block_number,
Expand All @@ -99,8 +112,8 @@ impl StarknetTransactionReceipt {
gas_used: Some(U256::from(500_000)),
contract_address,
logs,
state_root: None, // TODO: Fetch real data
logs_bloom: Bloom::default(), // TODO: Fetch real data
state_root: None,
logs_bloom: bloom,
status_code,
effective_gas_price: U128::from(1_000_000), // TODO: Fetch real data
transaction_type: U8::from(0), // TODO: Fetch real data
Expand Down

0 comments on commit 0cfad71

Please sign in to comment.