Skip to content

Commit 004bf4d

Browse files
committed
feat: add payjoin receive support
1 parent dca57c0 commit 004bf4d

File tree

3 files changed

+671
-1
lines changed

3 files changed

+671
-1
lines changed

src/commands.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,23 @@ pub enum OnlineWalletSubCommand {
430430
)]
431431
tx: Option<String>,
432432
},
433+
// Generates a Payjoin receive URI and processes the sender's Payjoin proposal.
434+
ReceivePayjoin {
435+
/// Amount to be received in sats.
436+
#[arg(env = "PAYJOIN_AMOUNT", long = "amount", required = true)]
437+
amount: u64,
438+
/// Payjoin directory which will be used to store the PSBTs which are pending action
439+
/// from one of the parties.
440+
#[arg(env = "PAYJOIN_DIRECTORY", long = "directory", required = true)]
441+
directory: String,
442+
/// URL of the Payjoin OHTTP relay. Can be repeated multiple times to attempt the
443+
/// operation with multiple relays for redundancy.
444+
#[arg(env = "PAYJOIN_OHTTP_RELAY", long = "ohttp_relay", required = true)]
445+
ohttp_relay: Vec<String>,
446+
/// Maximum effective fee rate the receiver is willing to pay for their own input/output contributions.
447+
#[arg(env = "PAYJOIN_RECEIVER_MAX_FEE_RATE", long = "max_fee_rate")]
448+
max_fee_rate: Option<u64>,
449+
},
433450
/// Sends an original PSBT to a BIP 21 URI and broadcasts the returned Payjoin PSBT.
434451
SendPayjoin {
435452
/// BIP 21 URI for the Payjoin.

src/handlers.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//! Command Handlers
1010
//!
1111
//! This module describes all the command handling logic used by bdk-cli.
12-
1312
use crate::commands::OfflineWalletSubCommand::*;
1413
use crate::commands::*;
1514
use crate::error::BDKCliError as Error;
@@ -715,6 +714,18 @@ pub(crate) async fn handle_online_wallet_subcommand(
715714
let txid = broadcast_transaction(client, tx).await?;
716715
Ok(serde_json::to_string_pretty(&json!({ "txid": txid }))?)
717716
}
717+
ReceivePayjoin {
718+
amount,
719+
directory,
720+
ohttp_relay,
721+
max_fee_rate,
722+
} => {
723+
let relay_manager = Arc::new(Mutex::new(RelayManager::new()));
724+
let mut payjoin_manager = PayjoinManager::new(wallet, relay_manager);
725+
return payjoin_manager
726+
.receive_payjoin(amount, directory, max_fee_rate, ohttp_relay, client)
727+
.await;
728+
}
718729
SendPayjoin {
719730
uri,
720731
ohttp_relay,

0 commit comments

Comments
 (0)