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

Commit a01069b

Browse files
committed
Return request_id from request_opening_params
.. and expose it via the corresponding event. This allows the client to track which previously-made request an event corresponds to.
1 parent 478ccf9 commit a01069b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/lsps2/client.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ where
155155
/// `token` is an optional `String` that will be provided to the LSP.
156156
/// It can be used by the LSP as an API key, coupon code, or some other way to identify a user.
157157
///
158+
/// Returns the used [`RequestId`], which will be returned via [`OpeningParametersReady`].
159+
///
158160
/// [`OpeningParametersReady`]: crate::lsps2::event::LSPS2ClientEvent::OpeningParametersReady
159-
pub fn request_opening_params(&self, counterparty_node_id: PublicKey, token: Option<String>) {
161+
pub fn request_opening_params(
162+
&self, counterparty_node_id: PublicKey, token: Option<String>,
163+
) -> RequestId {
160164
let request_id = crate::utils::generate_request_id(&self.entropy_source);
161165

162166
{
@@ -170,9 +174,14 @@ where
170174

171175
self.pending_messages.enqueue(
172176
&counterparty_node_id,
173-
LSPS2Message::Request(request_id, LSPS2Request::GetInfo(GetInfoRequest { token }))
174-
.into(),
177+
LSPS2Message::Request(
178+
request_id.clone(),
179+
LSPS2Request::GetInfo(GetInfoRequest { token }),
180+
)
181+
.into(),
175182
);
183+
184+
request_id
176185
}
177186

178187
/// Confirms a set of chosen channel opening parameters to use for the JIT channel and
@@ -249,6 +258,7 @@ where
249258

250259
self.pending_events.enqueue(Event::LSPS2Client(
251260
LSPS2ClientEvent::OpeningParametersReady {
261+
request_id,
252262
counterparty_node_id: *counterparty_node_id,
253263
opening_fee_params_menu: result.opening_fee_params_menu,
254264
min_payment_size_msat: result.min_payment_size_msat,

src/lsps2/event.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ pub enum LSPS2ClientEvent {
2525
///
2626
/// [`LSPS2ClientHandler::select_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::select_opening_params
2727
OpeningParametersReady {
28+
/// The identifier of the issued LSPS2 `get_info` request, as returned by
29+
/// [`LSPS2ClientHandler::request_opening_params`]
30+
///
31+
/// This can be used to track which request this event corresponds to.
32+
///
33+
/// [`LSPS2ClientHandler::request_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::request_opening_params
34+
request_id: RequestId,
2835
/// The node id of the LSP that provided this response.
2936
counterparty_node_id: PublicKey,
3037
/// The menu of fee parameters the LSP is offering at this time.

0 commit comments

Comments
 (0)