Skip to content

Commit 5ddcfbd

Browse files
Add LSPS5 event enums for webhook operations
- Introduce LSPS5ServiceEvent for LSPS-side webhook events including registration, listing, removal, and notification. - Define LSPS5ClientEvent for handling webhook outcomes on the client (Lightning node) side. - Outline WebhookNotificationParams enum to support notification-specific parameters. - Improve LSPS5 event documentation and field naming - Rename client/lsp fields to counterparty_node_id for consistent terminology - Replace generic String types with more specific Lsps5AppName and Lsps5WebhookUrl - Add comprehensive documentation for all events and fields - Include format specifications (UTF-8, ISO8601) and size constraints - Add request_id field to all relevant events for consistent request tracking - Provide detailed descriptions of error codes and their meanings - Use complete sentences in documentation comments
1 parent e247678 commit 5ddcfbd

File tree

2 files changed

+233
-1
lines changed

2 files changed

+233
-1
lines changed

lightning-liquidity/src/events/event_queue.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::LiquidityEvent;
22
use crate::sync::{Arc, Mutex};
3-
43
use alloc::collections::VecDeque;
54
use alloc::vec::Vec;
65

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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+
10+
//! Events generated by the LSPS5 service and client
11+
12+
use crate::lsps0::ser::LSPSRequestId;
13+
use alloc::string::String;
14+
use alloc::vec::Vec;
15+
use bitcoin::secp256k1::PublicKey;
16+
17+
use super::msgs::LSPS5AppName;
18+
use super::msgs::LSPS5WebhookUrl;
19+
use super::msgs::WebhookNotification;
20+
21+
/// An event which an bLIP-55 / LSPS5 server should take some action in response to.
22+
#[derive(Debug, Clone, PartialEq, Eq)]
23+
pub enum LSPS5ServiceEvent {
24+
/// A webhook was registered by a client
25+
///
26+
/// This event occurs when a client successfully registers a webhook via `lsps5.set_webhook`.
27+
/// You should store this information to be able to contact the client when they are offline.
28+
WebhookRegistered {
29+
/// Client node ID that registered the webhook
30+
counterparty_node_id: PublicKey,
31+
/// App name provided by the client (up to 64 bytes in UTF-8 format)
32+
app_name: LSPS5AppName,
33+
/// Webhook URL (HTTPS) that should be contacted to notify the client (up to 1024 ASCII characters)
34+
url: LSPS5WebhookUrl,
35+
/// The identifier of the issued bLIP-55 / LSPS5 webhook registration request
36+
///
37+
/// This can be used to track which request this event corresponds to.
38+
request_id: LSPSRequestId,
39+
/// Whether this was a new registration or an update to existing one with no changes
40+
/// If false, a notification should be sent to the registered webhook
41+
no_change: bool,
42+
},
43+
44+
/// Webhooks were listed for a client
45+
///
46+
/// This event occurs when a client requests their registered webhooks via `lsps5.list_webhooks`.
47+
WebhooksListed {
48+
/// Client node ID that requested their webhooks
49+
counterparty_node_id: PublicKey,
50+
/// App names with registered webhooks for this client
51+
app_names: Vec<LSPS5AppName>,
52+
/// The identifier of the issued bLIP-55 / LSPS5 webhook listing request
53+
///
54+
/// This can be used to track which request this event corresponds to.
55+
request_id: LSPSRequestId,
56+
/// Maximum number of webhooks allowed by LSP per client
57+
max_webhooks: u32,
58+
},
59+
60+
/// A webhook was removed by a client
61+
///
62+
/// This event occurs when a client successfully removes a webhook via `lsps5.remove_webhook`.
63+
WebhookRemoved {
64+
/// Client node ID that removed the webhook
65+
counterparty_node_id: PublicKey,
66+
/// App name that was removed
67+
app_name: LSPS5AppName,
68+
/// The identifier of the issued bLIP-55 / LSPS5 webhook removal request
69+
///
70+
/// This can be used to track which request this event corresponds to.
71+
request_id: LSPSRequestId,
72+
},
73+
74+
/// A notification needs to be sent to a client's webhook
75+
///
76+
/// This event occurs when the LSP needs to send a notification to a client's webhook.
77+
/// When this event is received, the LSP should:
78+
/// 1. Serialize the notification to JSON
79+
/// 2. Make an HTTP POST request to the provided URL with the given headers and the serialized notification
80+
///
81+
/// When the client receives this notification, they will process it and generate a
82+
/// `WebhookNotificationReceived` event on their side. The client will validate the
83+
/// signature using the LSP's node ID to ensure the notification is authentic.
84+
SendWebhookNotifications {
85+
/// Client node ID to be notified
86+
counterparty_node_id: PublicKey,
87+
/// App name to be notified
88+
app_name: LSPS5AppName,
89+
/// URL that to be contacted
90+
url: LSPS5WebhookUrl,
91+
/// Notification method with its parameters
92+
notification: WebhookNotification,
93+
/// ISO8601 timestamp of the notification (YYYY-MM-DDThh:mm:ss.uuuZ format)
94+
timestamp: String,
95+
/// Signature of the notification using the LSP's node ID
96+
signature: String,
97+
/// Headers to be included in the HTTP POST request
98+
headers: Vec<(String, String)>,
99+
},
100+
}
101+
102+
/// An event which an LSPS5 client should take some action in response to.
103+
#[derive(Debug, Clone, PartialEq, Eq)]
104+
pub enum LSPS5ClientEvent {
105+
/// A webhook was successfully registered with the LSP
106+
///
107+
/// This event is triggered when the LSP confirms successful registration
108+
/// of a webhook via `lsps5.set_webhook`.
109+
WebhookRegistered {
110+
/// The node id of the LSP that confirmed the registration
111+
counterparty_node_id: PublicKey,
112+
/// Current number of webhooks registered for this client
113+
num_webhooks: u32,
114+
/// Maximum number of webhooks allowed by LSP
115+
max_webhooks: u32,
116+
/// Whether this was an unchanged registration (same app_name and URL)
117+
/// If true, the LSP didn't send a webhook notification for this registration
118+
no_change: bool,
119+
/// The app name that was registered (up to 64 bytes in UTF-8 format)
120+
app_name: LSPS5AppName,
121+
/// The webhook URL that was registered (HTTPS protocol)
122+
url: LSPS5WebhookUrl,
123+
/// The identifier of the issued bLIP-55 / LSPS5 webhook registration request
124+
///
125+
/// This can be used to track which request this event corresponds to.
126+
request_id: LSPSRequestId,
127+
},
128+
129+
/// A webhook registration attempt failed
130+
///
131+
/// This event is triggered when the LSP rejects a webhook registration
132+
/// via `lsps5.set_webhook`. This can happen if the app_name or URL is too long,
133+
/// the URL uses an unsupported protocol, or the maximum number of webhooks is reached.
134+
WebhookRegistrationFailed {
135+
/// The node id of the LSP that rejected the registration
136+
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,
142+
/// The app name that was attempted
143+
app_name: LSPS5AppName,
144+
/// The webhook URL that was attempted
145+
url: LSPS5WebhookUrl,
146+
/// The identifier of the issued bLIP-55 / LSPS5 webhook registration request
147+
///
148+
/// This can be used to track which request this event corresponds to.
149+
request_id: LSPSRequestId,
150+
},
151+
152+
/// The list of registered webhooks was successfully retrieved
153+
///
154+
/// This event is triggered when the LSP responds to a `lsps5.list_webhooks` request.
155+
WebhooksListed {
156+
/// The node id of the LSP that provided the list
157+
counterparty_node_id: PublicKey,
158+
/// List of app names with registered webhooks
159+
app_names: Vec<LSPS5AppName>,
160+
/// Maximum number of webhooks allowed by LSP
161+
max_webhooks: u32,
162+
/// The identifier of the issued bLIP-55 / LSPS5 list webhooks request
163+
///
164+
/// This can be used to track which request this event corresponds to.
165+
request_id: LSPSRequestId,
166+
},
167+
168+
/// The attempt to list webhooks failed
169+
///
170+
/// This event is triggered when the LSP rejects a `lsps5.list_webhooks` request.
171+
WebhooksListFailed {
172+
/// The node id of the LSP that rejected the request
173+
counterparty_node_id: PublicKey,
174+
/// Error code from the LSP
175+
error_code: i32,
176+
/// Error message from the LSP
177+
error_message: String,
178+
/// The identifier of the issued bLIP-55 / LSPS5 list webhooks request
179+
///
180+
/// This can be used to track which request this event corresponds to.
181+
request_id: LSPSRequestId,
182+
},
183+
184+
/// A webhook was successfully removed
185+
///
186+
/// This event is triggered when the LSP confirms successful removal
187+
/// of a webhook via `lsps5.remove_webhook`.
188+
WebhookRemoved {
189+
/// The node id of the LSP that confirmed the removal
190+
counterparty_node_id: PublicKey,
191+
/// The app name that was removed
192+
app_name: LSPS5AppName,
193+
/// The identifier of the issued bLIP-55 / LSPS5 remove webhook request
194+
///
195+
/// This can be used to track which request this event corresponds to.
196+
request_id: LSPSRequestId,
197+
},
198+
199+
/// A webhook removal attempt failed
200+
///
201+
/// This event is triggered when the LSP rejects a webhook removal
202+
/// via `lsps5.remove_webhook`. The most common error is app_name_not_found (1010).
203+
WebhookRemovalFailed {
204+
/// The node id of the LSP that rejected the removal
205+
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,
210+
/// The app name that was attempted to be removed
211+
app_name: LSPS5AppName,
212+
/// The identifier of the issued bLIP-55 / LSPS5 remove webhook request
213+
///
214+
/// This can be used to track which request this event corresponds to.
215+
request_id: LSPSRequestId,
216+
},
217+
218+
/// A webhook notification was received from the LSP
219+
///
220+
/// This event is triggered when the client receives a webhook notification
221+
/// from the LSP. This can happen for various reasons such as incoming payment,
222+
/// expiring HTLCs, liquidity management requests, or incoming onion messages.
223+
WebhookNotificationReceived {
224+
/// LSP node ID that sent the notification
225+
counterparty_node_id: PublicKey,
226+
/// The notification with its method and parameters
227+
notification: WebhookNotification,
228+
/// Timestamp of the notification in ISO8601 format (YYYY-MM-DDThh:mm:ss.uuuZ)
229+
timestamp: String,
230+
/// Whether the LSP's signature was successfully verified
231+
signature_valid: bool,
232+
},
233+
}

0 commit comments

Comments
 (0)