44//! specifcation](https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS0) for more
55//! information.
66
7+ use crate :: events:: { Event , EventQueue } ;
8+ use crate :: lsps0:: event:: LSPS0ClientEvent ;
79use crate :: lsps0:: msgs:: {
810 LSPS0Message , LSPS0Request , LSPS0Response , LSPSMessage , ListProtocolsRequest ,
911 ListProtocolsResponse , ProtocolMessageHandler , ResponseError ,
2729{
2830 entropy_source : ES ,
2931 pending_messages : Arc < Mutex < Vec < ( PublicKey , LSPSMessage ) > > > ,
32+ pending_events : Arc < EventQueue > ,
3033}
3134
3235impl < ES : Deref > LSPS0ClientHandler < ES >
3639 /// Returns a new instance of [`LSPS0ClientHandler`].
3740 pub ( crate ) fn new (
3841 entropy_source : ES , pending_messages : Arc < Mutex < Vec < ( PublicKey , LSPSMessage ) > > > ,
42+ pending_events : Arc < EventQueue > ,
3943 ) -> Self {
40- Self { entropy_source, pending_messages }
44+ Self { entropy_source, pending_messages, pending_events }
4145 }
4246
4347 /// Calls LSPS0's `list_protocols`.
@@ -59,10 +63,18 @@ where
5963 }
6064
6165 fn handle_response (
62- & self , response : LSPS0Response , _counterparty_node_id : & PublicKey ,
66+ & self , response : LSPS0Response , counterparty_node_id : & PublicKey ,
6367 ) -> Result < ( ) , LightningError > {
6468 match response {
65- LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols : _ } ) => Ok ( ( ) ) ,
69+ LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols } ) => {
70+ self . pending_events . enqueue ( Event :: LSPS0Client (
71+ LSPS0ClientEvent :: ListProtocolsResponse {
72+ counterparty_node_id : * counterparty_node_id,
73+ protocols,
74+ } ,
75+ ) ) ;
76+ Ok ( ( ) )
77+ }
6678 LSPS0Response :: ListProtocolsError ( ResponseError { code, message, data, .. } ) => {
6779 Err ( LightningError {
6880 err : format ! (
@@ -121,9 +133,14 @@ mod tests {
121133 #[ test]
122134 fn test_list_protocols ( ) {
123135 let pending_messages = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
124-
125- let lsps0_handler =
126- Arc :: new ( LSPS0ClientHandler :: new ( Arc :: new ( TestEntropy { } ) , pending_messages. clone ( ) ) ) ;
136+ let entropy_source = Arc :: new ( TestEntropy { } ) ;
137+ let event_queue = Arc :: new ( EventQueue :: new ( ) ) ;
138+
139+ let lsps0_handler = Arc :: new ( LSPS0ClientHandler :: new (
140+ entropy_source,
141+ Arc :: clone ( & pending_messages) ,
142+ event_queue,
143+ ) ) ;
127144
128145 let counterparty_node_id = utils:: parse_pubkey (
129146 "027100442c3b79f606f80f322d98d499eefcb060599efc5d4ecb00209c2cb54190" ,
0 commit comments