Skip to content

Commit eb44232

Browse files
authored
feat(wallets): MultiWallet generic Network (#13648)
1 parent 311231b commit eb44232

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

crates/cast/src/cmd/send.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use foundry_cli::{
1313
opts::TransactionOpts,
1414
utils::{LoadConfig, get_provider},
1515
};
16+
use foundry_primitives::FoundryNetwork;
1617

1718
use crate::tx::{self, CastTxBuilder, CastTxSender, SendTxOpts};
1819

@@ -139,7 +140,7 @@ impl SendTxArgs {
139140
let is_tempo = builder.is_tempo();
140141

141142
// Launch browser signer if `--browser` flag is set
142-
let browser = send_tx.browser.run().await?;
143+
let browser = send_tx.browser.run::<FoundryNetwork>().await?;
143144

144145
// Tempo transactions with browser signer are not supported
145146
if is_tempo && browser.is_some() {
@@ -189,7 +190,7 @@ impl SendTxArgs {
189190
// Browser wallet work differently as it sign and send the transaction in one step.
190191
if let Some(browser) = browser {
191192
let (tx_request, _) = builder.build(browser.address()).await?;
192-
let tx_hash = browser.send_transaction_via_browser(tx_request.into_inner()).await?;
193+
let tx_hash = browser.send_transaction_via_browser(tx_request).await?;
193194

194195
if send_tx.cast_async {
195196
sh_println!("{tx_hash:#x}")?;

crates/wallets/src/wallet_browser/opts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::time::Duration;
22

3+
use alloy_network::Network;
34
use clap::Parser;
45
use eyre::Result;
56
use serde::Serialize;
@@ -31,7 +32,7 @@ pub struct BrowserWalletOpts {
3132
}
3233

3334
impl BrowserWalletOpts {
34-
pub async fn run(&self) -> Result<Option<BrowserSigner>> {
35+
pub async fn run<N: Network>(&self) -> Result<Option<BrowserSigner<N>>> {
3536
Ok(if self.browser {
3637
Some(
3738
BrowserSigner::new(

crates/wallets/src/wallet_multi/mod.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
utils,
55
wallet_browser::signer::BrowserSigner,
66
};
7+
use alloy_network::{Ethereum, Network};
78
use alloy_primitives::map::AddressHashMap;
89
use alloy_signer::Signer;
910
use clap::Parser;
@@ -14,22 +15,32 @@ use serde::Serialize;
1415
use std::path::PathBuf;
1516

1617
/// Container for multiple wallets.
17-
#[derive(Debug, Default)]
18-
pub struct MultiWallet {
18+
#[derive(Debug)]
19+
pub struct MultiWallet<N: Network = Ethereum> {
1920
/// Vector of wallets that require an action to be unlocked.
2021
/// Those are lazily unlocked on the first access of the signers.
2122
pending_signers: Vec<PendingSigner>,
2223
/// Contains unlocked signers.
2324
signers: AddressHashMap<WalletSigner>,
2425
/// Browser signer
25-
browser: Option<BrowserSigner>,
26+
browser: Option<BrowserSigner<N>>,
2627
}
2728

28-
impl MultiWallet {
29+
impl<N: Network> Default for MultiWallet<N> {
30+
fn default() -> Self {
31+
Self {
32+
pending_signers: Default::default(),
33+
signers: Default::default(),
34+
browser: Default::default(),
35+
}
36+
}
37+
}
38+
39+
impl<N: Network> MultiWallet<N> {
2940
pub fn new(
3041
pending_signers: Vec<PendingSigner>,
3142
signers: Vec<WalletSigner>,
32-
browser: Option<BrowserSigner>,
43+
browser: Option<BrowserSigner<N>>,
3344
) -> Self {
3445
let signers = signers.into_iter().map(|signer| (signer.address(), signer)).collect();
3546
Self { pending_signers, signers, browser }
@@ -43,12 +54,16 @@ impl MultiWallet {
4354
Ok(())
4455
}
4556

46-
pub fn signers(&mut self) -> Result<(&AddressHashMap<WalletSigner>, Option<&BrowserSigner>)> {
57+
pub fn signers(
58+
&mut self,
59+
) -> Result<(&AddressHashMap<WalletSigner>, Option<&BrowserSigner<N>>)> {
4760
self.maybe_unlock_pending()?;
4861
Ok((&self.signers, self.browser.as_ref()))
4962
}
5063

51-
pub fn into_signers(mut self) -> Result<(AddressHashMap<WalletSigner>, Option<BrowserSigner>)> {
64+
pub fn into_signers(
65+
mut self,
66+
) -> Result<(AddressHashMap<WalletSigner>, Option<BrowserSigner<N>>)> {
5267
self.maybe_unlock_pending()?;
5368
Ok((self.signers, self.browser))
5469
}
@@ -245,7 +260,7 @@ pub struct MultiWalletOpts {
245260

246261
impl MultiWalletOpts {
247262
/// Returns [MultiWallet] container configured with provided options.
248-
pub async fn get_multi_wallet(&self) -> Result<MultiWallet> {
263+
pub async fn get_multi_wallet<N: Network>(&self) -> Result<MultiWallet<N>> {
249264
let mut pending = Vec::new();
250265
let mut signers: Vec<WalletSigner> = Vec::new();
251266
let browser = self.browser_signer().await?;
@@ -502,7 +517,7 @@ impl MultiWalletOpts {
502517
}
503518

504519
/// Launches and returns the Browser signer if `--browser` flag is set
505-
pub async fn browser_signer(&self) -> Result<Option<BrowserSigner>> {
520+
pub async fn browser_signer<N: Network>(&self) -> Result<Option<BrowserSigner<N>>> {
506521
self.browser.run().await
507522
}
508523
}

0 commit comments

Comments
 (0)