Introduce Future Streams for Payments and Minting Proofs (#985)

* Introduce Future Streams for Payments and Minting Proofs

Introduce Future Streams (`ProofStream`, `PaymentStream`) for Payments and
Proofs, an easier to use interface, async friendly, to interact for the mint
waiting for payments of mints for Bolt11 and Bolt12.

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
This commit is contained in:
C
2025-08-26 07:57:15 -03:00
committed by GitHub
parent 4de5566451
commit 218b39a670
21 changed files with 988 additions and 442 deletions

View File

@@ -1,5 +1,4 @@
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, Result};
use cdk::amount::SplitTarget;
@@ -7,7 +6,7 @@ use cdk::mint_url::MintUrl;
use cdk::nuts::nut00::ProofsMethods;
use cdk::nuts::{CurrencyUnit, PaymentMethod};
use cdk::wallet::MultiMintWallet;
use cdk::Amount;
use cdk::{Amount, StreamExt};
use clap::Args;
use serde::{Deserialize, Serialize};
@@ -96,26 +95,17 @@ pub async fn mint(
let mut amount_minted = Amount::ZERO;
loop {
let proofs = wallet
.wait_and_mint_quote(
quote.clone(),
SplitTarget::default(),
None,
Duration::from_secs(sub_command_args.wait_duration),
)
.await?;
let mut proof_streams = wallet.proof_stream(quote, SplitTarget::default(), None);
while let Some(proofs) = proof_streams.next().await {
let proofs = match proofs {
Ok(proofs) => proofs,
Err(err) => {
tracing::error!("Proof streams ended with {:?}", err);
break;
}
};
amount_minted += proofs.total_amount()?;
if sub_command_args.quote_id.is_none() || quote.payment_method == PaymentMethod::Bolt11 {
break;
} else {
println!(
"Minted {} waiting for next payment.",
proofs.total_amount()?
);
}
}
println!("Received {amount_minted} from mint {mint_url}");