Skip to content

Commit

Permalink
avoid initializing signer twice
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Nov 19, 2024
1 parent f01aa15 commit e027089
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions crates/cast/bin/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,25 @@ impl SendTxArgs {
// If we cannot successfully instantiate a local signer, then we will assume we don't have
// enough information to sign and we must bail.
} else {
// Retrieve the signer, and bail if it can't be constructed.
let signer = eth.wallet.signer().await?;
let zk_signer = eth.wallet.signer().await?;
let from = signer.address();
// NOTE(zk): Avoid initializing `signer` twice as it will error out with Ledger, so we
// move the signers to their respective blocks.
if zksync_params.zksync {
// Retrieve the signer, and bail if it can't be constructed.
let zk_signer: foundry_wallets::WalletSigner = eth.wallet.signer().await?;
let from = zk_signer.address();

tx::validate_from_address(eth.wallet.from, from)?;
tx::validate_from_address(eth.wallet.from, from)?;

if zksync_params.zksync {
// Zksync transaction
let (tx, _) = builder.build(&signer).await?;

let wallet = EthereumWallet::from(signer);
let provider = ProviderBuilder::<_, _, AnyNetwork>::default()
.wallet(wallet)
.on_provider(&provider);
let (tx, _) = builder.build(&zk_signer).await?;

let zk_wallet = ZksyncWallet::from(zk_signer);
let zk_provider = ProviderBuilder::<_, _, Zksync>::default()
.wallet(zk_wallet)
.wallet(zk_wallet.clone())
.on_provider(&zk_provider);
let provider = ProviderBuilder::<_, _, AnyNetwork>::default()
.wallet(zk_wallet)
.on_provider(&provider);

cast_send_zk(
provider,
Expand All @@ -225,6 +224,12 @@ impl SendTxArgs {
)
.await
} else {
// Retrieve the signer, and bail if it can't be constructed.
let signer = eth.wallet.signer().await?;
let from = signer.address();

tx::validate_from_address(eth.wallet.from, from)?;

// Standard transaction
let (tx, _) = builder.build(&signer).await?;

Expand Down

0 comments on commit e027089

Please sign in to comment.