Skip to content

Commit

Permalink
Impl EthTraceTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank committed Mar 7, 2025
1 parent 7eb21c5 commit 85935e6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ impl RpcMethod<1> for EthGetTransactionByHash {
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(tx_hash,): Self::Params,
) -> Result<Self::Ok, ServerError> {
get_eth_transaction_by_hash(ctx, tx_hash, None).await
get_eth_transaction_by_hash(&ctx, &tx_hash, None).await
}
}

Expand All @@ -2250,16 +2250,16 @@ impl RpcMethod<2> for EthGetTransactionByHashLimited {
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(tx_hash, limit): Self::Params,
) -> Result<Self::Ok, ServerError> {
get_eth_transaction_by_hash(ctx, tx_hash, Some(limit)).await
get_eth_transaction_by_hash(&ctx, &tx_hash, Some(limit)).await
}
}

async fn get_eth_transaction_by_hash(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
tx_hash: EthHash,
ctx: &Ctx<impl Blockstore + Send + Sync + 'static>,
tx_hash: &EthHash,
limit: Option<ChainEpoch>,
) -> Result<Option<ApiEthTx>, ServerError> {
let message_cid = ctx.chain_store().get_mapping(&tx_hash)?.unwrap_or_else(|| {
let message_cid = ctx.chain_store().get_mapping(tx_hash)?.unwrap_or_else(|| {
tracing::debug!(
"could not find transaction hash {} in Ethereum mapping",
tx_hash
Expand Down Expand Up @@ -2908,6 +2908,37 @@ async fn trace_block<B: Blockstore + Send + Sync + 'static>(
Ok(all_traces)
}

pub enum EthTraceTransaction {}
impl RpcMethod<1> for EthTraceTransaction {
const NAME: &'static str = "Filecoin.EthTraceTransaction";
const NAME_ALIAS: Option<&'static str> = Some("trace_transaction");
const N_REQUIRED_PARAMS: usize = 1;
const PARAM_NAMES: [&'static str; 1] = ["tx_hash"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;
type Params = (String,);
type Ok = Vec<EthBlockTrace>;
async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(tx_hash,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let eth_hash = EthHash::from_str(&tx_hash)?;
let eth_txn = get_eth_transaction_by_hash(&ctx, &eth_hash, None)
.await?
.ok_or(ServerError::internal_error("transaction not found", None))?;

let traces = trace_block(
ctx,
ExtBlockNumberOrHash::from_block_number(eth_txn.block_number.0 as i64),
)
.await?
.into_iter()
.filter(|trace| trace.transaction_hash == eth_hash)
.collect();
Ok(traces)
}
}

pub enum EthTraceReplayBlockTransactions {}
impl RpcMethod<2> for EthTraceReplayBlockTransactions {
const N_REQUIRED_PARAMS: usize = 2;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ macro_rules! for_each_rpc_method {
$callback!($crate::rpc::eth::EthUninstallFilter);
$callback!($crate::rpc::eth::EthSyncing);
$callback!($crate::rpc::eth::EthTraceBlock);
$callback!($crate::rpc::eth::EthTraceTransaction);
$callback!($crate::rpc::eth::EthTraceReplayBlockTransactions);
$callback!($crate::rpc::eth::Web3ClientVersion);
$callback!($crate::rpc::eth::EthSendRawTransaction);
Expand Down
3 changes: 3 additions & 0 deletions src/tool/subcommands/api_cmd/api_compare_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,9 @@ fn eth_state_tests_with_tipset<DB: Blockstore>(
tests.push(RpcTest::identity(EthGetTransactionByHashLimited::request(
(tx.hash.clone(), shared_tipset.epoch()),
)?));
tests.push(RpcTest::identity(
EthTraceTransaction::request((tx.hash.to_string(),)).unwrap(),
));
if smsg.message.from.protocol() == Protocol::Delegated
&& smsg.message.to.protocol() == Protocol::Delegated
{
Expand Down

0 comments on commit 85935e6

Please sign in to comment.