mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 15:44:50 +01:00
fix: mpp (#523)
This commit is contained in:
@@ -3,7 +3,8 @@ use std::io::Write;
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use cdk::nuts::CurrencyUnit;
|
||||
use cdk::amount::MSAT_IN_SAT;
|
||||
use cdk::nuts::{CurrencyUnit, MeltOptions};
|
||||
use cdk::wallet::multi_mint_wallet::{MultiMintWallet, WalletKey};
|
||||
use cdk::Bolt11Invoice;
|
||||
use clap::Args;
|
||||
@@ -15,6 +16,9 @@ pub struct MeltSubCommand {
|
||||
/// Currency unit e.g. sat
|
||||
#[arg(default_value = "sat")]
|
||||
unit: String,
|
||||
/// Mpp
|
||||
#[arg(short, long)]
|
||||
mpp: bool,
|
||||
}
|
||||
|
||||
pub async fn pay(
|
||||
@@ -52,14 +56,33 @@ pub async fn pay(
|
||||
stdin.read_line(&mut user_input)?;
|
||||
let bolt11 = Bolt11Invoice::from_str(user_input.trim())?;
|
||||
|
||||
if bolt11
|
||||
let mut options: Option<MeltOptions> = None;
|
||||
|
||||
if sub_command_args.mpp {
|
||||
println!("Enter the amount you would like to pay in sats, for a mpp payment.");
|
||||
let mut user_input = String::new();
|
||||
let stdin = io::stdin();
|
||||
io::stdout().flush().unwrap();
|
||||
stdin.read_line(&mut user_input)?;
|
||||
|
||||
let user_amount = user_input.trim_end().parse::<u64>()?;
|
||||
|
||||
if user_amount
|
||||
.gt(&(<cdk::Amount as Into<u64>>::into(mints_amounts[mint_number].1) * MSAT_IN_SAT))
|
||||
{
|
||||
bail!("Not enough funds");
|
||||
}
|
||||
|
||||
options = Some(MeltOptions::new_mpp(user_amount * MSAT_IN_SAT));
|
||||
} else if bolt11
|
||||
.amount_milli_satoshis()
|
||||
.unwrap()
|
||||
.gt(&(<cdk::Amount as Into<u64>>::into(mints_amounts[mint_number].1) * 1000_u64))
|
||||
.gt(&(<cdk::Amount as Into<u64>>::into(mints_amounts[mint_number].1) * MSAT_IN_SAT))
|
||||
{
|
||||
bail!("Not enough funds");
|
||||
}
|
||||
let quote = wallet.melt_quote(bolt11.to_string(), None).await?;
|
||||
|
||||
let quote = wallet.melt_quote(bolt11.to_string(), options).await?;
|
||||
|
||||
println!("{:?}", quote);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user