Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 12a0b11

Browse files
committed
LSPS1 service: Drop enqueue_response helper
.. as tiny helpers like this just tend to obfuscate what's going on.
1 parent 64d69e4 commit 12a0b11

File tree

1 file changed

+36
-48
lines changed

1 file changed

+36
-48
lines changed

src/lsps1/service.rs

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ where
170170
fn handle_get_info_request(
171171
&self, request_id: RequestId, counterparty_node_id: &PublicKey,
172172
) -> Result<(), LightningError> {
173-
let response = GetInfoResponse {
173+
let response = LSPS1Response::GetInfo(GetInfoResponse {
174174
website: self.config.website.clone().unwrap().to_string(),
175175
options: self
176176
.config
@@ -181,28 +181,27 @@ where
181181
action: ErrorAction::IgnoreAndLog(Level::Info),
182182
})
183183
.unwrap(),
184-
};
184+
});
185185

186-
self.enqueue_response(counterparty_node_id, request_id, LSPS1Response::GetInfo(response));
186+
let msg = LSPS1Message::Response(request_id, response).into();
187+
self.pending_messages.enqueue(counterparty_node_id, msg);
187188
Ok(())
188189
}
189190

190191
fn handle_create_order_request(
191192
&self, request_id: RequestId, counterparty_node_id: &PublicKey, params: CreateOrderRequest,
192193
) -> Result<(), LightningError> {
193194
if !is_valid(&params.order, &self.config.options_supported.as_ref().unwrap()) {
194-
self.enqueue_response(
195-
counterparty_node_id,
196-
request_id,
197-
LSPS1Response::CreateOrderError(ResponseError {
198-
code: LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
199-
message: format!("Order does not match options supported by LSP server"),
200-
data: Some(format!(
201-
"Supported options are {:?}",
202-
&self.config.options_supported.as_ref().unwrap()
203-
)),
204-
}),
205-
);
195+
let response = LSPS1Response::CreateOrderError(ResponseError {
196+
code: LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE,
197+
message: format!("Order does not match options supported by LSP server"),
198+
data: Some(format!(
199+
"Supported options are {:?}",
200+
&self.config.options_supported.as_ref().unwrap()
201+
)),
202+
});
203+
let msg = LSPS1Message::Response(request_id, response).into();
204+
self.pending_messages.enqueue(counterparty_node_id, msg);
206205
return Err(LightningError {
207206
err: format!(
208207
"Client order does not match any supported options: {:?}",
@@ -262,19 +261,17 @@ where
262261

263262
peer_state_lock.insert_outbound_channel(order_id.clone(), channel);
264263

265-
self.enqueue_response(
266-
counterparty_node_id,
267-
request_id,
268-
LSPS1Response::CreateOrder(CreateOrderResponse {
269-
order: params.order,
270-
order_id,
271-
order_state: OrderState::Created,
272-
created_at,
273-
expires_at,
274-
payment,
275-
channel: None,
276-
}),
277-
);
264+
let response = LSPS1Response::CreateOrder(CreateOrderResponse {
265+
order: params.order,
266+
order_id,
267+
order_state: OrderState::Created,
268+
created_at,
269+
expires_at,
270+
payment,
271+
channel: None,
272+
});
273+
let msg = LSPS1Message::Response(request_id, response).into();
274+
self.pending_messages.enqueue(counterparty_node_id, msg);
278275
},
279276

280277
_ => {
@@ -372,19 +369,17 @@ where
372369
{
373370
let config = &outbound_channel.config;
374371

375-
self.enqueue_response(
376-
&counterparty_node_id,
377-
request_id,
378-
LSPS1Response::GetOrder(CreateOrderResponse {
379-
order_id,
380-
order: config.order.clone(),
381-
order_state,
382-
created_at: config.created_at,
383-
expires_at: config.expires_at,
384-
payment: config.payment.clone(),
385-
channel,
386-
}),
387-
)
372+
let response = LSPS1Response::GetOrder(CreateOrderResponse {
373+
order_id,
374+
order: config.order.clone(),
375+
order_state,
376+
created_at: config.created_at,
377+
expires_at: config.expires_at,
378+
payment: config.payment.clone(),
379+
channel,
380+
});
381+
let msg = LSPS1Message::Response(request_id, response).into();
382+
self.pending_messages.enqueue(&counterparty_node_id, msg);
388383
} else {
389384
return Err(APIError::APIMisuseError {
390385
err: format!("Channel with order_id {} not found", order_id.0),
@@ -400,13 +395,6 @@ where
400395
Ok(())
401396
}
402397

403-
fn enqueue_response(
404-
&self, counterparty_node_id: &PublicKey, request_id: RequestId, response: LSPS1Response,
405-
) {
406-
self.pending_messages
407-
.enqueue(counterparty_node_id, LSPS1Message::Response(request_id, response).into());
408-
}
409-
410398
fn generate_order_id(&self) -> OrderId {
411399
let bytes = self.entropy_source.get_secure_random_bytes();
412400
OrderId(utils::hex_str(&bytes[0..16]))

0 commit comments

Comments
 (0)