mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 15:44:50 +01:00
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:
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user