list_mint_proofs.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. use anyhow::Result;
  2. use cdk::mint_url::MintUrl;
  3. use cdk::nuts::{CurrencyUnit, Proof};
  4. use cdk::wallet::multi_mint_wallet::MultiMintWallet;
  5. pub async fn proofs(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
  6. list_proofs(multi_mint_wallet).await?;
  7. Ok(())
  8. }
  9. async fn list_proofs(
  10. multi_mint_wallet: &MultiMintWallet,
  11. ) -> Result<Vec<(MintUrl, (Vec<Proof>, CurrencyUnit))>> {
  12. let mut proofs_vec = Vec::new();
  13. let wallets = multi_mint_wallet.get_wallets().await;
  14. for (i, wallet) in wallets.iter().enumerate() {
  15. let mint_url = wallet.mint_url.clone();
  16. println!("{i}: {mint_url}");
  17. println!("| Amount | Unit | State | Secret | DLEQ proof included");
  18. println!("|----------|------|----------|------------------------------------------------------------------|--------------------");
  19. // Unspent proofs
  20. let unspent_proofs = wallet.get_unspent_proofs().await?;
  21. for proof in unspent_proofs.iter() {
  22. println!(
  23. "| {:8} | {:4} | {:8} | {:64} | {}",
  24. proof.amount,
  25. wallet.unit,
  26. "unspent",
  27. proof.secret,
  28. proof.dleq.is_some()
  29. );
  30. }
  31. // Pending proofs
  32. let pending_proofs = wallet.get_pending_proofs().await?;
  33. for proof in pending_proofs {
  34. println!(
  35. "| {:8} | {:4} | {:8} | {:64} | {}",
  36. proof.amount,
  37. wallet.unit,
  38. "pending",
  39. proof.secret,
  40. proof.dleq.is_some()
  41. );
  42. }
  43. // Reserved proofs
  44. let reserved_proofs = wallet.get_reserved_proofs().await?;
  45. for proof in reserved_proofs {
  46. println!(
  47. "| {:8} | {:4} | {:8} | {:64} | {}",
  48. proof.amount,
  49. wallet.unit,
  50. "reserved",
  51. proof.secret,
  52. proof.dleq.is_some()
  53. );
  54. }
  55. println!();
  56. proofs_vec.push((mint_url, (unspent_proofs, wallet.unit.clone())));
  57. }
  58. Ok(proofs_vec)
  59. }