Skip to content

Commit

Permalink
make output more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbabeck committed Oct 11, 2024
1 parent 413a5ca commit 0b112c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
22 changes: 17 additions & 5 deletions crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@ use cdk::{
};

pub async fn proofs(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
list_proofs(multi_mint_wallet, &CurrencyUnit::Sat).await?;
list_proofs(multi_mint_wallet).await?;
Ok(())
}

async fn list_proofs(
multi_mint_wallet: &MultiMintWallet,
unit: &CurrencyUnit,
) -> Result<Vec<(MintUrl, Vec<Proof>)>> {
let wallets_proofs: BTreeMap<MintUrl, Vec<Proof>> = multi_mint_wallet.list_proofs(unit).await?;
) -> Result<Vec<(MintUrl, (Vec<Proof>, CurrencyUnit))>> {
let wallets_proofs: BTreeMap<MintUrl, (Vec<Proof>, CurrencyUnit)> =
multi_mint_wallet.list_proofs().await?;

let mut proofs_vec = Vec::with_capacity(wallets_proofs.len());

for (i, (mint_url, proofs)) in wallets_proofs.iter().enumerate() {
let mint_url = mint_url.clone();
println!("{i}: {mint_url} {:#?}", proofs);
println!("{i}: {mint_url}");
// TODO make this try to format this to a more readable format.
println!("|Amount |Unit\t| Secret\t\t\t\t\t\t\t\t| Dleq proof included(bool)");
for proof in &proofs.0 {
println!(
"|{}\t|{}\t| {}\t| {:#?}",
proof.amount,
proofs.1,
proof.secret,
proof.dleq.is_some()
);
}
println!();
proofs_vec.push((mint_url, proofs.clone()))
}
Ok(proofs_vec)
Expand Down
9 changes: 3 additions & 6 deletions crates/cdk/src/wallet/multi_mint_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,12 @@ impl MultiMintWallet {
#[instrument(skip(self))]
pub async fn list_proofs(
&self,
unit: &CurrencyUnit,
) -> Result<BTreeMap<MintUrl, Vec<Proof>>, Error> {
) -> Result<BTreeMap<MintUrl, (Vec<Proof>, CurrencyUnit)>, Error> {
let mut mint_proofs = BTreeMap::new();

for (WalletKey { mint_url, unit: u }, wallet) in self.wallets.lock().await.iter() {
if unit == u {
let wallet_proofs = wallet.get_proofs().await?;
mint_proofs.insert(mint_url.clone(), wallet_proofs);
}
let wallet_proofs = wallet.get_proofs().await?;
mint_proofs.insert(mint_url.clone(), (wallet_proofs, u.clone()));
}
Ok(mint_proofs)
}
Expand Down

0 comments on commit 0b112c3

Please sign in to comment.