burn.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. use std::str::FromStr;
  2. use anyhow::Result;
  3. use cdk::mint_url::MintUrl;
  4. use cdk::nuts::CurrencyUnit;
  5. use cdk::wallet::types::WalletKey;
  6. use cdk::wallet::MultiMintWallet;
  7. use cdk::Amount;
  8. use clap::Args;
  9. #[derive(Args)]
  10. pub struct BurnSubCommand {
  11. /// Mint Url
  12. mint_url: Option<MintUrl>,
  13. /// Currency unit e.g. sat
  14. #[arg(default_value = "sat")]
  15. unit: String,
  16. }
  17. pub async fn burn(
  18. multi_mint_wallet: &MultiMintWallet,
  19. sub_command_args: &BurnSubCommand,
  20. ) -> Result<()> {
  21. let mut total_burnt = Amount::ZERO;
  22. let unit = CurrencyUnit::from_str(&sub_command_args.unit)?;
  23. match &sub_command_args.mint_url {
  24. Some(mint_url) => {
  25. let wallet = multi_mint_wallet
  26. .get_wallet(&WalletKey::new(mint_url.clone(), unit))
  27. .await
  28. .unwrap();
  29. total_burnt = wallet.check_all_pending_proofs().await?;
  30. }
  31. None => {
  32. for wallet in multi_mint_wallet.get_wallets().await {
  33. let amount_burnt = wallet.check_all_pending_proofs().await?;
  34. total_burnt += amount_burnt;
  35. }
  36. }
  37. }
  38. println!("{total_burnt} burned");
  39. Ok(())
  40. }