mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): Implement debug_codeByHash. (#14524)
This commit is contained in:
@ -195,6 +195,11 @@ pub trait DebugApi {
|
|||||||
#[method(name = "chaindbProperty")]
|
#[method(name = "chaindbProperty")]
|
||||||
async fn debug_chaindb_property(&self, property: String) -> RpcResult<()>;
|
async fn debug_chaindb_property(&self, property: String) -> RpcResult<()>;
|
||||||
|
|
||||||
|
/// 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>;
|
||||||
|
|
||||||
/// Turns on CPU profiling for the given duration and writes profile data to disk.
|
/// Turns on CPU profiling for the given duration and writes profile data to disk.
|
||||||
#[method(name = "cpuProfile")]
|
#[method(name = "cpuProfile")]
|
||||||
async fn debug_cpu_profile(&self, file: String, seconds: u64) -> RpcResult<()>;
|
async fn debug_cpu_profile(&self, file: String, seconds: u64) -> RpcResult<()>;
|
||||||
|
|||||||
@ -25,7 +25,8 @@ use reth_primitives::{NodePrimitives, ReceiptWithBloom, RecoveredBlock};
|
|||||||
use reth_primitives_traits::{Block as _, BlockBody, SignedTransaction};
|
use reth_primitives_traits::{Block as _, BlockBody, SignedTransaction};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider, ProviderBlock,
|
BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider, ProviderBlock,
|
||||||
ReceiptProviderIdExt, StateProofProvider, TransactionVariant,
|
ReceiptProviderIdExt, StateProofProvider, StateProvider, StateProviderFactory,
|
||||||
|
TransactionVariant,
|
||||||
};
|
};
|
||||||
use reth_revm::{database::StateProviderDatabase, witness::ExecutionWitnessRecord};
|
use reth_revm::{database::StateProviderDatabase, witness::ExecutionWitnessRecord};
|
||||||
use reth_rpc_api::DebugApiServer;
|
use reth_rpc_api::DebugApiServer;
|
||||||
@ -660,6 +661,23 @@ where
|
|||||||
.await
|
.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.
|
||||||
|
pub async fn debug_code_by_hash(
|
||||||
|
&self,
|
||||||
|
hash: B256,
|
||||||
|
block_id: Option<BlockId>,
|
||||||
|
) -> Result<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())
|
||||||
|
}
|
||||||
|
|
||||||
/// Executes the configured transaction with the environment on the given database.
|
/// Executes the configured transaction with the environment on the given database.
|
||||||
///
|
///
|
||||||
/// It optionally takes fused inspector ([`TracingInspector::fused`]) to avoid re-creating the
|
/// It optionally takes fused inspector ([`TracingInspector::fused`]) to avoid re-creating the
|
||||||
@ -1044,6 +1062,10 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn debug_code_by_hash(&self, hash: B256, block_id: Option<BlockId>) -> RpcResult<Bytes> {
|
||||||
|
Self::debug_code_by_hash(self, hash, block_id).await.map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
async fn debug_cpu_profile(&self, _file: String, _seconds: u64) -> RpcResult<()> {
|
async fn debug_cpu_profile(&self, _file: String, _seconds: u64) -> RpcResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user