Skip to content

Commit

Permalink
Refactor anchor transaction handling for improved code readability an…
Browse files Browse the repository at this point in the history
…d maintainability
  • Loading branch information
johntaiko committed Jul 8, 2024
1 parent a93d974 commit 920038e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/taiko/evm/src/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn check_anchor_tx(
check_anchor_signature(tx).context(anyhow!("failed to check anchor signature"))?;

// Extract the `to` address
let TxKind::Call(to) = anchor.to else { panic!("anchor tx not a smart contract call") };
let TxKind::Call(to) = anchor.to else { bail!("anchor tx not a smart contract call") };
// Check that it's from the golden touch address
ensure!(*from == *GOLDEN_TOUCH_ACCOUNT, "anchor transaction from mismatch");
// Check that the L2 contract is being called
Expand Down
4 changes: 2 additions & 2 deletions crates/taiko/payload/builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ fn check_anchor_tx(
base_fee_per_gas: u128,
chain_spec: &Arc<ChainSpec>,
) -> anyhow::Result<()> {
use anyhow::{anyhow, ensure, Context};
use anyhow::{anyhow, bail, ensure, Context};
let anchor = tx.as_eip1559().context(anyhow!("anchor tx is not an EIP1559 tx"))?;

// Check the signature
check_anchor_signature(tx).context(anyhow!("failed to check anchor signature"))?;

// Extract the `to` address
let TxKind::Call(to) = anchor.to else { panic!("anchor tx not a smart contract call") };
let TxKind::Call(to) = anchor.to else { bail!("anchor tx not a smart contract call") };
// Check that the L2 contract is being called
ensure!(to == chain_spec.l2_contract.unwrap(), "anchor transaction to mismatch");
// Check that it's from the golden touch address
Expand Down

0 comments on commit 920038e

Please sign in to comment.