Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Jul 4, 2024
1 parent 0c684a9 commit 6bcd28c
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 257 deletions.
29 changes: 13 additions & 16 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use crate::io::sqlite_store::SqliteStore;
use crate::liquidity::LiquiditySource;
use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
use crate::message_handler::NodeCustomMessageHandler;
use crate::payment::payjoin::handler::PayjoinHandler;
use crate::payment::store::PaymentStore;
use crate::peer_store::PeerStore;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PayjoinSender, PeerManager,
OnionMessenger, PeerManager,
};
use crate::wallet::Wallet;
use crate::{LogLevel, Node};
Expand Down Expand Up @@ -262,10 +263,9 @@ impl NodeBuilder {
}

/// Configures the [`Node`] instance to enable payjoin transactions.
pub fn set_payjoin_config(
&mut self, payjoin_relay: String
) -> Result<&mut Self, BuildError> {
let payjoin_relay = payjoin::Url::parse(&payjoin_relay).map_err(|_| BuildError::InvalidPayjoinConfig)?;
pub fn set_payjoin_config(&mut self, payjoin_relay: String) -> Result<&mut Self, BuildError> {
let payjoin_relay =
payjoin::Url::parse(&payjoin_relay).map_err(|_| BuildError::InvalidPayjoinConfig)?;
self.payjoin_config = Some(PayjoinConfig { payjoin_relay });
Ok(self)
}
Expand Down Expand Up @@ -479,12 +479,8 @@ impl ArcedNodeBuilder {
}

/// Configures the [`Node`] instance to enable payjoin transactions.
pub fn set_payjoin_config(
&self, payjoin_relay: String,
) -> Result<(), BuildError> {
self.inner.write().unwrap().set_payjoin_config(
payjoin_relay,
).map(|_| ())
pub fn set_payjoin_config(&self, payjoin_relay: String) -> Result<(), BuildError> {
self.inner.write().unwrap().set_payjoin_config(payjoin_relay).map(|_| ())
}

/// Configures the [`Node`] instance to source its gossip data from the given RapidGossipSync
Expand Down Expand Up @@ -1003,11 +999,12 @@ fn build_with_store_internal(

let mut payjoin_sender = None;
if let Some(pj_config) = payjoin_config {
payjoin_sender = Some(Arc::new(PayjoinSender::new(
Arc::clone(&logger),
Arc::clone(&wallet),
Arc::clone(&tx_broadcaster),
pj_config.payjoin_relay.clone(),
payjoin_sender = Some(Arc::new(PayjoinHandler::new(
Arc::clone(&logger),
pj_config.payjoin_relay.clone(),
Arc::clone(&tx_sync),
Arc::clone(&event_queue),
Arc::clone(&wallet),
)));
}

Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,9 @@ impl From<lightning_transaction_sync::TxSyncError> for Error {
Self::TxSyncFailed
}
}

impl From<reqwest::Error> for Error {
fn from(_e: reqwest::Error) -> Self {
Self::PayjoinRequestCreationFailed
}
}
42 changes: 35 additions & 7 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use lightning_liquidity::lsps2::utils::compute_opening_fee;

use bitcoin::blockdata::locktime::absolute::LockTime;
use bitcoin::secp256k1::PublicKey;
use bitcoin::OutPoint;
use bitcoin::{OutPoint, ScriptBuf};

use rand::{thread_rng, Rng};

Expand Down Expand Up @@ -143,18 +143,37 @@ pub enum Event {
/// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
reason: Option<ClosureReason>,
},
/// Failed to send Payjoin transaction.
///
/// This event is emitted when our attempt to send Payjoin transaction fail.
PayjoinPaymentPending {
/// Transaction ID of the successfully sent Payjoin transaction.
txid: bitcoin::Txid,
/// docs
amount: u64,
/// docs
receipient: ScriptBuf,
},
/// A Payjoin transaction has been successfully sent.
///
/// This event is emitted when we send a Payjoin transaction and it was accepted by the
/// receiver, and then finalised and broadcasted by us.
PayjoinTxSendSuccess {
PayjoinPaymentSuccess {
/// Transaction ID of the successfully sent Payjoin transaction.
txid: bitcoin::Txid,
/// docs
amount: u64,
/// docs
receipient: ScriptBuf,
},
/// Failed to send Payjoin transaction.
///
/// This event is emitted when our attempt to send Payjoin transaction fail.
PayjoinTxSendFailed {
PayjoinPaymentFailed {
/// docs
amount: u64,
/// docs
receipient: ScriptBuf,
/// Reason for the failure.
reason: String,
},
Expand Down Expand Up @@ -199,12 +218,21 @@ impl_writeable_tlv_based_enum!(Event,
(2, payment_id, required),
(4, claimable_amount_msat, required),
(6, claim_deadline, option),
},
(7, PayjoinTxSendSuccess) => {
},
(7, PayjoinPaymentPending) => {
(0, txid, required),
(2, amount, required),
(4, receipient, required),
},
(8, PayjoinPaymentSuccess) => {
(0, txid, required),
(2, amount, required),
(4, receipient, required),
},
(8, PayjoinTxSendFailed) => {
(0, reason, required),
(9, PayjoinPaymentFailed) => {
(0, amount, required),
(2, receipient, required),
(4, reason, required),
};
);

Expand Down
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ pub mod io;
mod liquidity;
mod logger;
mod message_handler;
mod payjoin_sender;
pub mod payment;
mod peer_store;
mod sweep;
Expand All @@ -110,6 +109,7 @@ pub use error::Error as NodeError;
use error::Error;

pub use event::Event;
use payment::payjoin::handler::PayjoinHandler;
pub use types::ChannelConfig;

pub use io::utils::generate_entropy_mnemonic;
Expand Down Expand Up @@ -141,7 +141,7 @@ use payment::{
use peer_store::{PeerInfo, PeerStore};
use types::{
Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, DynStore, FeeEstimator,
Graph, KeysManager, PayjoinSender, PeerManager, Router, Scorer, Sweeper, Wallet,
Graph, KeysManager, PeerManager, Router, Scorer, Sweeper, Wallet,
};
pub use types::{ChannelDetails, PeerDetails, UserChannelId};

Expand Down Expand Up @@ -189,7 +189,7 @@ pub struct Node {
output_sweeper: Arc<Sweeper>,
peer_manager: Arc<PeerManager>,
connection_manager: Arc<ConnectionManager<Arc<FilesystemLogger>>>,
payjoin_sender: Option<Arc<PayjoinSender>>,
payjoin_sender: Option<Arc<PayjoinHandler>>,
keys_manager: Arc<KeysManager>,
network_graph: Arc<Graph>,
gossip_source: Arc<GossipSource>,
Expand Down Expand Up @@ -1082,6 +1082,9 @@ impl Node {
payjoin_sender.map(Arc::clone),
Arc::clone(&self.config),
Arc::clone(&self.event_queue),
Arc::clone(&self.logger),
Arc::clone(&self.wallet),
Arc::clone(&self.tx_broadcaster),
)
}

Expand All @@ -1099,6 +1102,9 @@ impl Node {
payjoin_sender.map(Arc::clone),
Arc::clone(&self.config),
Arc::clone(&self.event_queue),
Arc::clone(&self.logger),
Arc::clone(&self.wallet),
Arc::clone(&self.tx_broadcaster),
))
}

Expand Down
173 changes: 0 additions & 173 deletions src/payjoin_sender.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/payment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod bolt11;
mod bolt12;
mod onchain;
mod payjoin;
pub(crate) mod payjoin;
mod spontaneous;
pub(crate) mod store;

Expand Down
Loading

0 comments on commit 6bcd28c

Please sign in to comment.