@@ -23,7 +23,7 @@ use super::msgs::{
2323 LSPS1ChannelInfo , LSPS1CreateOrderRequest , LSPS1CreateOrderResponse , LSPS1GetInfoResponse ,
2424 LSPS1GetOrderRequest , LSPS1Message , LSPS1Options , LSPS1OrderId , LSPS1OrderParams ,
2525 LSPS1PaymentInfo , LSPS1PaymentState , 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 [`Self::onchain_payments_required`] to reject the request.
341342 ///
342343 /// [`LSPS1ServiceEvent::RequestForPaymentDetails`]: crate::lsps1::event::LSPS1ServiceEvent::RequestForPaymentDetails
343344 pub async fn send_payment_details (
@@ -496,6 +497,45 @@ where
496497 }
497498 }
498499
500+ /// Used by LSP to inform a client that an order was rejected because they require onchain
501+ /// payments and the client didn't provide a `refund_onchain_address`.
502+ ///
503+ /// Should be called in response to receiving a [`LSPS1ServiceEvent::RequestForPaymentDetails`]
504+ /// event if the LSP requires onchain payments and `refund_onchain_address` is `None`.
505+ ///
506+ /// [`LSPS1ServiceEvent::RequestForPaymentDetails`]: crate::lsps1::event::LSPS1ServiceEvent::RequestForPaymentDetails
507+ pub fn onchain_payments_required (
508+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
509+ ) -> Result < ( ) , APIError > {
510+ let mut message_queue_notifier = self . pending_messages . notifier ( ) ;
511+
512+ match self . per_peer_state . read ( ) . unwrap ( ) . get ( & counterparty_node_id) {
513+ Some ( inner_state_lock) => {
514+ let mut peer_state_lock = inner_state_lock. lock ( ) . unwrap ( ) ;
515+ peer_state_lock. remove_request ( & request_id) . map_err ( |e| {
516+ debug_assert ! ( false , "Failed to send response due to: {}" , e) ;
517+ let err = format ! ( "Failed to send response due to: {}" , e) ;
518+ APIError :: APIMisuseError { err }
519+ } ) ?;
520+
521+ let response = LSPS1Response :: CreateOrderError ( LSPSResponseError {
522+ code : LSPS1_CREATE_ORDER_REQUEST_OPTION_MISMATCH_ERROR_CODE ,
523+ message :
524+ "We require onchain payment but no `refund_onchain_address` was provided"
525+ . to_string ( ) ,
526+ data : None ,
527+ } ) ;
528+
529+ let msg = LSPS1Message :: Response ( request_id, response) . into ( ) ;
530+ message_queue_notifier. enqueue ( & counterparty_node_id, msg) ;
531+ Ok ( ( ) )
532+ } ,
533+ None => Err ( APIError :: APIMisuseError {
534+ err : format ! ( "No state for the counterparty exists: {}" , counterparty_node_id) ,
535+ } ) ,
536+ }
537+ }
538+
499539 fn handle_get_order_request (
500540 & self , request_id : LSPSRequestId , counterparty_node_id : & PublicKey ,
501541 params : LSPS1GetOrderRequest ,
@@ -640,7 +680,6 @@ where
640680 /// Marks an order as failed and refunded.
641681 ///
642682 /// This should be called when:
643- /// - We require onchain payment and the client didn't provide a `refund_onchain_address`.
644683 /// - The order expires without payment
645684 /// - The channel open fails after payment and the LSP must refund
646685 pub async fn order_failed_and_refunded (
@@ -782,6 +821,16 @@ where
782821 self . inner . invalid_token_provided ( counterparty_node_id, request_id)
783822 }
784823
824+ /// Used by LSP to inform a client that an order was rejected because they require onchain
825+ /// payments and the client didn't provide a `refund_onchain_address`.
826+ ///
827+ /// Wraps [`LSPS1ServiceHandler::onchain_payments_required`].
828+ pub fn onchain_payments_required (
829+ & self , counterparty_node_id : PublicKey , request_id : LSPSRequestId ,
830+ ) -> Result < ( ) , APIError > {
831+ self . inner . onchain_payments_required ( counterparty_node_id, request_id)
832+ }
833+
785834 /// Marks an order as paid after payment has been received.
786835 ///
787836 /// Wraps [`LSPS1ServiceHandler::order_payment_received`].
0 commit comments