Skip to content

Commit 8526b9f

Browse files
committed
Prefix general LSPS message types to avoid naming collisions
1 parent cfc636c commit 8526b9f

File tree

14 files changed

+143
-136
lines changed

14 files changed

+143
-136
lines changed

lightning-liquidity/src/lsps0/client.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::lsps0::msgs::{
1010
LSPS0ListProtocolsRequest, LSPS0ListProtocolsResponse, LSPS0Message, LSPS0Request,
1111
LSPS0Response,
1212
};
13-
use crate::lsps0::ser::{ProtocolMessageHandler, ResponseError};
13+
use crate::lsps0::ser::{LSPSProtocolMessageHandler, LSPSResponseError};
1414
use crate::message_queue::MessageQueue;
1515
use crate::sync::Arc;
1616
use crate::utils;
@@ -69,20 +69,20 @@ where
6969
});
7070
Ok(())
7171
},
72-
LSPS0Response::ListProtocolsError(ResponseError { code, message, data, .. }) => {
73-
Err(LightningError {
74-
err: format!(
75-
"ListProtocols error received. code = {}, message = {}, data = {:?}",
76-
code, message, data
77-
),
78-
action: ErrorAction::IgnoreAndLog(Level::Info),
79-
})
80-
},
72+
LSPS0Response::ListProtocolsError(LSPSResponseError {
73+
code, message, data, ..
74+
}) => Err(LightningError {
75+
err: format!(
76+
"ListProtocols error received. code = {}, message = {}, data = {:?}",
77+
code, message, data
78+
),
79+
action: ErrorAction::IgnoreAndLog(Level::Info),
80+
}),
8181
}
8282
}
8383
}
8484

85-
impl<ES: Deref> ProtocolMessageHandler for LSPS0ClientHandler<ES>
85+
impl<ES: Deref> LSPSProtocolMessageHandler for LSPS0ClientHandler<ES>
8686
where
8787
ES::Target: EntropySource,
8888
{
@@ -113,7 +113,7 @@ mod tests {
113113
use alloc::string::ToString;
114114
use alloc::sync::Arc;
115115

116-
use crate::lsps0::ser::{LSPSMessage, RequestId};
116+
use crate::lsps0::ser::{LSPSMessage, LSPSRequestId};
117117
use crate::tests::utils::{self, TestEntropy};
118118

119119
use super::*;
@@ -146,7 +146,7 @@ mod tests {
146146
assert_eq!(
147147
*message,
148148
LSPSMessage::LSPS0(LSPS0Message::Request(
149-
RequestId("00000000000000000000000000000000".to_string()),
149+
LSPSRequestId("00000000000000000000000000000000".to_string()),
150150
LSPS0Request::ListProtocols(LSPS0ListProtocolsRequest {})
151151
))
152152
);

lightning-liquidity/src/lsps0/msgs.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Message, request, and other primitive types used to implement LSPS0.
22
3-
use crate::lsps0::ser::{LSPSMessage, RequestId, ResponseError};
3+
use crate::lsps0::ser::{LSPSMessage, LSPSRequestId, LSPSResponseError};
44
use crate::prelude::Vec;
55

66
use serde::{Deserialize, Serialize};
@@ -58,7 +58,7 @@ pub enum LSPS0Response {
5858
/// A response to a `list_protocols` request.
5959
ListProtocols(LSPS0ListProtocolsResponse),
6060
/// An error response to a `list_protocols` request.
61-
ListProtocolsError(ResponseError),
61+
ListProtocolsError(LSPSResponseError),
6262
}
6363

6464
/// An bLIP-50 / LSPS0 protocol message.
@@ -69,9 +69,9 @@ pub enum LSPS0Response {
6969
#[derive(Clone, Debug, PartialEq, Eq)]
7070
pub enum LSPS0Message {
7171
/// A request variant.
72-
Request(RequestId, LSPS0Request),
72+
Request(LSPSRequestId, LSPS0Request),
7373
/// A response variant.
74-
Response(RequestId, LSPS0Response),
74+
Response(LSPSRequestId, LSPS0Response),
7575
}
7676

7777
impl TryFrom<LSPSMessage> for LSPS0Message {
@@ -117,7 +117,7 @@ mod tests {
117117
assert_eq!(
118118
msg,
119119
LSPSMessage::LSPS0(LSPS0Message::Request(
120-
RequestId("request:id:xyz123".to_string()),
120+
LSPSRequestId("request:id:xyz123".to_string()),
121121
LSPS0Request::ListProtocols(LSPS0ListProtocolsRequest {})
122122
))
123123
);
@@ -126,7 +126,7 @@ mod tests {
126126
#[test]
127127
fn serializes_request() {
128128
let request = LSPSMessage::LSPS0(LSPS0Message::Request(
129-
RequestId("request:id:xyz123".to_string()),
129+
LSPSRequestId("request:id:xyz123".to_string()),
130130
LSPS0Request::ListProtocols(LSPS0ListProtocolsRequest {}),
131131
));
132132
let json = serde_json::to_string(&request).unwrap();
@@ -147,15 +147,15 @@ mod tests {
147147
}"#;
148148
let mut request_id_to_method_map = new_hash_map();
149149
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);
151151

152152
let response =
153153
LSPSMessage::from_str_with_id_map(json, &mut request_id_to_method_map).unwrap();
154154

155155
assert_eq!(
156156
response,
157157
LSPSMessage::LSPS0(LSPS0Message::Response(
158-
RequestId("request:id:xyz123".to_string()),
158+
LSPSRequestId("request:id:xyz123".to_string()),
159159
LSPS0Response::ListProtocols(LSPS0ListProtocolsResponse {
160160
protocols: vec![1, 2, 3]
161161
})
@@ -175,16 +175,16 @@ mod tests {
175175
}"#;
176176
let mut request_id_to_method_map = new_hash_map();
177177
request_id_to_method_map
178-
.insert(RequestId("request:id:xyz123".to_string()), LSPSMethod::LSPS0ListProtocols);
178+
.insert(LSPSRequestId("request:id:xyz123".to_string()), LSPSMethod::LSPS0ListProtocols);
179179

180180
let response =
181181
LSPSMessage::from_str_with_id_map(json, &mut request_id_to_method_map).unwrap();
182182

183183
assert_eq!(
184184
response,
185185
LSPSMessage::LSPS0(LSPS0Message::Response(
186-
RequestId("request:id:xyz123".to_string()),
187-
LSPS0Response::ListProtocolsError(ResponseError {
186+
LSPSRequestId("request:id:xyz123".to_string()),
187+
LSPS0Response::ListProtocolsError(LSPSResponseError {
188188
code: -32617,
189189
message: "Unknown Error".to_string(),
190190
data: None
@@ -204,7 +204,7 @@ mod tests {
204204
}"#;
205205
let mut request_id_to_method_map = new_hash_map();
206206
request_id_to_method_map
207-
.insert(RequestId("request:id:xyz123".to_string()), LSPSMethod::LSPS0ListProtocols);
207+
.insert(LSPSRequestId("request:id:xyz123".to_string()), LSPSMethod::LSPS0ListProtocols);
208208

209209
let response = LSPSMessage::from_str_with_id_map(json, &mut request_id_to_method_map);
210210
assert!(response.is_err());
@@ -213,7 +213,7 @@ mod tests {
213213
#[test]
214214
fn serializes_response() {
215215
let response = LSPSMessage::LSPS0(LSPS0Message::Response(
216-
RequestId("request:id:xyz123".to_string()),
216+
LSPSRequestId("request:id:xyz123".to_string()),
217217
LSPS0Response::ListProtocols(LSPS0ListProtocolsResponse { protocols: vec![1, 2, 3] }),
218218
));
219219
let json = serde_json::to_string(&response).unwrap();

lightning-liquidity/src/lsps0/ser.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub const LSPS_MESSAGE_TYPE_ID: u16 = 37913;
138138
///
139139
/// The messages the protocol uses need to be able to be mapped
140140
/// from and into [`LSPSMessage`].
141-
pub(crate) trait ProtocolMessageHandler {
141+
pub(crate) trait LSPSProtocolMessageHandler {
142142
type ProtocolMessage: TryFrom<LSPSMessage> + Into<LSPSMessage>;
143143
const PROTOCOL_NUMBER: Option<u16>;
144144

@@ -184,14 +184,14 @@ impl wire::Type for RawLSPSMessage {
184184
/// more information.
185185
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
186186
#[serde(transparent)]
187-
pub struct RequestId(pub String);
187+
pub struct LSPSRequestId(pub String);
188188

189189
/// An error returned in response to an JSON-RPC request.
190190
///
191191
/// Please refer to the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification#error_object) for
192192
/// more information.
193193
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
194-
pub struct ResponseError {
194+
pub struct LSPSResponseError {
195195
/// A number that indicates the error type that occurred.
196196
pub code: i32,
197197
/// A string providing a short description of the error.
@@ -204,7 +204,7 @@ pub struct ResponseError {
204204
#[derive(Clone, Debug, PartialEq, Eq)]
205205
pub enum LSPSMessage {
206206
/// An invalid variant.
207-
Invalid(ResponseError),
207+
Invalid(LSPSResponseError),
208208
/// An LSPS0 message.
209209
LSPS0(LSPS0Message),
210210
/// An LSPS1 message.
@@ -219,24 +219,24 @@ impl LSPSMessage {
219219
/// The given `request_id_to_method` associates request ids with method names, as response objects
220220
/// don't carry the latter.
221221
pub(crate) fn from_str_with_id_map(
222-
json_str: &str, request_id_to_method_map: &mut HashMap<RequestId, LSPSMethod>,
222+
json_str: &str, request_id_to_method_map: &mut HashMap<LSPSRequestId, LSPSMethod>,
223223
) -> Result<Self, serde_json::Error> {
224224
let deserializer = &mut serde_json::Deserializer::from_str(json_str);
225225
let visitor = LSPSMessageVisitor { request_id_to_method_map };
226226
deserializer.deserialize_any(visitor)
227227
}
228228

229229
/// Returns the request id and the method.
230-
pub(crate) fn get_request_id_and_method(&self) -> Option<(RequestId, LSPSMethod)> {
230+
pub(crate) fn get_request_id_and_method(&self) -> Option<(LSPSRequestId, LSPSMethod)> {
231231
match self {
232232
LSPSMessage::LSPS0(LSPS0Message::Request(request_id, request)) => {
233-
Some((RequestId(request_id.0.clone()), request.into()))
233+
Some((LSPSRequestId(request_id.0.clone()), request.into()))
234234
},
235235
LSPSMessage::LSPS1(LSPS1Message::Request(request_id, request)) => {
236-
Some((RequestId(request_id.0.clone()), request.into()))
236+
Some((LSPSRequestId(request_id.0.clone()), request.into()))
237237
},
238238
LSPSMessage::LSPS2(LSPS2Message::Request(request_id, request)) => {
239-
Some((RequestId(request_id.0.clone()), request.into()))
239+
Some((LSPSRequestId(request_id.0.clone()), request.into()))
240240
},
241241
_ => None,
242242
}
@@ -361,7 +361,7 @@ impl Serialize for LSPSMessage {
361361
}
362362

363363
struct LSPSMessageVisitor<'a> {
364-
request_id_to_method_map: &'a mut HashMap<RequestId, LSPSMethod>,
364+
request_id_to_method_map: &'a mut HashMap<LSPSRequestId, LSPSMethod>,
365365
}
366366

367367
impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
@@ -375,11 +375,11 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
375375
where
376376
A: MapAccess<'de>,
377377
{
378-
let mut id: Option<RequestId> = None;
378+
let mut id: Option<LSPSRequestId> = None;
379379
let mut method: Option<LSPSMethod> = None;
380380
let mut params = None;
381381
let mut result = None;
382-
let mut error: Option<ResponseError> = None;
382+
let mut error: Option<LSPSResponseError> = None;
383383

384384
while let Some(key) = map.next_key()? {
385385
match key {

lightning-liquidity/src/lsps0/service.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! information.
1515
1616
use crate::lsps0::msgs::{LSPS0ListProtocolsResponse, LSPS0Message, LSPS0Request, LSPS0Response};
17-
use crate::lsps0::ser::{ProtocolMessageHandler, RequestId};
17+
use crate::lsps0::ser::{LSPSProtocolMessageHandler, LSPSRequestId};
1818
use crate::message_queue::MessageQueue;
1919
use crate::prelude::Vec;
2020
use crate::sync::Arc;
@@ -37,7 +37,7 @@ impl LSPS0ServiceHandler {
3737
}
3838

3939
fn handle_request(
40-
&self, request_id: RequestId, request: LSPS0Request, counterparty_node_id: &PublicKey,
40+
&self, request_id: LSPSRequestId, request: LSPS0Request, counterparty_node_id: &PublicKey,
4141
) -> Result<(), lightning::ln::msgs::LightningError> {
4242
match request {
4343
LSPS0Request::ListProtocols(_) => {
@@ -54,7 +54,7 @@ impl LSPS0ServiceHandler {
5454
}
5555
}
5656

57-
impl ProtocolMessageHandler for LSPS0ServiceHandler {
57+
impl LSPSProtocolMessageHandler for LSPS0ServiceHandler {
5858
type ProtocolMessage = LSPS0Message;
5959
const PROTOCOL_NUMBER: Option<u16> = None;
6060

@@ -95,7 +95,7 @@ mod tests {
9595
let lsps0_handler = Arc::new(LSPS0ServiceHandler::new(protocols, pending_messages.clone()));
9696

9797
let list_protocols_request = LSPS0Message::Request(
98-
RequestId("xyz123".to_string()),
98+
LSPSRequestId("xyz123".to_string()),
9999
LSPS0Request::ListProtocols(LSPS0ListProtocolsRequest {}),
100100
);
101101
let counterparty_node_id = utils::parse_pubkey(
@@ -114,7 +114,7 @@ mod tests {
114114
assert_eq!(
115115
*message,
116116
LSPSMessage::LSPS0(LSPS0Message::Response(
117-
RequestId("xyz123".to_string()),
117+
LSPSRequestId("xyz123".to_string()),
118118
LSPS0Response::ListProtocols(LSPS0ListProtocolsResponse { protocols: vec![] })
119119
))
120120
);

0 commit comments

Comments
 (0)