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

Commit 832b0b3

Browse files
authored
Improve documentation for LSPS1 (#77)
* Added doc for lsps1/events * Added docs for pub fn in lsps1 * LSPS1 doc fixes
1 parent 5e0076c commit 832b0b3

File tree

3 files changed

+110
-29
lines changed

3 files changed

+110
-29
lines changed

src/lsps1/client.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ where
221221
C::Target: Filter,
222222
ES::Target: EntropySource,
223223
{
224+
/// Constructs an `LSPS1ClientHandler`.
224225
pub(crate) fn new(
225226
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
226227
channel_manager: CM, chain_source: Option<C>, config: LSPS1ClientConfig,
@@ -236,7 +237,12 @@ where
236237
}
237238
}
238239

239-
fn request_for_info(&self, counterparty_node_id: PublicKey, channel_id: u128) {
240+
/// Retrieve information from the LSP regarding the options supported.
241+
///
242+
/// `counterparty_node_id` is the node_id of the LSP you would like to use.
243+
///
244+
/// 'channel_id' is the id used to uniquely identify the channel with counterparty node.
245+
pub fn request_for_info(&self, counterparty_node_id: PublicKey, channel_id: u128) {
240246
let channel = InboundCRChannel::new(channel_id);
241247

242248
let mut outer_state_lock = self.per_peer_state.write().unwrap();
@@ -313,7 +319,13 @@ where
313319
Ok(())
314320
}
315321

316-
fn place_order(
322+
/// Places an order with the connected LSP given its `counterparty_node_id`.
323+
/// The client agrees to paying channel fees according to the provided parameters.
324+
///
325+
/// Should be called in response to receiving a [`LSPS1ClientEvent::GetInfoResponse`] event.
326+
///
327+
/// [`LSPS1ClientEvent::GetInfoResponse`]: crate::lsps1::event::LSPS1ClientEvent::GetInfoResponse
328+
pub fn place_order(
317329
&self, channel_id: u128, counterparty_node_id: &PublicKey, order: OrderParams,
318330
) -> Result<(), APIError> {
319331
let outer_state_lock = self.per_peer_state.write().unwrap();
@@ -466,7 +478,12 @@ where
466478
}
467479
}
468480

469-
fn check_order_status(
481+
/// Queries the status of a pending payment, i.e., whether a payment has been received by the LSP.
482+
///
483+
/// Should be called in response to receiving a [`LSPS1ClientEvent::DisplayOrder`] event.
484+
///
485+
/// [`LSPS1ClientEvent::DisplayOrder`]: crate::lsps1::event::LSPS1ClientEvent::DisplayOrder
486+
pub fn check_order_status(
470487
&self, counterparty_node_id: &PublicKey, order_id: OrderId, channel_id: u128,
471488
) -> Result<(), APIError> {
472489
let outer_state_lock = self.per_peer_state.write().unwrap();

src/lsps1/event.rs

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
110
//! Contains LSPS1 event types
211
312
use super::msgs::{ChannelInfo, OptionsSupported, OrderId, OrderParams, OrderPayment};
@@ -10,62 +19,103 @@ use bitcoin::secp256k1::PublicKey;
1019
/// An event which an LSPS1 client should take some action in response to.
1120
#[derive(Clone, Debug, PartialEq, Eq)]
1221
pub enum LSPS1ClientEvent {
13-
/// TODO
22+
/// Information from the LSP about their supported protocol options.
23+
///
24+
/// You must check whether LSP supports the parameters the client wants and then call
25+
/// [`LSPS1ClientHandler::place_order`] to place an order.
26+
///
27+
/// [`LSPS1ClientHandler::place_order`]: crate::lsps1::client::LSPS1ClientHandler::place_order
1428
GetInfoResponse {
15-
/// TODO
29+
/// This is a randomly generated identifier used to track the channel state.
30+
///
31+
/// It is not related in anyway to the eventual lightning channel id.
32+
/// It needs to be passed to [`LSPS1ClientHandler::place_order`].
33+
///
34+
/// [`LSPS1ClientHandler::place_order`]: crate::lsps1::client::LSPS1ClientHandler::place_order
1635
id: u128,
17-
/// TODO
36+
/// An identifier to track messages received.
1837
request_id: RequestId,
19-
/// TODO
38+
/// The node id of the LSP that provided this response.
2039
counterparty_node_id: PublicKey,
21-
/// TODO
40+
/// The website of the LSP.
2241
website: String,
23-
/// TODO
42+
/// All options supported by the LSP.
2443
options_supported: OptionsSupported,
2544
},
26-
/// TODO
45+
/// Confirmation from the LSP about the order created by the client.
46+
///
47+
/// When the payment is confirmed, the LSP will open a channel to you
48+
/// with the below agreed upon parameters.
49+
///
50+
/// You must pay the invoice if you want to continue and then
51+
/// call [`LSPS1ClientHandler::check_order_status`] with the order id
52+
/// to get information from LSP about progress of the order.
53+
///
54+
/// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
2755
DisplayOrder {
28-
/// TODO
56+
/// This is a randomly generated identifier used to track the channel state.
57+
/// It is not related in anyway to the eventual lightning channel id.
58+
/// It needs to be passed to [`LSPS1ClientHandler::check_order_status`].
59+
///
60+
/// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
2961
id: u128,
30-
/// TODO
62+
/// The node id of the LSP.
3163
counterparty_node_id: PublicKey,
32-
/// TODO
64+
/// The order created by client and approved by LSP.
3365
order: OrderParams,
34-
/// TODO
66+
/// The details regarding payment of the order
3567
payment: OrderPayment,
36-
/// TODO
68+
/// The details regarding state of the channel ordered.
3769
channel: Option<ChannelInfo>,
3870
},
3971
}
4072

4173
/// An event which an LSPS1 server should take some action in response to.
4274
#[derive(Clone, Debug, PartialEq, Eq)]
4375
pub enum LSPS1ServiceEvent {
44-
/// TODO
76+
/// A client has selected the parameters to use from the supported options of the LSP
77+
/// and would like to open a channel with the given payment parameters.
78+
///
79+
/// You must call [`LSPS1ServiceHandler::send_invoice_for_order`] to
80+
/// generate a complete invoice including the details regarding the
81+
/// payment and order id for this order for the client.
82+
///
83+
/// [`LSPS1ServiceHandler::send_invoice_for_order`]: crate::lsps1::service::LSPS1ServiceHandler::send_invoice_for_order
4584
CreateInvoice {
46-
/// TODO
85+
/// An identifier that must be passed to [`LSPS1ServiceHandler::send_invoice_for_order`].
86+
///
87+
/// [`LSPS1ServiceHandler::send_invoice_for_order`]: crate::lsps1::service::LSPS1ServiceHandler::send_invoice_for_order
4788
request_id: RequestId,
48-
/// TODO
89+
/// The node id of the client making the information request.
4990
counterparty_node_id: PublicKey,
50-
/// TODO
91+
/// The order requested by the client.
5192
order: OrderParams,
5293
},
53-
/// TODO
94+
/// A request from client to check the status of the payment.
95+
///
96+
/// An event to poll for checking payment status either onchain or lightning.
97+
///
98+
/// You must call [`LSPS1ServiceHandler::update_order_status`] to update the client
99+
/// regarding the status of the payment and order.
100+
///
101+
/// [`LSPS1ServiceHandler::update_order_status`]: crate::lsps1::service::LSPS1ServiceHandler::update_order_status
54102
CheckPaymentConfirmation {
55-
/// TODO
103+
/// An identifier that must be passed to [`LSPS1ServiceHandler::update_order_status`].
104+
///
105+
/// [`LSPS1ServiceHandler::update_order_status`]: crate::lsps1::service::LSPS1ServiceHandler::update_order_status
56106
request_id: RequestId,
57-
/// TODO
107+
/// The node id of the client making the information request.
58108
counterparty_node_id: PublicKey,
59-
/// TODO
109+
/// The order id of order with pending payment.
60110
order_id: OrderId,
61111
},
62-
/// TODO
112+
/// If error is encountered, refund the amount if paid by the client.
63113
Refund {
64-
/// TODO
114+
/// An identifier.
65115
request_id: RequestId,
66-
/// TODO
116+
/// The node id of the client making the information request.
67117
counterparty_node_id: PublicKey,
68-
/// TODO
118+
/// The order id of the refunded order.
69119
order_id: OrderId,
70120
},
71121
}

src/lsps1/service.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ where
152152
C::Target: Filter,
153153
ES::Target: EntropySource,
154154
{
155+
/// Constructs a `LSPS1ServiceHandler`.
155156
pub(crate) fn new(
156157
entropy_source: ES, pending_messages: Arc<MessageQueue>, pending_events: Arc<EventQueue>,
157158
channel_manager: CM, chain_source: Option<C>, config: LSPS1ServiceConfig,
@@ -232,7 +233,12 @@ where
232233
Ok(())
233234
}
234235

235-
fn send_invoice_for_order(
236+
/// Used by LSP to send invoice containing details regarding the channel fees and payment information.
237+
///
238+
/// Should be called in response to receiving a [`LSPS1ServiceEvent::CreateInvoice`] event.
239+
///
240+
/// [`LSPS1ServiceEvent::CreateInvoice`]: crate::lsps1::event::LSPS1ServiceEvent::CreateInvoice
241+
pub fn send_invoice_for_order(
236242
&self, request_id: RequestId, counterparty_node_id: &PublicKey, payment: OrderPayment,
237243
created_at: chrono::DateTime<Utc>, expires_at: chrono::DateTime<Utc>,
238244
) -> Result<(), APIError> {
@@ -342,7 +348,15 @@ where
342348
Ok(())
343349
}
344350

345-
fn update_order_status(
351+
/// Used by LSP to give details to client regarding the status of channel opening.
352+
/// Called to respond to client's GetOrder request.
353+
/// The LSP continously polls for checking payment confirmation on-chain or lighting
354+
/// and then responds to client request.
355+
///
356+
/// Should be called in response to receiving a [`LSPS1ServiceEvent::CheckPaymentConfirmation`] event.
357+
///
358+
/// [`LSPS1ServiceEvent::CheckPaymentConfirmation`]: crate::lsps1::event::LSPS1ServiceEvent::CheckPaymentConfirmation
359+
pub fn update_order_status(
346360
&self, request_id: RequestId, counterparty_node_id: PublicKey, order_id: OrderId,
347361
order_state: OrderState, channel: Option<ChannelInfo>,
348362
) -> Result<(), APIError> {

0 commit comments

Comments
 (0)