diff --git a/payjoin-cli/src/app.rs b/payjoin-cli/src/app.rs index dd786c37..5ba12c30 100644 --- a/payjoin-cli/src/app.rs +++ b/payjoin-cli/src/app.rs @@ -41,7 +41,7 @@ impl App { Ok(Self { config, bitcoind, seen_inputs }) } - pub fn send_payjoin(&self, bip21: &str) -> Result<()> { + pub fn send_payjoin(&self, bip21: &str, fee_rate: &f32) -> Result<()> { use payjoin::send::Configuration; let link = payjoin::Uri::try_from(bip21) @@ -57,10 +57,9 @@ impl App { // wallet_create_funded_psbt requires a HashMap let mut outputs = HashMap::with_capacity(1); outputs.insert(link.address.to_string(), amount); - - // TODO: make payjoin-cli send feerate configurable - // 2.1 sat/vB == 525 sat/kwu for testing purposes. - let fee_rate = bitcoin::FeeRate::from_sat_per_kwu(525); + let fee_rate_sat_per_kwu = fee_rate * 250.0_f32; + let fee_rate: bitcoin::FeeRate = + bitcoin::FeeRate::from_sat_per_kwu(fee_rate_sat_per_kwu.ceil() as u64); let fee_sat_per_kvb = fee_rate.to_sat_per_kwu().checked_mul(4).ok_or(anyhow!("Invalid fee rate"))?; let fee_per_kvb = Amount::from_sat(fee_sat_per_kvb); diff --git a/payjoin-cli/src/main.rs b/payjoin-cli/src/main.rs index d547235f..5cb8b81d 100644 --- a/payjoin-cli/src/main.rs +++ b/payjoin-cli/src/main.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use clap::{arg, Arg, ArgMatches, Command}; +use clap::{arg, value_parser, Arg, ArgMatches, Command}; mod app; use app::{App, AppConfig}; @@ -14,7 +14,14 @@ fn main() -> Result<()> { match matches.subcommand() { Some(("send", sub_matches)) => { let bip21 = sub_matches.get_one::("BIP21").context("Missing BIP21 argument")?; - app.send_payjoin(bip21)?; + let fee_rate_sat_per_vb = match sub_matches.get_one::("fee_rate") { + Some(fee_rate) => fee_rate, + None => { + log::info!("No fee rate specified, using default of 2.1 sat/vB"); + &2.1 + } + }; + app.send_payjoin(bip21, fee_rate_sat_per_vb)?; } Some(("receive", sub_matches)) => { let amount = @@ -49,6 +56,12 @@ fn cli() -> ArgMatches { Command::new("send") .arg_required_else_help(true) .arg(arg!( "The `bitcoin:...` payjoin uri to send to")) + .arg( + arg!(--fee_rate ) + .required(false) + .help("Fee rate in sat/vB - default is 2.1 sat/vB") + .value_parser(value_parser!(f32)), + ) .arg(Arg::new("DANGER_ACCEPT_INVALID_CERTS") .hide(true) .help("Wicked dangerous! Vulnerable to MITM attacks! Accept invalid certs for the payjoin endpoint"))