Skip to content
Merged
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
4 changes: 4 additions & 0 deletions crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ pub enum EthRequest {
#[serde(rename = "anvil_getBlobsByTransactionHash", with = "sequence")]
GetBlobByTransactionHash(TxHash),

/// Returns the blobs for a given transaction hash.
#[serde(rename = "anvil_getBlobSidecarsByBlockId", with = "sequence")]
GetBlobSidecarsByBlockId(BlockId),

#[serde(rename = "eth_getTransactionByBlockHashAndIndex")]
EthGetTransactionByBlockHashAndIndex(TxHash, Index),

Expand Down
13 changes: 13 additions & 0 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use alloy_consensus::{
use alloy_dyn_abi::TypedData;
use alloy_eips::{
eip2718::Encodable2718,
eip4844::BlobTransactionSidecar,
eip7910::{EthConfig, EthForkConfig},
};
use alloy_evm::overrides::{OverrideBlockHashes, apply_state_overrides};
Expand Down Expand Up @@ -284,6 +285,9 @@ impl EthApi {
EthRequest::GetBlobByTransactionHash(hash) => {
self.anvil_get_blob_by_tx_hash(hash).to_rpc_result()
}
EthRequest::GetBlobSidecarsByBlockId(block_id) => {
self.anvil_get_blob_sidecars_by_block_id(block_id).to_rpc_result()
}
EthRequest::EthGetRawTransactionByBlockHashAndIndex(hash, index) => {
self.raw_transaction_by_block_hash_and_index(hash, index).await.to_rpc_result()
}
Expand Down Expand Up @@ -1352,6 +1356,15 @@ impl EthApi {
Ok(self.backend.get_blob_by_tx_hash(hash)?)
}

/// Handler for RPC call: `anvil_getBlobSidecarsByBlockId`
pub fn anvil_get_blob_sidecars_by_block_id(
&self,
block_id: BlockId,
) -> Result<Option<BlobTransactionSidecar>> {
node_info!("anvil_getBlobSidecarsByBlockId");
Ok(self.backend.get_blob_sidecars_by_block_id(block_id)?)
}

/// Get transaction by its hash.
///
/// This will check the storage for a matching transaction, if no transaction exists in storage
Expand Down
27 changes: 26 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ use alloy_consensus::{
};
use alloy_eip5792::{Capabilities, DelegationCapability};
use alloy_eips::{
eip1559::BaseFeeParams, eip4844::kzg_to_versioned_hash, eip7840::BlobParams,
eip1559::BaseFeeParams,
eip4844::{BlobTransactionSidecar, kzg_to_versioned_hash},
eip7840::BlobParams,
eip7910::SystemContract,
};
use alloy_evm::{
Expand Down Expand Up @@ -3281,6 +3283,29 @@ impl Backend {
Ok(None)
}

pub fn get_blob_sidecars_by_block_id(
&self,
block_id: BlockId,
) -> Result<Option<BlobTransactionSidecar>> {
if let Some(full_block) = self.get_full_block(block_id) {
let sidecar = full_block
.into_transactions_iter()
.map(TypedTransaction::try_from)
.filter_map(|typed_tx_result| {
typed_tx_result.ok()?.sidecar().map(|sidecar| sidecar.sidecar().clone())
})
.fold(BlobTransactionSidecar::default(), |mut acc, sidecar| {
acc.blobs.extend(sidecar.blobs);
acc.commitments.extend(sidecar.commitments);
acc.proofs.extend(sidecar.proofs);
acc
});
Ok(Some(sidecar))
} else {
Ok(None)
}
}

pub fn get_blob_by_versioned_hash(&self, hash: B256) -> Result<Option<Blob>> {
let storage = self.blockchain.storage.read();
for block in storage.blocks.values() {
Expand Down
Loading