Skip to content

Commit

Permalink
fix: Only send ln payment received message to the actual trader
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Jun 5, 2024
1 parent 646d777 commit f379901
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions coordinator/src/node/invoice.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use crate::db;
use crate::message::TraderMessage;
use crate::notifications::NotificationKind;
use bitcoin::Amount;
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Pool;
use diesel::PgConnection;
use futures_util::TryStreamExt;
use lnd_bridge::InvoiceState;
use lnd_bridge::LndBridge;
use tokio::sync::broadcast;
use tokio::sync::mpsc;
use tokio::task::spawn_blocking;
use xxi_node::commons;
use xxi_node::commons::Message;

/// Watches a hodl invoice with the given r_hash
pub fn spawn_invoice_watch(
pool: Pool<ConnectionManager<PgConnection>>,
trader_sender: broadcast::Sender<Message>,
trader_sender: mpsc::Sender<TraderMessage>,
lnd_bridge: LndBridge,
invoice_params: commons::HodlInvoiceParams,
) {
Expand Down Expand Up @@ -77,10 +79,14 @@ pub fn spawn_invoice_watch(
}
InvoiceState::Accepted => {
tracing::info!(%trader_pubkey, r_hash, "Pending hodl invoice has been accepted.");
if let Err(e) = trader_sender.send(Message::LnPaymentReceived {
r_hash: r_hash.clone(),
amount: Amount::from_sat(invoice.amt_paid_sat),
}) {
if let Err(e) = trader_sender.send(TraderMessage {
trader_id: trader_pubkey,
message: Message::LnPaymentReceived {
r_hash: r_hash.clone(),
amount: Amount::from_sat(invoice.amt_paid_sat),
},
notification: Some(NotificationKind::Custom { title: "Open your DLC channel now!".to_string(), message: "Pending payment received, open the app to open your DLC channel.".to_string() }),
}).await {
tracing::error!(%trader_pubkey, r_hash, "Failed to send payment received event to app. Error: {e:#}")
}
continue;
Expand Down
2 changes: 1 addition & 1 deletion coordinator/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ async fn create_invoice(
// watch for the created hodl invoice
invoice::spawn_invoice_watch(
state.pool.clone(),
state.tx_orderbook_feed.clone(),
state.auth_users_notifier.clone(),
state.lnd_bridge.clone(),
invoice_params,
);
Expand Down

0 comments on commit f379901

Please sign in to comment.