Skip to content

Commit 1cff930

Browse files
Merge pull request #1146 from getlipa/feature/prevent-payments-sent-to-disabled-addresses
Prevent payments sent to disabled addresses
2 parents abc159f + c591a2e commit 1cff930

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/notification_handling.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::exchange_rate_provider::{ExchangeRateProvider, ExchangeRateProviderIm
1010
use crate::logger::init_logger_once;
1111
use crate::util::LogIgnoreError;
1212
use crate::{
13-
enable_backtrace, register_webhook_url, sanitize_input, start_sdk, Config, RuntimeErrorCode,
14-
UserPreferences, DB_FILENAME, LOGS_DIR,
13+
enable_backtrace, register_webhook_url, sanitize_input, start_sdk, Config, EnableStatus,
14+
RuntimeErrorCode, UserPreferences, DB_FILENAME, LOGS_DIR,
1515
};
1616
use breez_sdk_core::{
1717
BreezEvent, BreezServices, EventListener, InvoicePaidDetails, OpenChannelFeeRequest, Payment,
@@ -306,6 +306,29 @@ fn handle_lnurl_pay_request_notification(
306306
"Failed to query open channel fees",
307307
)?;
308308

309+
// Prevent payments sent to disabled address from being received
310+
let db_path = format!("{}/{DB_FILENAME}", config.local_persistence_path);
311+
let mut data_store = DataStore::new(&db_path)
312+
.map_runtime_error_using(NotificationHandlingErrorCode::from_runtime_error)?;
313+
match data_store
314+
.retrieve_lightning_addresses()
315+
.map_runtime_error_using(NotificationHandlingErrorCode::from_runtime_error)?
316+
.iter()
317+
.find(|(a, _)| data.recipient == *a)
318+
{
319+
None => {
320+
permanent_failure!(
321+
"Received LNURL Pay request notification for unrecognized address/phone number"
322+
)
323+
}
324+
Some((_, EnableStatus::FeatureDisabled)) => {
325+
permanent_failure!(
326+
"Received LNURL Pay request notification for disabled address/phone number feature"
327+
)
328+
}
329+
Some((_, EnableStatus::Enabled)) => {}
330+
}
331+
309332
let strong_typed_seed = get_strong_typed_seed(&config)?;
310333
let environment = get_environment(&config)?;
311334

@@ -370,9 +393,6 @@ fn handle_lnurl_pay_request_notification(
370393
"Failed to get exchange rates",
371394
)?;
372395

373-
let db_path = format!("{}/{DB_FILENAME}", config.local_persistence_path);
374-
let mut data_store = DataStore::new(&db_path)
375-
.map_runtime_error_using(NotificationHandlingErrorCode::from_runtime_error)?;
376396
data_store
377397
.store_payment_info(
378398
&receive_payment_result.ln_invoice.payment_hash,

0 commit comments

Comments
 (0)