Skip to content

Commit

Permalink
Add fee_rate to payjoin-cli
Browse files Browse the repository at this point in the history
    - Add `fee_rate` to `send_payjoin`
    - Set default `fee_rate` to 2.1 sat/vb
  • Loading branch information
jbesraa committed Oct 19, 2023
1 parent b1db4f9 commit 95ab22b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 4 additions & 5 deletions payjoin-cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -57,10 +57,9 @@ impl App {
// wallet_create_funded_psbt requires a HashMap<address: String, Amount>
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);
Expand Down
17 changes: 15 additions & 2 deletions payjoin-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -14,7 +14,14 @@ 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 = match sub_matches.get_one::<f32>("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 =
Expand Down Expand Up @@ -49,6 +56,12 @@ fn cli() -> ArgMatches {
Command::new("send")
.arg_required_else_help(true)
.arg(arg!(<BIP21> "The `bitcoin:...` payjoin uri to send to"))
.arg(
arg!(--fee_rate <VALUE>)
.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"))
Expand Down

0 comments on commit 95ab22b

Please sign in to comment.