Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make return for debug_codeByHash optional #14572

Merged
merged 1 commit into from
Feb 18, 2025
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
6 changes: 5 additions & 1 deletion crates/rpc/rpc-api/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ pub trait DebugApi {
/// Returns the code associated with a given hash at the specified block ID.
/// If no block ID is provided, it defaults to the latest block.
#[method(name = "codeByHash")]
async fn debug_code_by_hash(&self, hash: B256, block_id: Option<BlockId>) -> RpcResult<Bytes>;
async fn debug_code_by_hash(
&self,
hash: B256,
block_id: Option<BlockId>,
) -> RpcResult<Option<Bytes>>;

/// Turns on CPU profiling for the given duration and writes profile data to disk.
#[method(name = "cpuProfile")]
Expand Down
15 changes: 9 additions & 6 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,21 +654,20 @@ where
.await
}

/// Returns the code associated with a given hash at the specified block ID.
/// If no block ID is provided, it defaults to the latest block.
/// Returns the code associated with a given hash at the specified block ID. If no code is
/// found, it returns None. If no block ID is provided, it defaults to the latest block.
pub async fn debug_code_by_hash(
&self,
hash: B256,
block_id: Option<BlockId>,
) -> Result<Bytes, Eth::Error> {
) -> Result<Option<Bytes>, Eth::Error> {
Ok(self
.provider()
.state_by_block_id(block_id.unwrap_or_default())
.map_err(Eth::Error::from_eth_err)?
.bytecode_by_hash(&hash)
.map_err(Eth::Error::from_eth_err)?
.unwrap_or_default()
.original_bytes())
.map(|b| b.original_bytes()))
}

/// Executes the configured transaction with the environment on the given database.
Expand Down Expand Up @@ -1051,7 +1050,11 @@ where
Ok(())
}

async fn debug_code_by_hash(&self, hash: B256, block_id: Option<BlockId>) -> RpcResult<Bytes> {
async fn debug_code_by_hash(
&self,
hash: B256,
block_id: Option<BlockId>,
) -> RpcResult<Option<Bytes>> {
Self::debug_code_by_hash(self, hash, block_id).await.map_err(Into::into)
}

Expand Down
Loading