99
1010//! Contains the main bLIP-51 / LSPS1 server object, [`LSPS1ServiceHandler`].
1111
12- use alloc:: string:: String ;
13-
1412use core:: future:: Future as StdFuture ;
1513use core:: ops:: Deref ;
1614use core:: pin:: pin;
@@ -23,6 +21,7 @@ use super::msgs::{
2321 LSPS1GetOrderRequest , LSPS1Message , LSPS1Options , LSPS1OrderId , LSPS1OrderParams ,
2422 LSPS1OrderState , LSPS1PaymentInfo , LSPS1Request , LSPS1Response ,
2523 LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE ,
24+ LSPS1_CREATE_ORDER_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
2625 LSPS1_GET_ORDER_REQUEST_ORDER_NOT_FOUND_ERROR_CODE ,
2726} ;
2827use super :: peer_state:: PeerState ;
@@ -55,8 +54,6 @@ use bitcoin::secp256k1::PublicKey;
5554/// Server-side configuration options for bLIP-51 / LSPS1 channel requests.
5655#[ derive( Clone , Debug ) ]
5756pub struct LSPS1ServiceConfig {
58- /// A token to be send with each channel request.
59- pub token : Option < String > ,
6057 /// The options supported by the LSP.
6158 pub supported_options : LSPS1Options ,
6259}
@@ -429,6 +426,42 @@ where
429426 Ok ( ( ) )
430427 }
431428
429+ /// Used by LSP to inform a client that an order was rejected because the used token was invalid.
430+ ///
431+ /// Should be called in response to receiving a [`LSPS1ServiceEvent::RequestForPaymentDetails`]
432+ /// event if the provided token is invalid.
433+ ///
434+ /// [`LSPS1ServiceEvent::RequestForPaymentDetails`]: crate::lsps1::event::LSPS1ServiceEvent::RequestForPaymentDetails
435+ pub fn invalid_token_provided (
436+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
437+ ) -> Result < ( ) , APIError > {
438+ let mut message_queue_notifier = self . pending_messages . notifier ( ) ;
439+
440+ match self . per_peer_state . read ( ) . unwrap ( ) . get ( & counterparty_node_id) {
441+ Some ( inner_state_lock) => {
442+ let mut peer_state_lock = inner_state_lock. lock ( ) . unwrap ( ) ;
443+ peer_state_lock. remove_request ( & request_id) . map_err ( |e| {
444+ debug_assert ! ( false , "Failed to send response due to: {}" , e) ;
445+ let err = format ! ( "Failed to send response due to: {}" , e) ;
446+ APIError :: APIMisuseError { err }
447+ } ) ?;
448+
449+ let response = LSPS1Response :: CreateOrderError ( LSPSResponseError {
450+ code : LSPS1_CREATE_ORDER_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
451+ message : "An unrecognized or stale token was provided" . to_string ( ) ,
452+ data : None ,
453+ } ) ;
454+
455+ let msg = LSPS1Message :: Response ( request_id, response) . into ( ) ;
456+ message_queue_notifier. enqueue ( & counterparty_node_id, msg) ;
457+ Ok ( ( ) )
458+ } ,
459+ None => Err ( APIError :: APIMisuseError {
460+ err : format ! ( "No state for the counterparty exists: {}" , counterparty_node_id) ,
461+ } ) ,
462+ }
463+ }
464+
432465 fn handle_get_order_request (
433466 & self , request_id : LSPSRequestId , counterparty_node_id : & PublicKey ,
434467 params : LSPS1GetOrderRequest ,
@@ -589,6 +622,15 @@ where
589622 }
590623 }
591624
625+ /// Used by LSP to inform a client that an order was rejected because the used token was invalid.
626+ ///
627+ /// Wraps [`LSPS1ServiceHandler::invalid_token_provided`].
628+ pub fn invalid_token_provided (
629+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
630+ ) -> Result < ( ) , APIError > {
631+ self . inner . invalid_token_provided ( counterparty_node_id, request_id)
632+ }
633+
592634 /// Used by LSP to give details to client regarding the status of channel opening.
593635 ///
594636 /// Wraps [`LSPS1ServiceHandler::update_order_status`].
0 commit comments