99
1010//! Contains the main bLIP-51 / LSPS1 server object, [`LSPS1ServiceHandler`].
1111
12- use alloc:: string:: { String , ToString } ;
12+ use alloc:: string:: ToString ;
1313use alloc:: vec:: Vec ;
1414
1515use core:: future:: Future as StdFuture ;
@@ -24,6 +24,7 @@ use super::msgs::{
2424 LSPS1GetOrderRequest , LSPS1Message , LSPS1Options , LSPS1OrderId , LSPS1OrderParams ,
2525 LSPS1OrderState , LSPS1PaymentInfo , LSPS1Request , LSPS1Response ,
2626 LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE ,
27+ LSPS1_CREATE_ORDER_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
2728 LSPS1_GET_ORDER_REQUEST_ORDER_NOT_FOUND_ERROR_CODE ,
2829} ;
2930use super :: peer_state:: PeerState ;
@@ -56,8 +57,6 @@ use bitcoin::secp256k1::PublicKey;
5657/// Server-side configuration options for bLIP-51 / LSPS1 channel requests.
5758#[ derive( Clone , Debug ) ]
5859pub struct LSPS1ServiceConfig {
59- /// A token to be send with each channel request.
60- pub token : Option < String > ,
6160 /// The options supported by the LSP.
6261 pub supported_options : LSPS1Options ,
6362}
@@ -434,6 +433,42 @@ where
434433 Ok ( ( ) )
435434 }
436435
436+ /// Used by LSP to inform a client that an order was rejected because the used token was invalid.
437+ ///
438+ /// Should be called in response to receiving a [`LSPS1ServiceEvent::RequestForPaymentDetails`]
439+ /// event if the provided token is invalid.
440+ ///
441+ /// [`LSPS1ServiceEvent::RequestForPaymentDetails`]: crate::lsps1::event::LSPS1ServiceEvent::RequestForPaymentDetails
442+ pub fn invalid_token_provided (
443+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
444+ ) -> Result < ( ) , APIError > {
445+ let mut message_queue_notifier = self . pending_messages . notifier ( ) ;
446+
447+ match self . per_peer_state . read ( ) . unwrap ( ) . get ( & counterparty_node_id) {
448+ Some ( inner_state_lock) => {
449+ let mut peer_state_lock = inner_state_lock. lock ( ) . unwrap ( ) ;
450+ peer_state_lock. remove_request ( & request_id) . map_err ( |e| {
451+ debug_assert ! ( false , "Failed to send response due to: {}" , e) ;
452+ let err = format ! ( "Failed to send response due to: {}" , e) ;
453+ APIError :: APIMisuseError { err }
454+ } ) ?;
455+
456+ let response = LSPS1Response :: CreateOrderError ( LSPSResponseError {
457+ code : LSPS1_CREATE_ORDER_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
458+ message : "An unrecognized or stale token was provided" . to_string ( ) ,
459+ data : None ,
460+ } ) ;
461+
462+ let msg = LSPS1Message :: Response ( request_id, response) . into ( ) ;
463+ message_queue_notifier. enqueue ( & counterparty_node_id, msg) ;
464+ Ok ( ( ) )
465+ } ,
466+ None => Err ( APIError :: APIMisuseError {
467+ err : format ! ( "No state for the counterparty exists: {}" , counterparty_node_id) ,
468+ } ) ,
469+ }
470+ }
471+
437472 fn handle_get_order_request (
438473 & self , request_id : LSPSRequestId , counterparty_node_id : & PublicKey ,
439474 params : LSPS1GetOrderRequest ,
@@ -625,6 +660,15 @@ where
625660 }
626661 }
627662
663+ /// Used by LSP to inform a client that an order was rejected because the used token was invalid.
664+ ///
665+ /// Wraps [`LSPS1ServiceHandler::invalid_token_provided`].
666+ pub fn invalid_token_provided (
667+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
668+ ) -> Result < ( ) , APIError > {
669+ self . inner . invalid_token_provided ( counterparty_node_id, request_id)
670+ }
671+
628672 /// Used by LSP to give details to client regarding the status of channel opening.
629673 ///
630674 /// Wraps [`LSPS1ServiceHandler::update_order_status`].
0 commit comments