1
1
//! Message, request, and other primitive types used to implement LSPS0.
2
2
3
- use crate :: lsps0:: ser:: { LSPSMessage , RequestId , ResponseError } ;
3
+ use crate :: lsps0:: ser:: { LSPSMessage , LSPSRequestId , LSPSResponseError } ;
4
4
use crate :: prelude:: Vec ;
5
5
6
6
use serde:: { Deserialize , Serialize } ;
@@ -15,15 +15,15 @@ pub(crate) const LSPS0_LISTPROTOCOLS_METHOD_NAME: &str = "lsps0.list_protocols";
15
15
/// specification](https://github.com/lightning/blips/blob/master/blip-0050.md#lsps-specification-support-query)
16
16
/// for more information.
17
17
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize , Default ) ]
18
- pub struct ListProtocolsRequest { }
18
+ pub struct LSPS0ListProtocolsRequest { }
19
19
20
20
/// A response to a `list_protocols` request.
21
21
///
22
22
/// Please refer to the [bLIP-50 / LSPS0
23
23
/// specification](https://github.com/lightning/blips/blob/master/blip-0050.md#lsps-specification-support-query)
24
24
/// for more information.
25
25
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
26
- pub struct ListProtocolsResponse {
26
+ pub struct LSPS0ListProtocolsResponse {
27
27
/// A list of supported protocols.
28
28
pub protocols : Vec < u16 > ,
29
29
}
@@ -36,12 +36,12 @@ pub struct ListProtocolsResponse {
36
36
#[ derive( Clone , Debug , PartialEq , Eq ) ]
37
37
pub enum LSPS0Request {
38
38
/// A request calling `list_protocols`.
39
- ListProtocols ( ListProtocolsRequest ) ,
39
+ ListProtocols ( LSPS0ListProtocolsRequest ) ,
40
40
}
41
41
42
42
impl LSPS0Request {
43
43
/// Returns the method name associated with the given request variant.
44
- pub fn method ( & self ) -> & str {
44
+ pub fn method ( & self ) -> & ' static str {
45
45
match self {
46
46
LSPS0Request :: ListProtocols ( _) => LSPS0_LISTPROTOCOLS_METHOD_NAME ,
47
47
}
@@ -56,9 +56,9 @@ impl LSPS0Request {
56
56
#[ derive( Clone , Debug , PartialEq , Eq ) ]
57
57
pub enum LSPS0Response {
58
58
/// A response to a `list_protocols` request.
59
- ListProtocols ( ListProtocolsResponse ) ,
59
+ ListProtocols ( LSPS0ListProtocolsResponse ) ,
60
60
/// An error response to a `list_protocols` request.
61
- ListProtocolsError ( ResponseError ) ,
61
+ ListProtocolsError ( LSPSResponseError ) ,
62
62
}
63
63
64
64
/// An bLIP-50 / LSPS0 protocol message.
@@ -69,9 +69,9 @@ pub enum LSPS0Response {
69
69
#[ derive( Clone , Debug , PartialEq , Eq ) ]
70
70
pub enum LSPS0Message {
71
71
/// A request variant.
72
- Request ( RequestId , LSPS0Request ) ,
72
+ Request ( LSPSRequestId , LSPS0Request ) ,
73
73
/// A response variant.
74
- Response ( RequestId , LSPS0Response ) ,
74
+ Response ( LSPSRequestId , LSPS0Response ) ,
75
75
}
76
76
77
77
impl TryFrom < LSPSMessage > for LSPS0Message {
@@ -117,17 +117,17 @@ mod tests {
117
117
assert_eq ! (
118
118
msg,
119
119
LSPSMessage :: LSPS0 ( LSPS0Message :: Request (
120
- RequestId ( "request:id:xyz123" . to_string( ) ) ,
121
- LSPS0Request :: ListProtocols ( ListProtocolsRequest { } )
120
+ LSPSRequestId ( "request:id:xyz123" . to_string( ) ) ,
121
+ LSPS0Request :: ListProtocols ( LSPS0ListProtocolsRequest { } )
122
122
) )
123
123
) ;
124
124
}
125
125
126
126
#[ test]
127
127
fn serializes_request ( ) {
128
128
let request = LSPSMessage :: LSPS0 ( LSPS0Message :: Request (
129
- RequestId ( "request:id:xyz123" . to_string ( ) ) ,
130
- LSPS0Request :: ListProtocols ( ListProtocolsRequest { } ) ,
129
+ LSPSRequestId ( "request:id:xyz123" . to_string ( ) ) ,
130
+ LSPS0Request :: ListProtocols ( LSPS0ListProtocolsRequest { } ) ,
131
131
) ) ;
132
132
let json = serde_json:: to_string ( & request) . unwrap ( ) ;
133
133
assert_eq ! (
@@ -147,16 +147,18 @@ mod tests {
147
147
}"# ;
148
148
let mut request_id_to_method_map = new_hash_map ( ) ;
149
149
request_id_to_method_map
150
- . insert ( RequestId ( "request:id:xyz123" . to_string ( ) ) , LSPSMethod :: LSPS0ListProtocols ) ;
150
+ . insert ( LSPSRequestId ( "request:id:xyz123" . to_string ( ) ) , LSPSMethod :: LSPS0ListProtocols ) ;
151
151
152
152
let response =
153
153
LSPSMessage :: from_str_with_id_map ( json, & mut request_id_to_method_map) . unwrap ( ) ;
154
154
155
155
assert_eq ! (
156
156
response,
157
157
LSPSMessage :: LSPS0 ( LSPS0Message :: Response (
158
- RequestId ( "request:id:xyz123" . to_string( ) ) ,
159
- LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols: vec![ 1 , 2 , 3 ] } )
158
+ LSPSRequestId ( "request:id:xyz123" . to_string( ) ) ,
159
+ LSPS0Response :: ListProtocols ( LSPS0ListProtocolsResponse {
160
+ protocols: vec![ 1 , 2 , 3 ]
161
+ } )
160
162
) )
161
163
) ;
162
164
}
@@ -173,16 +175,16 @@ mod tests {
173
175
}"# ;
174
176
let mut request_id_to_method_map = new_hash_map ( ) ;
175
177
request_id_to_method_map
176
- . insert ( RequestId ( "request:id:xyz123" . to_string ( ) ) , LSPSMethod :: LSPS0ListProtocols ) ;
178
+ . insert ( LSPSRequestId ( "request:id:xyz123" . to_string ( ) ) , LSPSMethod :: LSPS0ListProtocols ) ;
177
179
178
180
let response =
179
181
LSPSMessage :: from_str_with_id_map ( json, & mut request_id_to_method_map) . unwrap ( ) ;
180
182
181
183
assert_eq ! (
182
184
response,
183
185
LSPSMessage :: LSPS0 ( LSPS0Message :: Response (
184
- RequestId ( "request:id:xyz123" . to_string( ) ) ,
185
- LSPS0Response :: ListProtocolsError ( ResponseError {
186
+ LSPSRequestId ( "request:id:xyz123" . to_string( ) ) ,
187
+ LSPS0Response :: ListProtocolsError ( LSPSResponseError {
186
188
code: -32617 ,
187
189
message: "Unknown Error" . to_string( ) ,
188
190
data: None
@@ -202,7 +204,7 @@ mod tests {
202
204
}"# ;
203
205
let mut request_id_to_method_map = new_hash_map ( ) ;
204
206
request_id_to_method_map
205
- . insert ( RequestId ( "request:id:xyz123" . to_string ( ) ) , LSPSMethod :: LSPS0ListProtocols ) ;
207
+ . insert ( LSPSRequestId ( "request:id:xyz123" . to_string ( ) ) , LSPSMethod :: LSPS0ListProtocols ) ;
206
208
207
209
let response = LSPSMessage :: from_str_with_id_map ( json, & mut request_id_to_method_map) ;
208
210
assert ! ( response. is_err( ) ) ;
@@ -211,8 +213,8 @@ mod tests {
211
213
#[ test]
212
214
fn serializes_response ( ) {
213
215
let response = LSPSMessage :: LSPS0 ( LSPS0Message :: Response (
214
- RequestId ( "request:id:xyz123" . to_string ( ) ) ,
215
- LSPS0Response :: ListProtocols ( ListProtocolsResponse { protocols : vec ! [ 1 , 2 , 3 ] } ) ,
216
+ LSPSRequestId ( "request:id:xyz123" . to_string ( ) ) ,
217
+ LSPS0Response :: ListProtocols ( LSPS0ListProtocolsResponse { protocols : vec ! [ 1 , 2 , 3 ] } ) ,
216
218
) ) ;
217
219
let json = serde_json:: to_string ( & response) . unwrap ( ) ;
218
220
assert_eq ! (
0 commit comments