9
9
10
10
//! Client implementation for LSPS5 webhook registration
11
11
12
+ use crate :: alloc:: string:: ToString ;
12
13
use crate :: events:: EventQueue ;
13
14
use crate :: lsps0:: ser:: { LSPSDateTime , LSPSMessage , LSPSProtocolMessageHandler , LSPSRequestId } ;
14
15
use crate :: lsps5:: event:: LSPS5ClientEvent ;
@@ -17,27 +18,25 @@ use crate::lsps5::msgs::{
17
18
SetWebhookRequest , WebhookNotification ,
18
19
} ;
19
20
use 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 ;
30
21
use 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;
32
24
33
25
use super :: msgs:: { LSPS5AppName , LSPS5WebhookUrl } ;
34
26
#[ cfg( feature = "time" ) ]
35
27
use super :: service:: DefaultTimeProvider ;
36
28
use super :: service:: TimeProvider ;
37
- use crate :: utils :: generate_request_id ;
29
+
38
30
use alloc:: collections:: VecDeque ;
31
+ use alloc:: string:: String ;
32
+ use bitcoin:: secp256k1:: PublicKey ;
33
+ use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
39
34
use lightning:: sign:: EntropySource ;
40
35
use lightning:: util:: logger:: Level ;
36
+ use lightning:: util:: message_signing;
37
+
38
+ use core:: ops:: Deref ;
39
+ use core:: time:: Duration ;
41
40
42
41
/// Default maximum age in seconds for cached responses (1 hour)
43
42
pub const DEFAULT_RESPONSE_MAX_AGE_SECS : u64 = 3600 ;
@@ -226,14 +225,13 @@ where
226
225
pub fn set_webhook (
227
226
& self , counterparty_node_id : PublicKey , app_name : String , webhook_url : String ,
228
227
) -> 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 ( ) ,
231
230
action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
232
231
} ) ?;
233
232
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 ) }
237
235
} ) ?;
238
236
239
237
let request_id = generate_request_id ( & self . entropy_source ) ;
@@ -304,8 +302,8 @@ where
304
302
pub fn remove_webhook (
305
303
& self , counterparty_node_id : PublicKey , app_name : String ,
306
304
) -> 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 ( ) ,
309
307
action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
310
308
} ) ?;
311
309
@@ -361,8 +359,7 @@ where
361
359
self . pending_events . enqueue (
362
360
LSPS5ClientEvent :: WebhookRegistrationFailed {
363
361
counterparty_node_id : * counterparty_node_id,
364
- error_code : error. code ,
365
- error_message : error. message ,
362
+ error,
366
363
app_name,
367
364
url : webhook_url,
368
365
request_id,
@@ -396,8 +393,7 @@ where
396
393
LSPS5Response :: ListWebhooksError ( error) => {
397
394
self . pending_events . enqueue ( LSPS5ClientEvent :: WebhooksListFailed {
398
395
counterparty_node_id : * counterparty_node_id,
399
- error_code : error. code ,
400
- error_message : error. message ,
396
+ error,
401
397
request_id,
402
398
} ) ;
403
399
result = Ok ( ( ) ) ;
@@ -426,8 +422,7 @@ where
426
422
self . pending_events . enqueue (
427
423
LSPS5ClientEvent :: WebhookRemovalFailed {
428
424
counterparty_node_id : * counterparty_node_id,
429
- error_code : error. code ,
430
- error_message : error. message ,
425
+ error,
431
426
app_name,
432
427
request_id,
433
428
} ,
@@ -686,8 +681,8 @@ mod tests {
686
681
let ( client, _, _, peer, _) = setup_test_client ( ) ;
687
682
const APP_NAME : & str = "test-app" ;
688
683
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 ( ) ;
691
686
let set_req_id =
692
687
client. set_webhook ( peer, APP_NAME . to_string ( ) , WEBHOOK_URL . to_string ( ) ) . unwrap ( ) ;
693
688
let list_req_id = client. list_webhooks ( peer) . unwrap ( ) ;
@@ -751,9 +746,9 @@ mod tests {
751
746
const OLD_APP_NAME : & str = "test-app-old" ;
752
747
const NEW_APP_NAME : & str = "test-app-new" ;
753
748
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 ( ) ;
757
752
let now = time_provider. duration_since_epoch ( ) ;
758
753
let mut peer_state = PeerState :: new ( Duration :: from_secs ( 1800 ) , time_provider. clone ( ) ) ;
759
754
peer_state. last_cleanup = Some ( LSPSDateTime :: new_from_duration_since_epoch (
0 commit comments