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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.8.2"
version = "0.8.3"
edition = "2021"
rust-version = "1.81"
authors = ["init4"]
Expand Down
20 changes: 16 additions & 4 deletions crates/rpc/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ where
Ok(builder.build())
}

/// Get the [`Header`] for a given block.
pub async fn raw_header(
&self,
t: impl Into<BlockId>,
) -> Result<Option<(B256, Header)>, EthApiError> {
let Some(hash) = self.provider.block_hash_for_id(t.into())? else {
return Ok(None);
};

let header = self.cache.get_header(hash).await.map_err(EthApiError::from)?;

Ok(Some((hash, header)))
}

/// Get the block for a given block, returning the block hash and
/// the block itself.
pub async fn raw_block(
Expand Down Expand Up @@ -513,20 +527,18 @@ where
build_signet_receipt(tx, meta, receipt, all_receipts.to_vec()).map(Some)
}

/// Create the [`Block`] object for a specific [`BlockId`].
/// Create the [`Header`] object for a specific [`BlockId`].
pub async fn block_cfg(&self, mut block_id: BlockId) -> Result<Header, EthApiError> {
// If the block is pending, we'll load the latest and
let pending = block_id.is_pending();
if pending {
block_id = BlockId::latest();
}

let Some((_, block)) = self.raw_block(block_id).await? else {
let Some((_, mut header)) = self.raw_header(block_id).await? else {
return Err(EthApiError::HeaderNotFound(block_id));
};

let mut header = block.clone_header();

// Modify the header for pending blocks, to simulate the next block.
if pending {
header.parent_hash = header.hash_slow();
Expand Down