From 3ced965e9601e5b87bb3babaa63708fe1e24f1a7 Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Tue, 7 May 2024 13:26:32 -0500 Subject: [PATCH] Allow from federation for sweeps --- mutiny-core/src/lib.rs | 6 +++--- mutiny-wasm/src/lib.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 52a209518..2e57ba978 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -1590,16 +1590,16 @@ impl MutinyWallet { pub async fn sweep_federation_balance( &self, amount: Option, + from_federation_id: Option, ) -> Result { - // TODO support more than one federation let federation_ids = self.list_federation_ids().await?; if federation_ids.is_empty() { return Err(MutinyError::NotFound); } - let federation_id = &federation_ids[0]; + let federation_id = from_federation_id.unwrap_or(federation_ids[0]); let federation_lock = self.federations.read().await; let fedimint_client = federation_lock - .get(federation_id) + .get(&federation_id) .ok_or(MutinyError::NotFound)?; let labels = vec![SWAP_LABEL.to_string()]; diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index 635726442..db5d1aa16 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -1059,8 +1059,20 @@ impl MutinyWallet { pub async fn sweep_federation_balance( &self, amount: Option, + from_federation_id: Option, ) -> Result { - Ok(self.inner.sweep_federation_balance(amount).await?.into()) + let from_federation_id = match from_federation_id { + Some(f) => { + Some(FederationId::from_str(&f).map_err(|_| MutinyJsError::InvalidArgumentsError)?) + } + None => None, + }; + + Ok(self + .inner + .sweep_federation_balance(amount, from_federation_id) + .await? + .into()) } /// Estimate the fee before trying to sweep from federation