diff --git a/payjoin-cli/src/app.rs b/payjoin-cli/src/app.rs index 3f453773..731e7b8b 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<()> { let uri = payjoin::Uri::try_from(bip21) .map_err(|e| anyhow!("Failed to create URI from BIP21: {}", e))? .assume_checked(); @@ -51,10 +51,9 @@ impl App { // wallet_create_funded_psbt requires a HashMap<address: String, Amount> let mut outputs = HashMap::with_capacity(1); outputs.insert(uri.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..73b008ae 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,9 @@ fn main() -> Result<()> { match matches.subcommand() { Some(("send", sub_matches)) => { let bip21 = sub_matches.get_one::<String>("BIP21").context("Missing BIP21 argument")?; - app.send_payjoin(bip21)?; + let fee_rate_sat_per_vb = + sub_matches.get_one::<f32>("fee_rate").context("Missing fee_rate argument")?; + app.send_payjoin(bip21, fee_rate_sat_per_vb)?; } Some(("receive", sub_matches)) => { let amount = @@ -49,6 +51,12 @@ fn cli() -> ArgMatches { Command::new("send") .arg_required_else_help(true) .arg(arg!(<BIP21> "The `bitcoin:...` payjoin uri to send to")) + .arg_required_else_help(true) + .arg( + arg!(--fee_rate <VALUE>) + .help("Fee rate in 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"))