Skip to content

Commit 65c4807

Browse files
fixup: LSPS5 events - Improve type safety and documentation
- Replaces raw error code/message pairs with a structured LSPS5Error type - Changes String timestamp fields to use the proper LSPSDateTime type - Improves documentation with references to MAX_APP_NAME_LENGTH constant
1 parent 1a7721b commit 65c4807

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

lightning-liquidity/src/lsps5/event.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99

1010
//! Events generated by the LSPS5 service and client
1111
12+
use crate::lsps0::ser::LSPSDateTime;
1213
use crate::lsps0::ser::LSPSRequestId;
1314
use alloc::string::String;
1415
use alloc::vec::Vec;
1516
use bitcoin::secp256k1::PublicKey;
1617

1718
use super::msgs::LSPS5AppName;
19+
use super::msgs::LSPS5Error;
1820
use super::msgs::LSPS5WebhookUrl;
1921
use super::msgs::WebhookNotification;
20-
2122
/// An event which an bLIP-55 / LSPS5 server should take some action in response to.
2223
#[derive(Debug, Clone, PartialEq, Eq)]
2324
pub enum LSPS5ServiceEvent {
@@ -28,9 +29,22 @@ pub enum LSPS5ServiceEvent {
2829
WebhookRegistered {
2930
/// Client node ID that registered the webhook
3031
counterparty_node_id: PublicKey,
31-
/// App name provided by the client (up to 64 bytes in UTF-8 format)
32+
/// App name provided by the client.
33+
///
34+
/// This app name is used to identify the webhook registration.
35+
///
36+
/// **Note**: Ensure the app name is valid and its length does not exceed [`MAX_APP_NAME_LENGTH`].
37+
///
38+
/// [`MAX_APP_NAME_LENGTH`]: super::msgs::MAX_APP_NAME_LENGTH
3239
app_name: LSPS5AppName,
33-
/// Webhook URL (HTTPS) that should be contacted to notify the client (up to 1024 ASCII characters)
40+
/// Webhook URL (HTTPS) to be contacted for notifying the client.
41+
///
42+
/// This URL is used by the LSP to send notifications.
43+
///
44+
/// **Note**: Ensure the URL is valid and its length does not exceed [`MAX_APP_NAME_LENGTH`].
45+
/// Also ensure that the URL points to a public host.
46+
///
47+
/// [`MAX_APP_NAME_LENGTH`]: super::msgs::MAX_APP_NAME_LENGTH
3448
url: LSPS5WebhookUrl,
3549
/// The identifier of the issued bLIP-55 / LSPS5 webhook registration request
3650
///
@@ -91,7 +105,7 @@ pub enum LSPS5ServiceEvent {
91105
/// Notification method with its parameters
92106
notification: WebhookNotification,
93107
/// ISO8601 timestamp of the notification (YYYY-MM-DDThh:mm:ss.uuuZ format)
94-
timestamp: String,
108+
timestamp: LSPSDateTime,
95109
/// Signature of the notification using the LSP's node ID
96110
signature: String,
97111
/// Headers to be included in the HTTP POST request
@@ -116,9 +130,9 @@ pub enum LSPS5ClientEvent {
116130
/// Whether this was an unchanged registration (same app_name and URL)
117131
/// If true, the LSP didn't send a webhook notification for this registration
118132
no_change: bool,
119-
/// The app name that was registered (up to 64 bytes in UTF-8 format)
133+
/// The app name that was registered
120134
app_name: LSPS5AppName,
121-
/// The webhook URL that was registered (HTTPS protocol)
135+
/// The webhook URL that was registered
122136
url: LSPS5WebhookUrl,
123137
/// The identifier of the issued bLIP-55 / LSPS5 webhook registration request
124138
///
@@ -134,11 +148,8 @@ pub enum LSPS5ClientEvent {
134148
WebhookRegistrationFailed {
135149
/// The node id of the LSP that rejected the registration
136150
counterparty_node_id: PublicKey,
137-
/// Error code from the LSP (500: too_long, 501: url_parse_error,
138-
/// 502: unsupported_protocol, 503: too_many_webhooks)
139-
error_code: i32,
140-
/// Error message from the LSP
141-
error_message: String,
151+
/// Error from the LSP
152+
error: LSPS5Error,
142153
/// The app name that was attempted
143154
app_name: LSPS5AppName,
144155
/// The webhook URL that was attempted
@@ -171,10 +182,8 @@ pub enum LSPS5ClientEvent {
171182
WebhooksListFailed {
172183
/// The node id of the LSP that rejected the request
173184
counterparty_node_id: PublicKey,
174-
/// Error code from the LSP
175-
error_code: i32,
176-
/// Error message from the LSP
177-
error_message: String,
185+
/// Error from the LSP
186+
error: LSPS5Error,
178187
/// The identifier of the issued bLIP-55 / LSPS5 list webhooks request
179188
///
180189
/// This can be used to track which request this event corresponds to.
@@ -203,10 +212,8 @@ pub enum LSPS5ClientEvent {
203212
WebhookRemovalFailed {
204213
/// The node id of the LSP that rejected the removal
205214
counterparty_node_id: PublicKey,
206-
/// Error code from the LSP (1010: app_name_not_found)
207-
error_code: i32,
208-
/// Error message from the LSP
209-
error_message: String,
215+
/// Error from the LSP
216+
error: LSPS5Error,
210217
/// The app name that was attempted to be removed
211218
app_name: LSPS5AppName,
212219
/// The identifier of the issued bLIP-55 / LSPS5 remove webhook request
@@ -226,7 +233,7 @@ pub enum LSPS5ClientEvent {
226233
/// The notification with its method and parameters
227234
notification: WebhookNotification,
228235
/// Timestamp of the notification in ISO8601 format (YYYY-MM-DDThh:mm:ss.uuuZ)
229-
timestamp: String,
236+
timestamp: LSPSDateTime,
230237
/// Whether the LSP's signature was successfully verified
231238
signature_valid: bool,
232239
},

0 commit comments

Comments
 (0)