Skip to content

Commit

Permalink
Merge pull request #109 from jbesraa/fee-rate-arg-in-cli
Browse files Browse the repository at this point in the history
Add `fee_rate` argument to `payjoin-cli`
  • Loading branch information
DanGould authored Oct 22, 2023
2 parents c9df020 + 048ec97 commit d1d1a8a
Show file tree
Hide file tree
Showing 2 changed files with 14 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<()> {
let uri = payjoin::Uri::try_from(bip21)
.map_err(|e| anyhow!("Failed to create URI from BIP21: {}", e))?
.assume_checked();
Expand All @@ -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);
Expand Down
12 changes: 10 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,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 =
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit d1d1a8a

Please sign in to comment.