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

Commit 427965d

Browse files
committed
Cleanup API names in LSPS2 client flow
In order to make the API flow a bit more intuitive, we rename the corresponding methods and events: - `create_invoice` -> `request_opening_params` - `opening_fee_params_selected` -> `select_opening_params` - `LSPS2ClientEvent::GetInfoResponse` -> `OpeningParametersReady` - `LSPS2ClientEvent::InvoiceGenerationReady` -> `InvoiceParametersReady` We also cleanup the docs a bit.
1 parent 51e7f90 commit 427965d

File tree

2 files changed

+49
-30
lines changed

2 files changed

+49
-30
lines changed

src/lsps2/client.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,26 @@ where
203203
}
204204
}
205205

206-
/// Initiate the creation of an invoice that when paid will open a channel
207-
/// with enough inbound liquidity to be able to receive the payment.
206+
/// Request the channel opening parameters from the LSP.
208207
///
209-
/// `counterparty_node_id` is the node_id of the LSP you would like to use.
208+
/// This initiates the JIT-channel flow that, at the end of it, will have the LSP
209+
/// open a channel with sufficient inbound liquidity to be able to receive the payment.
210+
///
211+
/// The user will receive the LSP's response via an [`OpeningParametersReady`] event.
212+
///
213+
/// `counterparty_node_id` is the `node_id` of the LSP you would like to use.
210214
///
211215
/// If `payment_size_msat` is [`Option::Some`] then the invoice will be for a fixed amount
212216
/// and MPP can be used to pay it.
213217
///
214218
/// If `payment_size_msat` is [`Option::None`] then the invoice can be for an arbitrary amount
215219
/// but MPP can no longer be used to pay it.
216220
///
217-
/// `token` is an optional String that will be provided to the LSP.
221+
/// `token` is an optional `String` that will be provided to the LSP.
218222
/// It can be used by the LSP as an API key, coupon code, or some other way to identify a user.
219-
pub fn create_invoice(
223+
///
224+
/// [`OpeningParametersReady`]: crate::lsps2::event::LSPS2ClientEvent::OpeningParametersReady
225+
pub fn request_opening_params(
220226
&self, counterparty_node_id: PublicKey, payment_size_msat: Option<u64>,
221227
token: Option<String>, user_channel_id: u128,
222228
) {
@@ -239,14 +245,19 @@ where
239245
);
240246
}
241247

242-
/// Used by client to confirm which channel parameters to use for the JIT Channel buy request.
248+
/// Confirms a set of chosen channel opening parameters to use for the JIT channel and
249+
/// requests the necessary invoice generation parameters from the LSP.
250+
///
251+
/// Should be called in response to receiving a [`OpeningParametersReady`] event.
252+
///
253+
/// The user will receive the LSP's response via an [`InvoiceParametersReady`] event.
254+
///
243255
/// The client agrees to paying an opening fee equal to
244256
/// `max(min_fee_msat, proportional*(payment_size_msat/1_000_000))`.
245257
///
246-
/// Should be called in response to receiving a [`LSPS2ClientEvent::GetInfoResponse`] event.
247-
///
248-
/// [`LSPS2ClientEvent::GetInfoResponse`]: crate::lsps2::event::LSPS2ClientEvent::GetInfoResponse
249-
pub fn opening_fee_params_selected(
258+
/// [`OpeningParametersReady`]: crate::lsps2::event::LSPS2ClientEvent::OpeningParametersReady
259+
/// [`InvoiceParametersReady`]: crate::lsps2::event::LSPS2ClientEvent::InvoiceParametersReady
260+
pub fn select_opening_params(
250261
&self, counterparty_node_id: PublicKey, jit_channel_id: u128,
251262
opening_fee_params: OpeningFeeParams,
252263
) -> Result<(), APIError> {
@@ -334,7 +345,7 @@ where
334345
}
335346

336347
self.pending_events.enqueue(Event::LSPS2Client(
337-
LSPS2ClientEvent::GetInfoResponse {
348+
LSPS2ClientEvent::OpeningParametersReady {
338349
counterparty_node_id: *counterparty_node_id,
339350
opening_fee_params_menu: result.opening_fee_params_menu,
340351
min_payment_size_msat: result.min_payment_size_msat,
@@ -442,7 +453,7 @@ where
442453

443454
if let Ok(intercept_scid) = result.intercept_scid.to_scid() {
444455
self.pending_events.enqueue(Event::LSPS2Client(
445-
LSPS2ClientEvent::InvoiceGenerationReady {
456+
LSPS2ClientEvent::InvoiceParametersReady {
446457
counterparty_node_id: *counterparty_node_id,
447458
intercept_scid,
448459
cltv_expiry_delta: result.lsp_cltv_expiry_delta,

src/lsps2/event.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@ use bitcoin::secp256k1::PublicKey;
2020
pub enum LSPS2ClientEvent {
2121
/// Information from the LSP about their current fee rates and channel parameters.
2222
///
23-
/// You must call [`LSPS2ClientHandler::opening_fee_params_selected`] with the fee parameter
23+
/// You must call [`LSPS2ClientHandler::select_opening_params`] with the fee parameter
2424
/// you want to use if you wish to proceed opening a channel.
2525
///
26-
/// [`LSPS2ClientHandler::opening_fee_params_selected`]: crate::lsps2::client::LSPS2ClientHandler::opening_fee_params_selected
27-
GetInfoResponse {
26+
/// [`LSPS2ClientHandler::select_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::select_opening_params
27+
OpeningParametersReady {
28+
/// A user-specified identifier used to track the channel open.
29+
///
30+
/// This is the same value as previously passed to
31+
/// [`LSPS2ClientHandler::request_opening_params`].
32+
///
33+
/// [`LSPS2ClientHandler::request_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::request_opening_params
34+
user_channel_id: u128,
2835
/// This is a randomly generated identifier used to track the JIT channel state.
29-
/// It is not related in anyway to the eventual lightning channel id.
30-
/// It needs to be passed to [`LSPS2ClientHandler::opening_fee_params_selected`].
3136
///
32-
/// [`LSPS2ClientHandler::opening_fee_params_selected`]: crate::lsps2::client::LSPS2ClientHandler::opening_fee_params_selected
37+
/// It is not related in anyway to the eventual lightning channel id, but needs to be
38+
/// given to [`LSPS2ClientHandler::select_opening_params`].
39+
///
40+
/// [`LSPS2ClientHandler::select_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::select_opening_params
3341
jit_channel_id: u128,
3442
/// The node id of the LSP that provided this response.
3543
counterparty_node_id: PublicKey,
@@ -40,16 +48,20 @@ pub enum LSPS2ClientEvent {
4048
min_payment_size_msat: u64,
4149
/// The max payment size allowed when opening the channel.
4250
max_payment_size_msat: u64,
43-
/// The user_channel_id value passed in to [`LSPS2ClientHandler::create_invoice`].
44-
///
45-
/// [`LSPS2ClientHandler::create_invoice`]: crate::lsps2::client::LSPS2ClientHandler::create_invoice
46-
user_channel_id: u128,
4751
},
48-
/// Use the provided fields to generate an invoice and give to payer.
52+
/// Provides the necessary information to generate a payable invoice that then may be given to
53+
/// the payer.
4954
///
50-
/// When the invoice is paid the LSP will open a channel to you
51-
/// with the previously agreed upon parameters.
52-
InvoiceGenerationReady {
55+
/// When the invoice is paid, the LSP will open a channel with the previously agreed upon
56+
/// parameters to you.
57+
InvoiceParametersReady {
58+
/// A user-specified identifier used to track the channel open.
59+
///
60+
/// This is the same value as previously passed to
61+
/// [`LSPS2ClientHandler::select_opening_params`].
62+
///
63+
/// [`LSPS2ClientHandler::select_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::select_opening_params
64+
user_channel_id: u128,
5365
/// The node id of the LSP.
5466
counterparty_node_id: PublicKey,
5567
/// The intercept short channel id to use in the route hint.
@@ -58,10 +70,6 @@ pub enum LSPS2ClientEvent {
5870
cltv_expiry_delta: u32,
5971
/// The initial payment size you specified.
6072
payment_size_msat: Option<u64>,
61-
/// The `user_channel_id` value passed in to [`LSPS2ClientHandler::create_invoice`].
62-
///
63-
/// [`LSPS2ClientHandler::create_invoice`]: crate::lsps2::client::LSPS2ClientHandler::create_invoice
64-
user_channel_id: u128,
6573
},
6674
}
6775

0 commit comments

Comments
 (0)