@@ -23,7 +23,7 @@ use super::msgs::{
2323 LSPS1ChannelInfo , LSPS1CreateOrderRequest , LSPS1CreateOrderResponse , LSPS1GetInfoResponse ,
2424 LSPS1GetOrderRequest , LSPS1Message , LSPS1Options , LSPS1OrderId , LSPS1OrderParams ,
2525 LSPS1PaymentInfo , LSPS1Request , LSPS1Response ,
26- LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE ,
26+ LSPS1_CREATE_ORDER_REQUEST_OPTION_MISMATCH_ERROR_CODE ,
2727 LSPS1_CREATE_ORDER_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE ,
2828 LSPS1_GET_ORDER_REQUEST_ORDER_NOT_FOUND_ERROR_CODE ,
2929} ;
@@ -291,7 +291,7 @@ where
291291
292292 if !is_valid ( & params. order , & self . config . supported_options ) {
293293 let response = LSPS1Response :: CreateOrderError ( LSPSResponseError {
294- code : LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE ,
294+ code : LSPS1_CREATE_ORDER_REQUEST_OPTION_MISMATCH_ERROR_CODE ,
295295 message : "Order does not match options supported by LSP server" . to_string ( ) ,
296296 data : Some ( format ! ( "Supported options are {:?}" , & self . config. supported_options) ) ,
297297 } ) ;
@@ -337,7 +337,8 @@ where
337337 /// Should be called in response to receiving a [`LSPS1ServiceEvent::RequestForPaymentDetails`] event.
338338 ///
339339 /// Note that the provided `payment_details` can't include the onchain payment variant if the
340- /// user didn't provide a `refund_onchain_address`.
340+ /// user didn't provide a `refund_onchain_address`. If you *require* onchain payments, you need
341+ /// to call [`onchain_payments_required`] to reject the request.
341342 ///
342343 /// [`LSPS1ServiceEvent::RequestForPaymentDetails`]: crate::lsps1::event::LSPS1ServiceEvent::RequestForPaymentDetails
343344 pub async fn send_payment_details (
@@ -469,6 +470,45 @@ where
469470 }
470471 }
471472
473+ /// Used by LSP to inform a client that an order was rejected because they require onchain
474+ /// payments and the client didn't provided a `refund_onchain_address`.
475+ ///
476+ /// Should be called in response to receiving a [`LSPS1ServiceEvent::RequestForPaymentDetails`]
477+ /// event if the LSP requires onchain payments and `refund_onchain_address` is `None`.
478+ ///
479+ /// [`LSPS1ServiceEvent::RequestForPaymentDetails`]: crate::lsps1::event::LSPS1ServiceEvent::RequestForPaymentDetails
480+ pub fn onchain_payments_required (
481+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
482+ ) -> Result < ( ) , APIError > {
483+ let mut message_queue_notifier = self . pending_messages . notifier ( ) ;
484+
485+ match self . per_peer_state . read ( ) . unwrap ( ) . get ( & counterparty_node_id) {
486+ Some ( inner_state_lock) => {
487+ let mut peer_state_lock = inner_state_lock. lock ( ) . unwrap ( ) ;
488+ peer_state_lock. remove_request ( & request_id) . map_err ( |e| {
489+ debug_assert ! ( false , "Failed to send response due to: {}" , e) ;
490+ let err = format ! ( "Failed to send response due to: {}" , e) ;
491+ APIError :: APIMisuseError { err }
492+ } ) ?;
493+
494+ let response = LSPS1Response :: CreateOrderError ( LSPSResponseError {
495+ code : LSPS1_CREATE_ORDER_REQUEST_OPTION_MISMATCH_ERROR_CODE ,
496+ message :
497+ "We require onchain payment but no `refund_onchain_address` was provided"
498+ . to_string ( ) ,
499+ data : None ,
500+ } ) ;
501+
502+ let msg = LSPS1Message :: Response ( request_id, response) . into ( ) ;
503+ message_queue_notifier. enqueue ( & counterparty_node_id, msg) ;
504+ Ok ( ( ) )
505+ } ,
506+ None => Err ( APIError :: APIMisuseError {
507+ err : format ! ( "No state for the counterparty exists: {}" , counterparty_node_id) ,
508+ } ) ,
509+ }
510+ }
511+
472512 fn handle_get_order_request (
473513 & self , request_id : LSPSRequestId , counterparty_node_id : & PublicKey ,
474514 params : LSPS1GetOrderRequest ,
0 commit comments