Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fee_rate argument to payjoin-cli #109

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading