mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-22 23:25:22 +01:00
feat: restart minting in cdk-cli with quote id
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{anyhow, Result};
|
||||
use cdk::amount::SplitTarget;
|
||||
use cdk::cdk_database::{Error, WalletDatabase};
|
||||
use cdk::mint_url::MintUrl;
|
||||
@@ -18,13 +18,16 @@ pub struct MintSubCommand {
|
||||
/// Mint url
|
||||
mint_url: MintUrl,
|
||||
/// Amount
|
||||
amount: u64,
|
||||
amount: Option<u64>,
|
||||
/// Currency unit e.g. sat
|
||||
#[arg(default_value = "sat")]
|
||||
unit: String,
|
||||
/// Quote description
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<String>,
|
||||
/// Quote Id
|
||||
#[arg(short, long)]
|
||||
quote_id: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn mint(
|
||||
@@ -50,29 +53,36 @@ pub async fn mint(
|
||||
}
|
||||
};
|
||||
|
||||
let quote = wallet
|
||||
.mint_quote(Amount::from(sub_command_args.amount), description)
|
||||
.await?;
|
||||
let quote_id = match &sub_command_args.quote_id {
|
||||
None => {
|
||||
let amount = sub_command_args
|
||||
.amount
|
||||
.ok_or(anyhow!("Amount must be defined"))?;
|
||||
let quote = wallet.mint_quote(Amount::from(amount), description).await?;
|
||||
|
||||
println!("Quote: {:#?}", quote);
|
||||
println!("Quote: {:#?}", quote);
|
||||
|
||||
println!("Please pay: {}", quote.request);
|
||||
println!("Please pay: {}", quote.request);
|
||||
|
||||
let mut subscription = wallet
|
||||
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote
|
||||
.id
|
||||
.clone()]))
|
||||
.await;
|
||||
let mut subscription = wallet
|
||||
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote
|
||||
.id
|
||||
.clone()]))
|
||||
.await;
|
||||
|
||||
while let Some(msg) = subscription.recv().await {
|
||||
if let NotificationPayload::MintQuoteBolt11Response(response) = msg {
|
||||
if response.state == MintQuoteState::Paid {
|
||||
break;
|
||||
while let Some(msg) = subscription.recv().await {
|
||||
if let NotificationPayload::MintQuoteBolt11Response(response) = msg {
|
||||
if response.state == MintQuoteState::Paid {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
quote.id
|
||||
}
|
||||
}
|
||||
Some(quote_id) => quote_id.to_string(),
|
||||
};
|
||||
|
||||
let proofs = wallet.mint("e.id, SplitTarget::default(), None).await?;
|
||||
let proofs = wallet.mint("e_id, SplitTarget::default(), None).await?;
|
||||
|
||||
let receive_amount = proofs.total_amount()?;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
# Nightly used for formatting
|
||||
nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
|
||||
targets = [ "wasm32-unknown-unknown" ]; # wasm
|
||||
extensions = [ "rustfmt" "clippy" "rust-src" ];
|
||||
extensions = [ "rustfmt" "clippy" "rust-src" "rust-analyzer" ];
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user