Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Jul 12, 2024
1 parent a839688 commit 8309118
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 258 deletions.
1 change: 0 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ fn build_with_store_internal(
let mut payjoin_receiver = None;
if let Some(pj_config) = payjoin_config {
payjoin_handler = Some(Arc::new(PayjoinHandler::new(
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
pj_config.payjoin_relay.clone(),
Arc::clone(&tx_sync),
Expand Down
3 changes: 3 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub enum PayjoinPaymentFailureReason {
Timeout,
TransactionFinalisationFailed,
InvalidReceiverResponse,
RequestFailed,
}

impl Readable for PayjoinPaymentFailureReason {
Expand All @@ -196,6 +197,7 @@ impl Readable for PayjoinPaymentFailureReason {
0 => Ok(Self::Timeout),
1 => Ok(Self::TransactionFinalisationFailed),
2 => Ok(Self::InvalidReceiverResponse),
3 => Ok(Self::RequestFailed),
_ => Err(DecodeError::InvalidValue),
}
}
Expand All @@ -207,6 +209,7 @@ impl Writeable for PayjoinPaymentFailureReason {
Self::Timeout => 0u8.write(writer),
Self::TransactionFinalisationFailed => 1u8.write(writer),
Self::InvalidReceiverResponse => 2u8.write(writer),
Self::RequestFailed => 3u8.write(writer),
}
}
}
Expand Down
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ impl Node {
let archive_cmon = Arc::clone(&self.chain_monitor);
let sync_sweeper = Arc::clone(&self.output_sweeper);
let sync_logger = Arc::clone(&self.logger);
let sync_payjoin = match &self.payjoin_handler {
Some(pjh) => Some(Arc::clone(pjh)),
None => None,
};
let sync_wallet_timestamp = Arc::clone(&self.latest_wallet_sync_timestamp);
let sync_monitor_archival_height = Arc::clone(&self.latest_channel_monitor_archival_height);
let mut stop_sync = self.stop_sender.subscribe();
Expand All @@ -393,11 +397,14 @@ impl Node {
return;
}
_ = wallet_sync_interval.tick() => {
let confirmables = vec![
let mut confirmables = vec![
&*sync_cman as &(dyn Confirm + Sync + Send),
&*sync_cmon as &(dyn Confirm + Sync + Send),
&*sync_sweeper as &(dyn Confirm + Sync + Send),
];
if let Some(sync_payjoin) = sync_payjoin.as_ref() {
confirmables.push(sync_payjoin.as_ref() as &(dyn Confirm + Sync + Send));
}
let now = Instant::now();
let timeout_fut = tokio::time::timeout(Duration::from_secs(LDK_WALLET_SYNC_TIMEOUT_SECS), tx_sync.sync(confirmables));
match timeout_fut.await {
Expand Down Expand Up @@ -1114,9 +1121,11 @@ impl Node {
Arc::clone(&self.config),
Arc::clone(&self.logger),
Arc::clone(&self.wallet),
Arc::clone(&self.tx_broadcaster),
Arc::clone(&self.peer_store),
Arc::clone(&self.channel_manager),
Arc::clone(&self.connection_manager),
Arc::clone(&self.payment_store),
)
}

Expand All @@ -1132,14 +1141,16 @@ impl Node {
let payjoin_receiver = self.payjoin_receiver.as_ref();
Arc::new(PayjoinPayment::new(
Arc::clone(&self.runtime),
payjoin_sender.map(Arc::clone),
payjoin_handler.map(Arc::clone),
payjoin_receiver.map(Arc::clone),
Arc::clone(&self.config),
Arc::clone(&self.logger),
Arc::clone(&self.wallet),
Arc::clone(&self.tx_broadcaster),
Arc::clone(&self.peer_store),
Arc::clone(&self.channel_manager),
Arc::clone(&self.connection_manager),
Arc::clone(&self.payment_store),
))
}

Expand Down Expand Up @@ -1344,11 +1355,15 @@ impl Node {
let fee_estimator = Arc::clone(&self.fee_estimator);
let sync_sweeper = Arc::clone(&self.output_sweeper);
let sync_logger = Arc::clone(&self.logger);
let confirmables = vec![
let sync_payjoin = &self.payjoin_handler.as_ref();
let mut confirmables = vec![
&*sync_cman as &(dyn Confirm + Sync + Send),
&*sync_cmon as &(dyn Confirm + Sync + Send),
&*sync_sweeper as &(dyn Confirm + Sync + Send),
];
if let Some(sync_payjoin) = sync_payjoin {
confirmables.push(sync_payjoin.as_ref() as &(dyn Confirm + Sync + Send));
}
let sync_wallet_timestamp = Arc::clone(&self.latest_wallet_sync_timestamp);
let sync_fee_rate_update_timestamp =
Arc::clone(&self.latest_fee_rate_cache_update_timestamp);
Expand Down
Loading

0 comments on commit 8309118

Please sign in to comment.