Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Scan for fedimint ecash
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Jan 26, 2024
1 parent 974cdda commit e86fd7f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mutiny-core/src/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,17 @@ impl<S: MutinyStorage> FederationClient<S> {
pub async fn delete_fedimint_storage(&self) -> Result<(), MutinyError> {
self.fedimint_storage.delete_store().await
}

pub async fn recover_backup(&self) -> Result<(), MutinyError> {
self.fedimint_client
.restore_from_backup(None)
.await
.map_err(|e| {
log_error!(self.logger, "Could not restore from backup: {}", e);
e
})?;
Ok(())
}
}

// A federation private key will be derived from
Expand Down
17 changes: 17 additions & 0 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,23 @@ impl<S: MutinyStorage> MutinyWallet<S> {
Ok(())
}

pub async fn recover_federation_backups(&self) -> Result<(), MutinyError> {
let federation_ids = self.list_federation_ids().await?;

let federations = self.federations.read().await;
for fed_id in federation_ids {
federations
.get(&fed_id)
.ok_or(MutinyError::NotFound)?
.recover_backup()
.await?;

log_info!(self.logger, "Scanned federation backups: {}", fed_id);
}

Ok(())
}

pub async fn get_total_federation_balance(&self) -> Result<u64, MutinyError> {
let federation_ids = self.list_federation_ids().await?;
let mut total_balance = 0;
Expand Down
8 changes: 8 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,14 @@ impl MutinyWallet {
Ok(self.inner.get_federation_balances().await?.into())
}

/// Scans all federations for user ecash.
///
/// This can be useful if you think you have some federation funds missing.
#[wasm_bindgen]
pub async fn recover_federation_backups(&mut self) -> Result<(), MutinyJsError> {
Ok(self.inner.recover_federation_backups().await?)
}

pub fn get_address_labels(
&self,
) -> Result<JsValue /* Map<Address, Vec<String>> */, MutinyJsError> {
Expand Down

0 comments on commit e86fd7f

Please sign in to comment.