|
@@ -180,7 +180,7 @@ pub struct MultiMintWallet {
|
|
|
/// The currency unit this wallet supports
|
|
/// The currency unit this wallet supports
|
|
|
unit: CurrencyUnit,
|
|
unit: CurrencyUnit,
|
|
|
/// Wallets indexed by mint URL
|
|
/// Wallets indexed by mint URL
|
|
|
- wallets: Arc<RwLock<BTreeMap<MintUrl, Wallet>>>,
|
|
|
|
|
|
|
+ wallets: Arc<RwLock<BTreeMap<MintUrl, Arc<Wallet>>>>,
|
|
|
/// Proxy configuration for HTTP clients (optional)
|
|
/// Proxy configuration for HTTP clients (optional)
|
|
|
proxy_config: Option<url::Url>,
|
|
proxy_config: Option<url::Url>,
|
|
|
/// Shared Tor transport to be cloned into each TorHttpClient (if enabled)
|
|
/// Shared Tor transport to be cloned into each TorHttpClient (if enabled)
|
|
@@ -293,8 +293,7 @@ impl MultiMintWallet {
|
|
|
.await?;
|
|
.await?;
|
|
|
|
|
|
|
|
// Insert into wallets map
|
|
// Insert into wallets map
|
|
|
- let mut wallets = self.wallets.write().await;
|
|
|
|
|
- wallets.insert(mint_url, wallet);
|
|
|
|
|
|
|
+ self.wallets.write().await.insert(mint_url, wallet.into());
|
|
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
@@ -315,8 +314,7 @@ impl MultiMintWallet {
|
|
|
.await?;
|
|
.await?;
|
|
|
|
|
|
|
|
// Insert into wallets map
|
|
// Insert into wallets map
|
|
|
- let mut wallets = self.wallets.write().await;
|
|
|
|
|
- wallets.insert(mint_url, wallet);
|
|
|
|
|
|
|
+ self.wallets.write().await.insert(mint_url, wallet.into());
|
|
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
@@ -332,31 +330,33 @@ impl MultiMintWallet {
|
|
|
config: WalletConfig,
|
|
config: WalletConfig,
|
|
|
) -> Result<(), Error> {
|
|
) -> Result<(), Error> {
|
|
|
// Check if wallet already exists
|
|
// Check if wallet already exists
|
|
|
- if self.has_mint(&mint_url).await {
|
|
|
|
|
- // Update existing wallet in place
|
|
|
|
|
- let mut wallets = self.wallets.write().await;
|
|
|
|
|
- if let Some(wallet) = wallets.get_mut(&mint_url) {
|
|
|
|
|
- // Update target_proof_count if provided
|
|
|
|
|
- if let Some(count) = config.target_proof_count {
|
|
|
|
|
- wallet.set_target_proof_count(count);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Update existing wallet in place
|
|
|
|
|
+ let mut wallets = self.wallets.write().await;
|
|
|
|
|
+ if let Some(wallet) = wallets.remove(&mint_url) {
|
|
|
|
|
+ let mut wallet = Wallet::new_as(&wallet);
|
|
|
|
|
+ // Update target_proof_count if provided
|
|
|
|
|
+ if let Some(count) = config.target_proof_count {
|
|
|
|
|
+ wallet.set_target_proof_count(count);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Update connector if provided
|
|
|
|
|
- if let Some(connector) = config.mint_connector {
|
|
|
|
|
- wallet.set_client(connector);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Update connector if provided
|
|
|
|
|
+ if let Some(connector) = config.mint_connector {
|
|
|
|
|
+ wallet.set_client(connector);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // TODO: Handle auth_connector if provided
|
|
|
|
|
- #[cfg(feature = "auth")]
|
|
|
|
|
- if let Some(_auth_connector) = config.auth_connector {
|
|
|
|
|
- // For now, we can't easily inject auth_connector into the wallet
|
|
|
|
|
- // This would require additional work on the Wallet API
|
|
|
|
|
- // We'll note this as a future enhancement
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // TODO: Handle auth_connector if provided
|
|
|
|
|
+ #[cfg(feature = "auth")]
|
|
|
|
|
+ if let Some(_auth_connector) = config.auth_connector {
|
|
|
|
|
+ // For now, we can't easily inject auth_connector into the wallet
|
|
|
|
|
+ // This would require additional work on the Wallet API
|
|
|
|
|
+ // We'll note this as a future enhancement
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ wallets.insert(mint_url, wallet.into());
|
|
|
|
|
+
|
|
|
Ok(())
|
|
Ok(())
|
|
|
} else {
|
|
} else {
|
|
|
- // Wallet doesn't exist, create it with the provided config
|
|
|
|
|
|
|
+ drop(wallets);
|
|
|
self.add_mint_with_config(mint_url, config).await
|
|
self.add_mint_with_config(mint_url, config).await
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -763,9 +763,12 @@ impl MultiMintWallet {
|
|
|
) -> Result<PreparedSend, Error> {
|
|
) -> Result<PreparedSend, Error> {
|
|
|
// Ensure the mint exists
|
|
// Ensure the mint exists
|
|
|
let wallets = self.wallets.read().await;
|
|
let wallets = self.wallets.read().await;
|
|
|
- let target_wallet = wallets.get(&mint_url).ok_or(Error::UnknownMint {
|
|
|
|
|
- mint_url: mint_url.to_string(),
|
|
|
|
|
- })?;
|
|
|
|
|
|
|
+ let target_wallet = wallets
|
|
|
|
|
+ .get(&mint_url)
|
|
|
|
|
+ .ok_or(Error::UnknownMint {
|
|
|
|
|
+ mint_url: mint_url.to_string(),
|
|
|
|
|
+ })?
|
|
|
|
|
+ .clone();
|
|
|
|
|
|
|
|
// Check current balance of target mint
|
|
// Check current balance of target mint
|
|
|
let target_balance = target_wallet.total_balance().await?;
|
|
let target_balance = target_wallet.total_balance().await?;
|
|
@@ -830,9 +833,12 @@ impl MultiMintWallet {
|
|
|
|
|
|
|
|
// Now prepare the send from the target mint
|
|
// Now prepare the send from the target mint
|
|
|
let wallets = self.wallets.read().await;
|
|
let wallets = self.wallets.read().await;
|
|
|
- let target_wallet = wallets.get(&mint_url).ok_or(Error::UnknownMint {
|
|
|
|
|
- mint_url: mint_url.to_string(),
|
|
|
|
|
- })?;
|
|
|
|
|
|
|
+ let target_wallet = wallets
|
|
|
|
|
+ .get(&mint_url)
|
|
|
|
|
+ .ok_or(Error::UnknownMint {
|
|
|
|
|
+ mint_url: mint_url.to_string(),
|
|
|
|
|
+ })?
|
|
|
|
|
+ .clone();
|
|
|
|
|
|
|
|
target_wallet.prepare_send(amount, opts.send_options).await
|
|
target_wallet.prepare_send(amount, opts.send_options).await
|
|
|
}
|
|
}
|