From 05cbb1702be20be57ff8c4a631b1ac0e2e864dbf Mon Sep 17 00:00:00 2001 From: Dario Anongba Varela Date: Fri, 23 Aug 2024 16:20:45 +0200 Subject: [PATCH] fix: sendpay_failure (#119) --- config/default.toml | 4 ++-- src/domains/ln_address/ln_address_service.rs | 8 +++++--- src/infra/lightning/cln/cln_websocket_client.rs | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config/default.toml b/config/default.toml index 4ac0113..84a9dae 100644 --- a/config/default.toml +++ b/config/default.toml @@ -1,7 +1,7 @@ # App invoice_expiry = "12h" domain = "numeraire.tech" -host = "https://swissknife.numeraire.tech" +host = "https://api.numeraire.tech" fee_buffer = 0.02 ln_provider = "breez" auth_provider = "jwt" @@ -33,7 +33,7 @@ retry_delay = "5s" endpoint = "http://localhost:3010" rune = "CHANGE_ME" connect_timeout = "5s" -timeout = "30s" +timeout = "90s" connection_verbose = true accept_invalid_certs = false accept_invalid_hostnames = false diff --git a/src/domains/ln_address/ln_address_service.rs b/src/domains/ln_address/ln_address_service.rs index c3219b7..971bf3d 100644 --- a/src/domains/ln_address/ln_address_service.rs +++ b/src/domains/ln_address/ln_address_service.rs @@ -31,17 +31,19 @@ impl LnAddressUseCases for LnAddressService { async fn register( &self, wallet_id: Uuid, - username: String, + mut username: String, ) -> Result { debug!(%wallet_id, username, "Registering lightning address"); + username = username.to_lowercase(); + if username.len() < MIN_USERNAME_LENGTH || username.len() > MAX_USERNAME_LENGTH { return Err(DataError::Validation("Invalid username length.".to_string()).into()); } // Regex validation for allowed characters - let email_username_re = Regex::new(r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$") - .expect("should not fail as a constant"); + let email_username_re = + Regex::new(r"^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$").expect("should not fail as a constant"); if !email_username_re.is_match(&username) { return Err(DataError::Validation("Invalid username format.".to_string()).into()); } diff --git a/src/infra/lightning/cln/cln_websocket_client.rs b/src/infra/lightning/cln/cln_websocket_client.rs index 095ea92..c3fbfa4 100644 --- a/src/infra/lightning/cln/cln_websocket_client.rs +++ b/src/infra/lightning/cln/cln_websocket_client.rs @@ -122,6 +122,7 @@ fn on_message( if sendpay_success.status != "complete" { warn!( payment_hash = sendpay_success.payment_hash, + status = sendpay_success.status, "Invalid payment status. Expected Complete." ); return; @@ -145,9 +146,11 @@ fn on_message( if sendpay_failure.data.status != "failed" { warn!( payment_hash = sendpay_failure.data.payment_hash, + status = sendpay_failure.data.status, "Invalid payment status. Expected Failed." ); - return; + // We must accept the payment as failed until this is fixed: https://github.com/ElementsProject/lightning/issues/7561 + // return; } if let Err(err) =