From 534b028203b47b996895c6c39d48f6ffbf0fb5c0 Mon Sep 17 00:00:00 2001 From: cakevm Date: Tue, 18 Feb 2025 19:42:15 +0100 Subject: [PATCH] chore: make return for debug_codeByHash optional (#14572) --- crates/rpc/rpc-api/src/debug.rs | 6 +++++- crates/rpc/rpc/src/debug.rs | 15 +++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/rpc/rpc-api/src/debug.rs b/crates/rpc/rpc-api/src/debug.rs index 427bcfc7515a..c3246c333b4a 100644 --- a/crates/rpc/rpc-api/src/debug.rs +++ b/crates/rpc/rpc-api/src/debug.rs @@ -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) -> RpcResult; + async fn debug_code_by_hash( + &self, + hash: B256, + block_id: Option, + ) -> RpcResult>; /// Turns on CPU profiling for the given duration and writes profile data to disk. #[method(name = "cpuProfile")] diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index d15d16033e06..cdae15763d3f 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -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, - ) -> Result { + ) -> Result, 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. @@ -1051,7 +1050,11 @@ where Ok(()) } - async fn debug_code_by_hash(&self, hash: B256, block_id: Option) -> RpcResult { + async fn debug_code_by_hash( + &self, + hash: B256, + block_id: Option, + ) -> RpcResult> { Self::debug_code_by_hash(self, hash, block_id).await.map_err(Into::into) }