Skip to content

Commit afcf5b1

Browse files
authored
chore: include tx in setup output (#8324)
1 parent dc4ddda commit afcf5b1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

crates/anvil/src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ Chain ID: {}
245245
fork.block_hash(),
246246
fork.chain_id()
247247
);
248+
249+
if let Some(tx_hash) = fork.transaction_hash() {
250+
let _ = writeln!(config_string, "Transaction hash: {tx_hash}");
251+
}
248252
} else {
249253
let _ = write!(
250254
config_string,
@@ -1169,6 +1173,7 @@ latest block number: {latest_block}"
11691173
eth_rpc_url,
11701174
block_number: fork_block_number,
11711175
block_hash,
1176+
transaction_hash: self.fork_choice.and_then(|fc| fc.transaction_hash()),
11721177
provider,
11731178
chain_id,
11741179
override_chain_id,
@@ -1245,6 +1250,24 @@ pub enum ForkChoice {
12451250
Transaction(TxHash),
12461251
}
12471252

1253+
impl ForkChoice {
1254+
/// Returns the block number to fork from
1255+
pub fn block_number(&self) -> Option<BlockNumber> {
1256+
match self {
1257+
Self::Block(block_number) => Some(*block_number),
1258+
Self::Transaction(_) => None,
1259+
}
1260+
}
1261+
1262+
/// Returns the transaction hash to fork from
1263+
pub fn transaction_hash(&self) -> Option<TxHash> {
1264+
match self {
1265+
Self::Block(_) => None,
1266+
Self::Transaction(transaction_hash) => Some(*transaction_hash),
1267+
}
1268+
}
1269+
}
1270+
12481271
/// Convert a transaction hash into a ForkChoice
12491272
impl From<TxHash> for ForkChoice {
12501273
fn from(tx_hash: TxHash) -> Self {

crates/anvil/src/eth/backend/fork.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl ClientFork {
118118
self.config.read().block_number
119119
}
120120

121+
/// Returns the transaction hash we forked off of, if any.
122+
pub fn transaction_hash(&self) -> Option<B256> {
123+
self.config.read().transaction_hash
124+
}
125+
121126
pub fn total_difficulty(&self) -> U256 {
122127
self.config.read().total_difficulty
123128
}
@@ -579,6 +584,8 @@ pub struct ClientForkConfig {
579584
pub block_number: u64,
580585
/// The hash of the forked block
581586
pub block_hash: B256,
587+
/// The transaction hash we forked off of, if any.
588+
pub transaction_hash: Option<B256>,
582589
// TODO make provider agnostic
583590
pub provider: Arc<RetryProvider>,
584591
pub chain_id: u64,

0 commit comments

Comments
 (0)