Skip to content

Commit

Permalink
Only apply &ohttp param to v2 URIs (#167)
Browse files Browse the repository at this point in the history
v1 uris otherwise contained blank, dangling params like
`bitcoin:<address>&pj=<pj_endpoint>&ohttp=`
  • Loading branch information
DanGould authored Jan 16, 2024
2 parents 4a9b812 + 9349bd6 commit 3769fff
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions payjoin-cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,15 @@ impl App {
};

let pj_uri_string = format!(
"{}?amount={}&pj={}&ohttp={}",
"{}?amount={}&pj={}",
pj_receiver_address.to_qr_uri(),
amount.to_btc(),
pj_part,
self.config.ohttp_config,
);

#[cfg(feature = "v2")]
let pj_uri_string = format!("{}&ohttp={}", pj_uri_string, self.config.ohttp_config,);

// to check uri validity
let _pj_uri = payjoin::Uri::from_str(&pj_uri_string)
.map_err(|e| anyhow!("Constructed a bad URI string from args: {}", e))?;
Expand Down Expand Up @@ -775,6 +777,7 @@ pub(crate) struct AppConfig {
pub bitcoind_cookie: Option<String>,
pub bitcoind_rpcuser: String,
pub bitcoind_rpcpass: String,
#[cfg(feature = "v2")]
pub ohttp_config: String,
#[cfg(feature = "v2")]
pub ohttp_proxy: String,
Expand Down Expand Up @@ -808,6 +811,14 @@ impl AppConfig {
"bitcoind_rpcpass",
matches.get_one::<String>("rpcpass").map(|s| s.as_str()),
)?
// Subcommand defaults without which file serialization fails.
.set_default("pj_host", "0.0.0.0:3000")?
.set_default("pj_endpoint", "https://localhost:3000")?
.set_default("sub_only", false)?
.add_source(File::new("config.toml", FileFormat::Toml).required(false));

#[cfg(feature = "v2")]
let builder = builder
.set_default("ohttp_config", "")?
.set_override_option(
"ohttp_config",
Expand All @@ -817,12 +828,7 @@ impl AppConfig {
.set_override_option(
"ohttp_proxy",
matches.get_one::<String>("ohttp_proxy").map(|s| s.as_str()),
)?
// Subcommand defaults without which file serialization fails.
.set_default("pj_host", "0.0.0.0:3000")?
.set_default("pj_endpoint", "https://localhost:3000")?
.set_default("sub_only", false)?
.add_source(File::new("config.toml", FileFormat::Toml).required(false));
)?;

let builder = match matches.subcommand() {
Some(("send", _)) => builder,
Expand Down

0 comments on commit 3769fff

Please sign in to comment.