@@ -5,7 +5,6 @@ use lightning::util::logger::Level;
5
5
use std:: ops:: Deref ;
6
6
use std:: sync:: { Arc , Mutex } ;
7
7
8
- use crate :: events:: Event ;
9
8
use crate :: transport:: message_handler:: ProtocolMessageHandler ;
10
9
use crate :: transport:: msgs:: {
11
10
LSPS0Message , LSPS0Request , LSPS0Response , LSPSMessage , ListProtocolsRequest ,
19
18
{
20
19
entropy_source : ES ,
21
20
pending_messages : Arc < Mutex < Vec < ( PublicKey , LSPSMessage ) > > > ,
22
- pending_events : Arc < Mutex < Vec < Event > > > ,
23
21
protocols : Vec < u16 > ,
24
22
}
25
23
30
28
pub fn new (
31
29
entropy_source : ES , protocols : Vec < u16 > ,
32
30
pending_messages : Arc < Mutex < Vec < ( PublicKey , LSPSMessage ) > > > ,
33
- pending_events : Arc < Mutex < Vec < Event > > > ,
34
31
) -> Self {
35
- Self { entropy_source, protocols, pending_messages, pending_events }
32
+ Self { entropy_source, protocols, pending_messages }
36
33
}
37
34
38
35
pub fn list_protocols ( & self , counterparty_node_id : PublicKey ) {
48
45
self . pending_messages . lock ( ) . unwrap ( ) . push ( ( counterparty_node_id, message. into ( ) ) ) ;
49
46
}
50
47
51
- fn enqueue_event ( & self , event : Event ) {
52
- let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
53
- pending_events. push ( event) ;
54
- }
55
-
56
48
fn handle_request (
57
49
& self , request_id : RequestId , request : LSPS0Request , counterparty_node_id : & PublicKey ,
58
50
) -> Result < ( ) , lightning:: ln:: msgs:: LightningError > {
74
66
& self , response : LSPS0Response , counterparty_node_id : & PublicKey ,
75
67
) -> Result < ( ) , LightningError > {
76
68
match response {
77
- LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols } ) => {
78
- self . enqueue_event ( Event :: ListProtocols {
79
- counterparty_node_id : * counterparty_node_id,
80
- protocols,
81
- } ) ;
82
- Ok ( ( ) )
83
- }
69
+ LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols } ) => Ok ( ( ) ) ,
84
70
LSPS0Response :: ListProtocolsError ( ResponseError { code, message, data, .. } ) => {
85
71
Err ( LightningError {
86
72
err : format ! (
@@ -134,14 +120,9 @@ mod tests {
134
120
let entropy = Arc :: new ( TestEntropy { } ) ;
135
121
let protocols: Vec < u16 > = vec ! [ ] ;
136
122
let pending_messages = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
137
- let pending_events = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
138
123
139
- let lsps0_handler = Arc :: new ( LSPS0MessageHandler :: new (
140
- entropy,
141
- protocols,
142
- pending_messages. clone ( ) ,
143
- pending_events,
144
- ) ) ;
124
+ let lsps0_handler =
125
+ Arc :: new ( LSPS0MessageHandler :: new ( entropy, protocols, pending_messages. clone ( ) ) ) ;
145
126
146
127
let list_protocols_request = LSPS0Message :: Request (
147
128
RequestId ( "xyz123" . to_string ( ) ) ,
@@ -172,13 +153,11 @@ mod tests {
172
153
#[ test]
173
154
fn test_list_protocols ( ) {
174
155
let pending_messages = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
175
- let pending_events = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
176
156
177
157
let lsps0_handler = Arc :: new ( LSPS0MessageHandler :: new (
178
158
Arc :: new ( TestEntropy { } ) ,
179
159
vec ! [ 1 , 2 , 3 ] ,
180
160
pending_messages. clone ( ) ,
181
- pending_events,
182
161
) ) ;
183
162
184
163
let counterparty_node_id = utils:: parse_pubkey (
@@ -202,36 +181,4 @@ mod tests {
202
181
) )
203
182
) ;
204
183
}
205
-
206
- #[ test]
207
- fn test_handle_list_protocols_response ( ) {
208
- let pending_messages = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
209
- let pending_events = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
210
- let protocols = vec ! [ 1 , 2 , 3 ] ;
211
-
212
- let lsps0_handler = Arc :: new ( LSPS0MessageHandler :: new (
213
- Arc :: new ( TestEntropy { } ) ,
214
- protocols,
215
- pending_messages,
216
- pending_events. clone ( ) ,
217
- ) ) ;
218
-
219
- let list_protocols_response = LSPS0Message :: Response (
220
- RequestId ( "00000000000000000000000000000000" . to_string ( ) ) ,
221
- LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols : vec ! [ 1 , 2 , 3 ] } ) ,
222
- ) ;
223
- let counterparty_node_id = utils:: parse_pubkey (
224
- "027100442c3b79f606f80f322d98d499eefcb060599efc5d4ecb00209c2cb54190" ,
225
- )
226
- . unwrap ( ) ;
227
-
228
- lsps0_handler. handle_message ( list_protocols_response, & counterparty_node_id) . unwrap ( ) ;
229
- let pending_events = pending_events. lock ( ) . unwrap ( ) ;
230
-
231
- assert_eq ! ( pending_events. len( ) , 1 ) ;
232
- assert_eq ! (
233
- pending_events[ 0 ] ,
234
- Event :: ListProtocols { counterparty_node_id, protocols: vec![ 1 , 2 , 3 ] }
235
- ) ;
236
- }
237
184
}
0 commit comments