This commit is contained in:
thesimplekid
2025-01-05 14:42:44 +00:00
committed by GitHub
parent d6b7d49ea9
commit 6a8a5a7941
27 changed files with 222 additions and 145 deletions

View File

@@ -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);