diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f79b367e..285c0be37 120000 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1 +1 @@ -/nix/store/v4wkgb0g7safy7b8s1qjfsvgqzjjdvss-pre-commit-config.json \ No newline at end of file +/nix/store/dqzwknkkrd4k0s60rrl86m0xyfqpkcfi-pre-commit-config.json \ No newline at end of file diff --git a/crates/cdk-cli/src/sub_commands/mint.rs b/crates/cdk-cli/src/sub_commands/mint.rs index 4f250f8b6..605da3b6e 100644 --- a/crates/cdk-cli/src/sub_commands/mint.rs +++ b/crates/cdk-cli/src/sub_commands/mint.rs @@ -9,17 +9,15 @@ use cdk::mint_url::MintUrl; use cdk::nuts::{CurrencyUnit, MintQuoteState, PaymentMethod}; use cdk::wallet::multi_mint_wallet::WalletKey; use cdk::wallet::{MultiMintWallet, Wallet}; -use cdk::Amount; use clap::Args; -use serde::{Deserialize, Serialize}; use tokio::time::sleep; -#[derive(Args, Serialize, Deserialize)] +#[derive(Args)] pub struct MintSubCommand { /// Mint url mint_url: MintUrl, /// Amount - amount: u64, + amount: Option, /// Currency unit e.g. sat #[arg(short, long, default_value = "sat")] unit: String, @@ -27,7 +25,6 @@ pub struct MintSubCommand { #[arg(long, default_value = "bolt11")] method: String, /// Quote description - #[serde(skip_serializing_if = "Option::is_none")] description: Option, } @@ -60,12 +57,23 @@ pub async fn mint( PaymentMethod::Bolt11 => { println!("Bolt11"); wallet - .mint_quote(Amount::from(sub_command_args.amount), description) + .mint_quote( + sub_command_args + .amount + .expect("Amount must be defined") + .into(), + description, + ) .await? } PaymentMethod::Bolt12 => { wallet - .mint_bolt12_quote(Amount::from(sub_command_args.amount), description) + .mint_bolt12_quote( + sub_command_args.amount.map(|a| a.into()), + description, + false, + None, + ) .await? } _ => panic!("Unsupported unit"), diff --git a/crates/cdk-redb/src/mint/migrations.rs b/crates/cdk-redb/src/mint/migrations.rs index 0f8101406..4b90e50c5 100644 --- a/crates/cdk-redb/src/mint/migrations.rs +++ b/crates/cdk-redb/src/mint/migrations.rs @@ -176,7 +176,7 @@ impl From for MintQuote { // TODO: Create real migrations amount_paid: Amount::ZERO, amount_issued: Amount::ZERO, - single_use: None, + single_use: true, } } } diff --git a/crates/cdk-sqlite/src/mint/mod.rs b/crates/cdk-sqlite/src/mint/mod.rs index 121d43dde..ce980be6f 100644 --- a/crates/cdk-sqlite/src/mint/mod.rs +++ b/crates/cdk-sqlite/src/mint/mod.rs @@ -1300,7 +1300,7 @@ fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result { // TODO: Get these values amount_paid: Amount::ZERO, amount_issued: Amount::ZERO, - single_use: None, + single_use: true, }) } diff --git a/crates/cdk/src/mint/mint_18.rs b/crates/cdk/src/mint/mint_18.rs index cdc9c8183..ec7a37d0a 100644 --- a/crates/cdk/src/mint/mint_18.rs +++ b/crates/cdk/src/mint/mint_18.rs @@ -52,8 +52,6 @@ impl Mint { return Err(Error::InvoiceDescriptionUnsupported); } - let single_use = single_use.unwrap_or(true); - let create_invoice_response = ln .create_bolt12_offer( amount, @@ -77,7 +75,7 @@ impl Mint { create_invoice_response.request_lookup_id.clone(), Amount::ZERO, Amount::ZERO, - Some(single_use), + single_use, ); tracing::debug!( diff --git a/crates/cdk/src/mint/mint_nut04.rs b/crates/cdk/src/mint/mint_nut04.rs index ce26bce86..7861b30b5 100644 --- a/crates/cdk/src/mint/mint_nut04.rs +++ b/crates/cdk/src/mint/mint_nut04.rs @@ -107,7 +107,7 @@ impl Mint { create_invoice_response.request_lookup_id.clone(), Amount::ZERO, Amount::ZERO, - None, + true, ); tracing::debug!( @@ -237,7 +237,7 @@ impl Mint { request_lookup_id: quote.request_lookup_id, amount_paid, amount_issued: quote.amount_issued, - single_use: None, + single_use: quote.single_use, }; tracing::debug!( @@ -358,7 +358,7 @@ impl Mint { .total_amount() .map_err(|_| Error::AmountOverflow)?, request_lookup_id: quote.request_lookup_id, - single_use: None, + single_use: quote.single_use, }; self.localstore.add_mint_quote(mint_quote).await?; diff --git a/crates/cdk/src/mint/types.rs b/crates/cdk/src/mint/types.rs index d764e2ac3..09ef6357c 100644 --- a/crates/cdk/src/mint/types.rs +++ b/crates/cdk/src/mint/types.rs @@ -30,11 +30,14 @@ pub struct MintQuote { /// Value used by ln backend to look up state of request pub request_lookup_id: String, /// Amount paid + #[serde(default)] pub amount_paid: Amount, /// Amount issued + #[serde(default)] pub amount_issued: Amount, /// Single use - pub single_use: Option, + #[serde(default)] + pub single_use: bool, } impl MintQuote { @@ -49,7 +52,7 @@ impl MintQuote { request_lookup_id: String, amount_paid: Amount, amount_issued: Amount, - single_use: Option, + single_use: bool, ) -> Self { let id = Uuid::new_v4(); diff --git a/crates/cdk/src/nuts/nut19.rs b/crates/cdk/src/nuts/nut19.rs index 992fb0572..a15529005 100644 --- a/crates/cdk/src/nuts/nut19.rs +++ b/crates/cdk/src/nuts/nut19.rs @@ -29,7 +29,7 @@ pub struct MintQuoteBolt12Request { /// Memo to create the invoice with pub description: Option, /// Single use - pub single_use: Option, + pub single_use: bool, /// Expiry pub expiry: Option, } @@ -42,7 +42,7 @@ pub struct MintQuoteBolt12Response { /// Payment request to fulfil pub request: String, /// Single use - pub single_use: Option, + pub single_use: bool, /// Unix timestamp until the quote is valid pub expiry: Option, /// Amount that has been paid diff --git a/crates/cdk/src/wallet/client.rs b/crates/cdk/src/wallet/client.rs index 68659134c..a9d6af927 100644 --- a/crates/cdk/src/wallet/client.rs +++ b/crates/cdk/src/wallet/client.rs @@ -9,7 +9,7 @@ use super::Error; use crate::error::ErrorResponse; use crate::mint_url::MintUrl; use crate::nuts::nut15::Mpp; -use crate::nuts::nut19::MintQuoteBolt12Response; +use crate::nuts::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response}; use crate::nuts::{ BlindedMessage, CheckStateRequest, CheckStateResponse, CurrencyUnit, Id, KeySet, KeysResponse, KeysetResponse, MeltBolt11Request, MeltBolt12Request, MeltQuoteBolt11Request, @@ -145,18 +145,10 @@ impl HttpClient { pub async fn post_mint_bolt12_quote( &self, mint_url: MintUrl, - amount: Amount, - unit: CurrencyUnit, - description: Option, + request: MintQuoteBolt12Request, ) -> Result { let url = mint_url.join_paths(&["v1", "mint", "quote", "bolt12"])?; - let request = MintQuoteBolt11Request { - amount, - unit, - description, - }; - let res = self.inner.post(url).json(&request).send().await?; println!("{:?}", res); diff --git a/crates/cdk/src/wallet/mint_bolt12.rs b/crates/cdk/src/wallet/mint_bolt12.rs index 28f5876de..824214d93 100644 --- a/crates/cdk/src/wallet/mint_bolt12.rs +++ b/crates/cdk/src/wallet/mint_bolt12.rs @@ -2,7 +2,7 @@ use tracing::instrument; use super::MintQuote; use crate::nuts::nut00::ProofsMethods; -use crate::nuts::nut19::MintQuoteBolt12Response; +use crate::nuts::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response}; use crate::nuts::PaymentMethod; use crate::{ amount::SplitTarget, @@ -18,8 +18,10 @@ impl Wallet { #[instrument(skip(self))] pub async fn mint_bolt12_quote( &self, - amount: Amount, + amount: Option, description: Option, + single_use: bool, + expiry: Option, ) -> Result { let mint_url = self.mint_url.clone(); let unit = self.unit; @@ -41,16 +43,24 @@ impl Wallet { } } + let mint_request = MintQuoteBolt12Request { + amount, + unit, + description, + single_use, + expiry, + }; + let quote_res = self .client - .post_mint_bolt12_quote(mint_url.clone(), amount, unit, description) + .post_mint_bolt12_quote(mint_url.clone(), mint_request) .await?; let quote = MintQuote { mint_url, id: quote_res.quote.clone(), payment_method: PaymentMethod::Bolt12, - amount, + amount: amount.unwrap_or(Amount::ZERO), unit, request: quote_res.request, state: crate::nuts::MintQuoteState::Unpaid, diff --git a/flake.lock b/flake.lock index d8d8de915..f03717648 100644 --- a/flake.lock +++ b/flake.lock @@ -57,16 +57,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1730137625, - "narHash": "sha256-9z8oOgFZiaguj+bbi3k4QhAD6JabWrnv7fscC/mt0KE=", + "lastModified": 1730200266, + "narHash": "sha256-l253w0XMT8nWHGXuXqyiIC/bMvh1VRszGXgdpQlfhvU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "64b80bfb316b57cdb8919a9110ef63393d74382a", + "rev": "807e9154dcb16384b1b765ebe9cd2bba2ac287fd", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-24.05", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index b40785577..003ab6982 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "CDK Flake"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; rust-overlay = { url = "github:oxalica/rust-overlay"; @@ -63,7 +63,7 @@ pkg-config curl just - protobuf3_20 + protobuf nixpkgs-fmt rust-analyzer typos