@@ -16,6 +16,10 @@ use crate::lsps1::msgs::{
1616use crate :: lsps2:: msgs:: {
1717 LSPS2Message , LSPS2Request , LSPS2Response , LSPS2_BUY_METHOD_NAME , LSPS2_GET_INFO_METHOD_NAME ,
1818} ;
19+ use crate :: lsps5:: msgs:: {
20+ LSPS5Message , LSPS5Request , LSPS5Response , LSPS5_LIST_WEBHOOKS_METHOD_NAME ,
21+ LSPS5_REMOVE_WEBHOOK_METHOD_NAME , LSPS5_SET_WEBHOOK_METHOD_NAME ,
22+ } ;
1923use crate :: prelude:: { HashMap , String } ;
2024
2125use lightning:: ln:: msgs:: LightningError ;
@@ -55,6 +59,9 @@ pub(crate) enum LSPSMethod {
5559 LSPS1CreateOrder ,
5660 LSPS2GetInfo ,
5761 LSPS2Buy ,
62+ LSPS5SetWebhook ,
63+ LSPS5ListWebhooks ,
64+ LSPS5RemoveWebhook ,
5865}
5966
6067impl LSPSMethod {
@@ -66,6 +73,9 @@ impl LSPSMethod {
6673 Self :: LSPS1GetOrder => LSPS1_GET_ORDER_METHOD_NAME ,
6774 Self :: LSPS2GetInfo => LSPS2_GET_INFO_METHOD_NAME ,
6875 Self :: LSPS2Buy => LSPS2_BUY_METHOD_NAME ,
76+ Self :: LSPS5SetWebhook => LSPS5_SET_WEBHOOK_METHOD_NAME ,
77+ Self :: LSPS5ListWebhooks => LSPS5_LIST_WEBHOOKS_METHOD_NAME ,
78+ Self :: LSPS5RemoveWebhook => LSPS5_REMOVE_WEBHOOK_METHOD_NAME ,
6979 }
7080 }
7181}
@@ -80,6 +90,10 @@ impl FromStr for LSPSMethod {
8090 LSPS1_GET_ORDER_METHOD_NAME => Ok ( Self :: LSPS1GetOrder ) ,
8191 LSPS2_GET_INFO_METHOD_NAME => Ok ( Self :: LSPS2GetInfo ) ,
8292 LSPS2_BUY_METHOD_NAME => Ok ( Self :: LSPS2Buy ) ,
93+ // Add LSPS5 methods
94+ LSPS5_SET_WEBHOOK_METHOD_NAME => Ok ( Self :: LSPS5SetWebhook ) ,
95+ LSPS5_LIST_WEBHOOKS_METHOD_NAME => Ok ( Self :: LSPS5ListWebhooks ) ,
96+ LSPS5_REMOVE_WEBHOOK_METHOD_NAME => Ok ( Self :: LSPS5RemoveWebhook ) ,
8397 _ => Err ( & "Unknown method name" ) ,
8498 }
8599 }
@@ -112,6 +126,17 @@ impl From<&LSPS2Request> for LSPSMethod {
112126 }
113127}
114128
129+ // Add implementation for LSPS5Request
130+ impl From < & LSPS5Request > for LSPSMethod {
131+ fn from ( value : & LSPS5Request ) -> Self {
132+ match value {
133+ LSPS5Request :: SetWebhook ( _) => Self :: LSPS5SetWebhook ,
134+ LSPS5Request :: ListWebhooks ( _) => Self :: LSPS5ListWebhooks ,
135+ LSPS5Request :: RemoveWebhook ( _) => Self :: LSPS5RemoveWebhook ,
136+ }
137+ }
138+ }
139+
115140impl < ' de > Deserialize < ' de > for LSPSMethod {
116141 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
117142 where
@@ -269,6 +294,8 @@ pub enum LSPSMessage {
269294 LSPS1 ( LSPS1Message ) ,
270295 /// An LSPS2 message.
271296 LSPS2 ( LSPS2Message ) ,
297+ /// An LSPS5 message.
298+ LSPS5 ( LSPS5Message ) ,
272299}
273300
274301impl LSPSMessage {
@@ -296,6 +323,10 @@ impl LSPSMessage {
296323 LSPSMessage :: LSPS2 ( LSPS2Message :: Request ( request_id, request) ) => {
297324 Some ( ( LSPSRequestId ( request_id. 0 . clone ( ) ) , request. into ( ) ) )
298325 } ,
326+ // Add LSPS5
327+ LSPSMessage :: LSPS5 ( LSPS5Message :: Request ( request_id, request) ) => {
328+ Some ( ( LSPSRequestId ( request_id. 0 . clone ( ) ) , request. into ( ) ) )
329+ } ,
299330 _ => None ,
300331 }
301332 }
@@ -412,6 +443,47 @@ impl Serialize for LSPSMessage {
412443 jsonrpc_object. serialize_field ( JSONRPC_ID_FIELD_KEY , & serde_json:: Value :: Null ) ?;
413444 jsonrpc_object. serialize_field ( JSONRPC_ERROR_FIELD_KEY , & error) ?;
414445 } ,
446+ LSPSMessage :: LSPS5 ( LSPS5Message :: Request ( request_id, request) ) => {
447+ jsonrpc_object. serialize_field ( JSONRPC_ID_FIELD_KEY , & request_id. 0 ) ?;
448+ jsonrpc_object
449+ . serialize_field ( JSONRPC_METHOD_FIELD_KEY , & LSPSMethod :: from ( request) ) ?;
450+
451+ match request {
452+ LSPS5Request :: SetWebhook ( params) => {
453+ jsonrpc_object. serialize_field ( JSONRPC_PARAMS_FIELD_KEY , params) ?
454+ } ,
455+ LSPS5Request :: ListWebhooks ( params) => {
456+ jsonrpc_object. serialize_field ( JSONRPC_PARAMS_FIELD_KEY , params) ?
457+ } ,
458+ LSPS5Request :: RemoveWebhook ( params) => {
459+ jsonrpc_object. serialize_field ( JSONRPC_PARAMS_FIELD_KEY , params) ?
460+ } ,
461+ }
462+ } ,
463+ LSPSMessage :: LSPS5 ( LSPS5Message :: Response ( request_id, response) ) => {
464+ jsonrpc_object. serialize_field ( JSONRPC_ID_FIELD_KEY , & request_id. 0 ) ?;
465+
466+ match response {
467+ LSPS5Response :: SetWebhook ( result) => {
468+ jsonrpc_object. serialize_field ( JSONRPC_RESULT_FIELD_KEY , result) ?
469+ } ,
470+ LSPS5Response :: SetWebhookError ( error) => {
471+ jsonrpc_object. serialize_field ( JSONRPC_ERROR_FIELD_KEY , error) ?
472+ } ,
473+ LSPS5Response :: ListWebhooks ( result) => {
474+ jsonrpc_object. serialize_field ( JSONRPC_RESULT_FIELD_KEY , result) ?
475+ } ,
476+ LSPS5Response :: ListWebhooksError ( error) => {
477+ jsonrpc_object. serialize_field ( JSONRPC_ERROR_FIELD_KEY , error) ?
478+ } ,
479+ LSPS5Response :: RemoveWebhook ( result) => {
480+ jsonrpc_object. serialize_field ( JSONRPC_RESULT_FIELD_KEY , result) ?
481+ } ,
482+ LSPS5Response :: RemoveWebhookError ( error) => {
483+ jsonrpc_object. serialize_field ( JSONRPC_ERROR_FIELD_KEY , error) ?
484+ } ,
485+ }
486+ } ,
415487 }
416488
417489 jsonrpc_object. end ( )
@@ -525,6 +597,31 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
525597 . map_err ( de:: Error :: custom) ?;
526598 Ok ( LSPSMessage :: LSPS2 ( LSPS2Message :: Request ( id, LSPS2Request :: Buy ( request) ) ) )
527599 } ,
600+ // Add LSPS5 methods
601+ LSPSMethod :: LSPS5SetWebhook => {
602+ let request = serde_json:: from_value ( params. unwrap_or ( json ! ( { } ) ) )
603+ . map_err ( de:: Error :: custom) ?;
604+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Request (
605+ id,
606+ LSPS5Request :: SetWebhook ( request) ,
607+ ) ) )
608+ } ,
609+ LSPSMethod :: LSPS5ListWebhooks => {
610+ let request = serde_json:: from_value ( params. unwrap_or ( json ! ( { } ) ) )
611+ . map_err ( de:: Error :: custom) ?;
612+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Request (
613+ id,
614+ LSPS5Request :: ListWebhooks ( request) ,
615+ ) ) )
616+ } ,
617+ LSPSMethod :: LSPS5RemoveWebhook => {
618+ let request = serde_json:: from_value ( params. unwrap_or ( json ! ( { } ) ) )
619+ . map_err ( de:: Error :: custom) ?;
620+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Request (
621+ id,
622+ LSPS5Request :: RemoveWebhook ( request) ,
623+ ) ) )
624+ } ,
528625 } ,
529626 None => match self . request_id_to_method_map . remove ( & id) {
530627 Some ( method) => match method {
@@ -630,6 +727,58 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
630727 Err ( de:: Error :: custom ( "Received invalid JSON-RPC object: one of method, result, or error required" ) )
631728 }
632729 } ,
730+ // Add LSPS5 methods
731+ LSPSMethod :: LSPS5SetWebhook => {
732+ if let Some ( error) = error {
733+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Response (
734+ id,
735+ LSPS5Response :: SetWebhookError ( error) ,
736+ ) ) )
737+ } else if let Some ( result) = result {
738+ let response =
739+ serde_json:: from_value ( result) . map_err ( de:: Error :: custom) ?;
740+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Response (
741+ id,
742+ LSPS5Response :: SetWebhook ( response) ,
743+ ) ) )
744+ } else {
745+ Err ( de:: Error :: custom ( "Received invalid JSON-RPC object: one of method, result, or error required" ) )
746+ }
747+ } ,
748+ LSPSMethod :: LSPS5ListWebhooks => {
749+ if let Some ( error) = error {
750+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Response (
751+ id,
752+ LSPS5Response :: ListWebhooksError ( error) ,
753+ ) ) )
754+ } else if let Some ( result) = result {
755+ let response =
756+ serde_json:: from_value ( result) . map_err ( de:: Error :: custom) ?;
757+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Response (
758+ id,
759+ LSPS5Response :: ListWebhooks ( response) ,
760+ ) ) )
761+ } else {
762+ Err ( de:: Error :: custom ( "Received invalid JSON-RPC object: one of method, result, or error required" ) )
763+ }
764+ } ,
765+ LSPSMethod :: LSPS5RemoveWebhook => {
766+ if let Some ( error) = error {
767+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Response (
768+ id,
769+ LSPS5Response :: RemoveWebhookError ( error) ,
770+ ) ) )
771+ } else if let Some ( result) = result {
772+ let response =
773+ serde_json:: from_value ( result) . map_err ( de:: Error :: custom) ?;
774+ Ok ( LSPSMessage :: LSPS5 ( LSPS5Message :: Response (
775+ id,
776+ LSPS5Response :: RemoveWebhook ( response) ,
777+ ) ) )
778+ } else {
779+ Err ( de:: Error :: custom ( "Received invalid JSON-RPC object: one of method, result, or error required" ) )
780+ }
781+ } ,
633782 } ,
634783 None => Err ( de:: Error :: custom ( format ! (
635784 "Received response for unknown request id: {}" ,
0 commit comments