99
1010//! Client implementation for LSPS5 webhook registration
1111
12+ use crate :: alloc:: string:: ToString ;
1213use crate :: events:: EventQueue ;
1314use crate :: lsps0:: ser:: { LSPSDateTime , LSPSMessage , LSPSProtocolMessageHandler , LSPSRequestId } ;
1415use crate :: lsps5:: event:: LSPS5ClientEvent ;
@@ -17,27 +18,25 @@ use crate::lsps5::msgs::{
1718 SetWebhookRequest , WebhookNotification ,
1819} ;
1920use crate :: message_queue:: MessageQueue ;
20-
21- use bitcoin:: secp256k1:: PublicKey ;
22- use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
23- use lightning:: util:: message_signing;
24-
25- use crate :: sync:: { Arc , Mutex , RwLock } ;
26- use core:: ops:: Deref ;
27- use core:: time:: Duration ;
28-
29- use crate :: alloc:: string:: ToString ;
3021use crate :: prelude:: { new_hash_map, HashMap } ;
31- use alloc:: string:: String ;
22+ use crate :: sync:: { Arc , Mutex , RwLock } ;
23+ use crate :: utils:: generate_request_id;
3224
3325use super :: msgs:: { LSPS5AppName , LSPS5WebhookUrl } ;
3426#[ cfg( feature = "time" ) ]
3527use super :: service:: DefaultTimeProvider ;
3628use super :: service:: TimeProvider ;
37- use crate :: utils :: generate_request_id ;
29+
3830use alloc:: collections:: VecDeque ;
31+ use alloc:: string:: String ;
32+ use bitcoin:: secp256k1:: PublicKey ;
33+ use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
3934use lightning:: sign:: EntropySource ;
4035use lightning:: util:: logger:: Level ;
36+ use lightning:: util:: message_signing;
37+
38+ use core:: ops:: Deref ;
39+ use core:: time:: Duration ;
4140
4241/// Default maximum age in seconds for cached responses (1 hour)
4342pub const DEFAULT_RESPONSE_MAX_AGE_SECS : u64 = 3600 ;
@@ -226,14 +225,13 @@ where
226225 pub fn set_webhook (
227226 & self , counterparty_node_id : PublicKey , app_name : String , webhook_url : String ,
228227 ) -> Result < LSPSRequestId , LightningError > {
229- let app_name = LSPS5AppName :: new ( app_name) . map_err ( |e| LightningError {
230- err : e. message ,
228+ let app_name = LSPS5AppName :: from_string ( app_name) . map_err ( |e| LightningError {
229+ err : e. message ( ) ,
231230 action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
232231 } ) ?;
233232
234- let lsps_webhook_url = LSPS5WebhookUrl :: new ( webhook_url) . map_err ( |e| LightningError {
235- err : e. message ,
236- action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
233+ let lsps_webhook_url = LSPS5WebhookUrl :: from_string ( webhook_url) . map_err ( |e| {
234+ LightningError { err : e. message ( ) , action : ErrorAction :: IgnoreAndLog ( Level :: Error ) }
237235 } ) ?;
238236
239237 let request_id = generate_request_id ( & self . entropy_source ) ;
@@ -304,8 +302,8 @@ where
304302 pub fn remove_webhook (
305303 & self , counterparty_node_id : PublicKey , app_name : String ,
306304 ) -> Result < LSPSRequestId , LightningError > {
307- let app_name = LSPS5AppName :: new ( app_name) . map_err ( |e| LightningError {
308- err : e. message ,
305+ let app_name = LSPS5AppName :: from_string ( app_name) . map_err ( |e| LightningError {
306+ err : e. message ( ) ,
309307 action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
310308 } ) ?;
311309
@@ -361,8 +359,7 @@ where
361359 self . pending_events . enqueue (
362360 LSPS5ClientEvent :: WebhookRegistrationFailed {
363361 counterparty_node_id : * counterparty_node_id,
364- error_code : error. code ,
365- error_message : error. message ,
362+ error,
366363 app_name,
367364 url : webhook_url,
368365 request_id,
@@ -396,8 +393,7 @@ where
396393 LSPS5Response :: ListWebhooksError ( error) => {
397394 self . pending_events . enqueue ( LSPS5ClientEvent :: WebhooksListFailed {
398395 counterparty_node_id : * counterparty_node_id,
399- error_code : error. code ,
400- error_message : error. message ,
396+ error,
401397 request_id,
402398 } ) ;
403399 result = Ok ( ( ) ) ;
@@ -426,8 +422,7 @@ where
426422 self . pending_events . enqueue (
427423 LSPS5ClientEvent :: WebhookRemovalFailed {
428424 counterparty_node_id : * counterparty_node_id,
429- error_code : error. code ,
430- error_message : error. message ,
425+ error,
431426 app_name,
432427 request_id,
433428 } ,
@@ -686,8 +681,8 @@ mod tests {
686681 let ( client, _, _, peer, _) = setup_test_client ( ) ;
687682 const APP_NAME : & str = "test-app" ;
688683 const WEBHOOK_URL : & str = "https://example.com/hook" ;
689- let lsps5_app_name = LSPS5AppName :: new ( APP_NAME . to_string ( ) ) . unwrap ( ) ;
690- let lsps5_webhook_url = LSPS5WebhookUrl :: new ( WEBHOOK_URL . to_string ( ) ) . unwrap ( ) ;
684+ let lsps5_app_name = LSPS5AppName :: from_string ( APP_NAME . to_string ( ) ) . unwrap ( ) ;
685+ let lsps5_webhook_url = LSPS5WebhookUrl :: from_string ( WEBHOOK_URL . to_string ( ) ) . unwrap ( ) ;
691686 let set_req_id =
692687 client. set_webhook ( peer, APP_NAME . to_string ( ) , WEBHOOK_URL . to_string ( ) ) . unwrap ( ) ;
693688 let list_req_id = client. list_webhooks ( peer) . unwrap ( ) ;
@@ -751,9 +746,9 @@ mod tests {
751746 const OLD_APP_NAME : & str = "test-app-old" ;
752747 const NEW_APP_NAME : & str = "test-app-new" ;
753748 const WEBHOOK_URL : & str = "https://example.com/hook" ;
754- let lsps5_old_app_name = LSPS5AppName :: new ( OLD_APP_NAME . to_string ( ) ) . unwrap ( ) ;
755- let lsps5_new_app_name = LSPS5AppName :: new ( NEW_APP_NAME . to_string ( ) ) . unwrap ( ) ;
756- let lsps5_webhook_url = LSPS5WebhookUrl :: new ( WEBHOOK_URL . to_string ( ) ) . unwrap ( ) ;
749+ let lsps5_old_app_name = LSPS5AppName :: from_string ( OLD_APP_NAME . to_string ( ) ) . unwrap ( ) ;
750+ let lsps5_new_app_name = LSPS5AppName :: from_string ( NEW_APP_NAME . to_string ( ) ) . unwrap ( ) ;
751+ let lsps5_webhook_url = LSPS5WebhookUrl :: from_string ( WEBHOOK_URL . to_string ( ) ) . unwrap ( ) ;
757752 let now = time_provider. duration_since_epoch ( ) ;
758753 let mut peer_state = PeerState :: new ( Duration :: from_secs ( 1800 ) , time_provider. clone ( ) ) ;
759754 peer_state. last_cleanup = Some ( LSPSDateTime :: new_from_duration_since_epoch (
0 commit comments