feat: mint-proofs command

fix typo

make output more readable.

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
Ruben
2024-10-12 10:21:20 +02:00
committed by thesimplekid
parent ef3ecce3cf
commit e0f5344e8f
6 changed files with 79 additions and 9 deletions

View File

@@ -70,6 +70,8 @@ enum Commands {
Restore(sub_commands::restore::RestoreSubCommand),
/// Update Mint Url
UpdateMintUrl(sub_commands::update_mint_url::UpdateMintUrlSubCommand),
/// Get proofs from mint.
ListMintProofs,
}
#[tokio::main]
@@ -123,10 +125,10 @@ async fn main() -> Result<()> {
let mut rng = rand::thread_rng();
let random_bytes: [u8; 32] = rng.gen();
let mnemnic = Mnemonic::from_entropy(&random_bytes)?;
let mnemonic = Mnemonic::from_entropy(&random_bytes)?;
tracing::info!("Using randomly generated seed you will not be able to restore");
mnemnic
mnemonic
}
};
@@ -199,5 +201,8 @@ async fn main() -> Result<()> {
sub_commands::update_mint_url::update_mint_url(&multi_mint_wallet, sub_command_args)
.await
}
Commands::ListMintProofs => {
sub_commands::list_mint_proofs::proofs(&multi_mint_wallet).await
}
}
}

View File

@@ -0,0 +1,41 @@
use std::collections::BTreeMap;
use anyhow::Result;
use cdk::{
mint_url::MintUrl,
nuts::{CurrencyUnit, Proof},
wallet::multi_mint_wallet::MultiMintWallet,
};
pub async fn proofs(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
list_proofs(multi_mint_wallet).await?;
Ok(())
}
async fn list_proofs(
multi_mint_wallet: &MultiMintWallet,
) -> 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}");
println!("| Amount | Unit | Secret | DLEQ proof included");
println!("|----------|------|------------------------------------------------------------------|--------------------");
for proof in &proofs.0 {
println!(
"| {:8} | {:4} | {:64} | {}",
proof.amount,
proofs.1,
proof.secret,
proof.dleq.is_some()
);
}
println!();
proofs_vec.push((mint_url, proofs.clone()))
}
Ok(proofs_vec)
}

View File

@@ -2,6 +2,7 @@ pub mod balance;
pub mod burn;
pub mod check_spent;
pub mod decode_token;
pub mod list_mint_proofs;
pub mod melt;
pub mod mint;
pub mod mint_info;