From f3799013352ed6774770aaf067883008609d0d6e Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Wed, 5 Jun 2024 08:42:01 +0200 Subject: [PATCH] fix: Only send ln payment received message to the actual trader --- coordinator/src/node/invoice.rs | 18 ++++++++++++------ coordinator/src/routes.rs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/coordinator/src/node/invoice.rs b/coordinator/src/node/invoice.rs index 2b404504d..a2705f197 100644 --- a/coordinator/src/node/invoice.rs +++ b/coordinator/src/node/invoice.rs @@ -1,4 +1,6 @@ use crate::db; +use crate::message::TraderMessage; +use crate::notifications::NotificationKind; use bitcoin::Amount; use diesel::r2d2::ConnectionManager; use diesel::r2d2::Pool; @@ -6,7 +8,7 @@ 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; @@ -14,7 +16,7 @@ use xxi_node::commons::Message; /// Watches a hodl invoice with the given r_hash pub fn spawn_invoice_watch( pool: Pool>, - trader_sender: broadcast::Sender, + trader_sender: mpsc::Sender, lnd_bridge: LndBridge, invoice_params: commons::HodlInvoiceParams, ) { @@ -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; diff --git a/coordinator/src/routes.rs b/coordinator/src/routes.rs index 3492f94b3..1b968ae90 100644 --- a/coordinator/src/routes.rs +++ b/coordinator/src/routes.rs @@ -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, );