feat: restart minting in cdk-cli with quote id

This commit is contained in:
thesimplekid
2025-02-06 10:46:18 +00:00
parent f2e1940cc7
commit 8f5764aad2
2 changed files with 29 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use anyhow::Result; use anyhow::{anyhow, Result};
use cdk::amount::SplitTarget; use cdk::amount::SplitTarget;
use cdk::cdk_database::{Error, WalletDatabase}; use cdk::cdk_database::{Error, WalletDatabase};
use cdk::mint_url::MintUrl; use cdk::mint_url::MintUrl;
@@ -18,13 +18,16 @@ pub struct MintSubCommand {
/// Mint url /// Mint url
mint_url: MintUrl, mint_url: MintUrl,
/// Amount /// Amount
amount: u64, amount: Option<u64>,
/// Currency unit e.g. sat /// Currency unit e.g. sat
#[arg(default_value = "sat")] #[arg(default_value = "sat")]
unit: String, unit: String,
/// Quote description /// Quote description
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>, description: Option<String>,
/// Quote Id
#[arg(short, long)]
quote_id: Option<String>,
} }
pub async fn mint( pub async fn mint(
@@ -50,9 +53,12 @@ pub async fn mint(
} }
}; };
let quote = wallet let quote_id = match &sub_command_args.quote_id {
.mint_quote(Amount::from(sub_command_args.amount), description) None => {
.await?; 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);
@@ -71,8 +77,12 @@ pub async fn mint(
} }
} }
} }
quote.id
}
Some(quote_id) => quote_id.to_string(),
};
let proofs = wallet.mint(&quote.id, SplitTarget::default(), None).await?; let proofs = wallet.mint(&quote_id, SplitTarget::default(), None).await?;
let receive_amount = proofs.total_amount()?; let receive_amount = proofs.total_amount()?;

View File

@@ -68,7 +68,7 @@
# Nightly used for formatting # Nightly used for formatting
nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
targets = [ "wasm32-unknown-unknown" ]; # wasm targets = [ "wasm32-unknown-unknown" ]; # wasm
extensions = [ "rustfmt" "clippy" "rust-src" ]; extensions = [ "rustfmt" "clippy" "rust-src" "rust-analyzer" ];
}); });