Skip to content

Commit

Permalink
fix: client selects ohttp relay
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 29, 2024
1 parent 6ac7f02 commit 836fe25
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 45 deletions.
33 changes: 12 additions & 21 deletions crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,10 @@ pub async fn get_mint_onchain_quote(
let settings = onchain.get_settings();

let payjoin = match settings.payjoin_settings.receive_enabled {
true => match (settings.payjoin_settings.ohttp_relay, address.payjoin_url) {
(Some(ohttp_relay), Some(payjoin_directory)) => Some(PayjoinInfo {
origin: payjoin_directory,
ohttp_relay: Some(ohttp_relay),
pjos: false,
}),
_ => None,
},
true => address.payjoin_url.map(|payjoin_directory| PayjoinInfo {
origin: payjoin_directory,
pjos: false,
}),
false => None,
};

Expand Down Expand Up @@ -227,19 +223,14 @@ pub async fn get_check_mint_onchain_quote(
let settings = onchain.get_settings();

let payjoin = match settings.payjoin_settings.receive_enabled {
true => {
match (
settings.payjoin_settings.ohttp_relay,
settings.payjoin_settings.payjoin_directory,
) {
(Some(ohttp_relay), Some(payjoin_directory)) => Some(PayjoinInfo {
origin: payjoin_directory,
ohttp_relay: Some(ohttp_relay),
pjos: false,
}),
_ => None,
}
}
true => settings
.payjoin_settings
.payjoin_directory
.map(|payjoin_directory| PayjoinInfo {
origin: payjoin_directory,
pjos: false,
}),

false => None,
};

Expand Down
13 changes: 6 additions & 7 deletions crates/cdk-bdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,17 @@ impl BdkWallet {
// TODO: Making this a payjoin trait
impl BdkWallet {
async fn start_payjoin(&self, address: &str) -> Result<String, Error> {
let ohttp_relay = self
.payjoin_settings
.ohttp_relay
.clone()
.ok_or(anyhow!("ohttp relay required"))?;
let ohttp_relay = self.payjoin_settings.ohttp_relay.clone();

let payjoin_directory = self
.payjoin_settings
.payjoin_directory
.clone()
.ok_or(anyhow!("payjoin directory required"))?;
.ok_or(anyhow!("pajoin directory required"))?;

let ohttp_relay: Url = ohttp_relay.parse()?;
let ohttp_relay: Url = ohttp_relay
.ok_or(anyhow!("Payjoing ohttp relay must be defined"))?
.parse()?;
let payjoin_directory: Url = payjoin_directory.parse()?;

// Fetch keys using HTTP CONNECT method
Expand Down
25 changes: 10 additions & 15 deletions crates/cdk-cli/src/sub_commands/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cdk::wallet::multi_mint_wallet::WalletKey;
use cdk::wallet::{MultiMintWallet, Wallet};
use cdk::Amount;
use clap::Args;
use payjoin::{OhttpKeys, PjUriBuilder};
use payjoin::PjUriBuilder;
use tokio::time::sleep;

#[derive(Args, Debug)]
Expand All @@ -25,6 +25,9 @@ pub struct MintSubCommand {
unit: String,
#[arg(long, default_value = "bolt11")]
method: String,
/// Payjoin relay
#[arg(short, long, default_value = "https://pj.bobspacebkk.com")]
payjoin_relay: String,
}

pub async fn mint(
Expand Down Expand Up @@ -55,7 +58,6 @@ pub async fn mint(
}
};

println!("here");
let quote_id;

match method {
Expand Down Expand Up @@ -87,25 +89,18 @@ pub async fn mint(

match quote.payjoin {
Some(payjoin_info) => {
let ohttp_keys: Option<OhttpKeys> = match payjoin_info.ohttp_relay {
Some(relay) => Some(
payjoin::io::fetch_ohttp_keys(
relay.clone().parse()?,
payjoin_info.origin.parse()?,
)
.await?,
),
None => None,
};

println!("ohttp keys: {:?}", ohttp_keys.clone().unwrap().to_string());
let ohttp_keys = payjoin::io::fetch_ohttp_keys(
sub_command_args.payjoin_relay.parse()?,
payjoin_info.origin.parse()?,
)
.await?;

let address = payjoin::bitcoin::Address::from_str(&quote.address)?;

let uri = PjUriBuilder::new(
address.assume_checked(),
payjoin_info.origin.parse()?,
ohttp_keys,
Some(ohttp_keys),
None,
)
.amount(payjoin::bitcoin::Amount::from_sat(sub_command_args.amount))
Expand Down
2 changes: 0 additions & 2 deletions crates/cdk/src/nuts/nut17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub struct MintQuoteBtcOnchainResponse {
pub struct PayjoinInfo {
/// Origin Directory in v2
pub origin: String,
/// Ohttp keys
pub ohttp_relay: Option<String>,
/// PJO
pub pjos: bool,
}
Expand Down

0 comments on commit 836fe25

Please sign in to comment.