Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions crates/anvil/src/eth/backend/info.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Handler that can get current storage related data

use crate::mem::Backend;
use alloy_consensus::TxReceipt;
use alloy_network::{AnyRpcBlock, Network};
use alloy_primitives::B256;
use anvil_core::eth::block::Block;
use foundry_primitives::{FoundryNetwork, FoundryReceiptEnvelope};
use std::{fmt, sync::Arc};

/// A type that can fetch data related to the ethereum storage.
Expand Down Expand Up @@ -39,16 +39,17 @@ impl<N: Network> StorageInfo<N> {
}
}

impl StorageInfo<FoundryNetwork> {
// TODO: receipts methods require N::ReceiptEnvelope generalization

impl<N: Network> StorageInfo<N>
where
N::ReceiptEnvelope: TxReceipt<Log = alloy_primitives::Log> + Clone,
{
/// Returns the receipts of the current block
pub fn current_receipts(&self) -> Option<Vec<FoundryReceiptEnvelope>> {
pub fn current_receipts(&self) -> Option<Vec<N::ReceiptEnvelope>> {
self.backend.mined_receipts(self.backend.best_hash())
}

/// Returns the receipts of the block with the given hash
pub fn receipts(&self, hash: B256) -> Option<Vec<FoundryReceiptEnvelope>> {
pub fn receipts(&self, hash: B256) -> Option<Vec<N::ReceiptEnvelope>> {
self.backend.mined_receipts(hash)
}
}
Expand Down
26 changes: 13 additions & 13 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ impl<N: Network> Backend<N> {

impl<N: Network> Backend<N>
where
N::ReceiptEnvelope: alloy_consensus::TxReceipt<Log = alloy_primitives::Log>,
N::ReceiptEnvelope: alloy_consensus::TxReceipt<Log = alloy_primitives::Log> + Clone,
{
/// Returns all `Log`s mined by the node that were emitted in the `block` and match the `Filter`
fn mined_logs_for_block(&self, filter: Filter, block: Block, block_hash: B256) -> Vec<Log> {
Expand Down Expand Up @@ -1678,6 +1678,18 @@ where
self.logs_for_range(&filter, from_block, to_block).await
}
}

/// Returns all receipts of the block
pub fn mined_receipts(&self, hash: B256) -> Option<Vec<N::ReceiptEnvelope>> {
let block = self.mined_block_by_hash(hash)?;
let mut receipts = Vec::new();
let storage = self.blockchain.storage.read();
for tx in block.transactions.hashes() {
let receipt = storage.transactions.get(&tx)?.receipt.clone();
receipts.push(receipt);
}
Some(receipts)
}
}

impl Backend<FoundryNetwork> {
Expand Down Expand Up @@ -3327,18 +3339,6 @@ impl Backend<FoundryNetwork> {
Ok(None)
}

/// Returns all receipts of the block
pub fn mined_receipts(&self, hash: B256) -> Option<Vec<FoundryReceiptEnvelope>> {
let block = self.mined_block_by_hash(hash)?;
let mut receipts = Vec::new();
let storage = self.blockchain.storage.read();
for tx in block.transactions.hashes() {
let receipt = storage.transactions.get(&tx)?.receipt.clone();
receipts.push(receipt);
}
Some(receipts)
}

/// Returns all transaction receipts of the block
pub fn mined_block_receipts(&self, id: impl Into<BlockId>) -> Option<Vec<FoundryTxReceipt>> {
let mut receipts = Vec::new();
Expand Down
Loading