Skip to content

Commit 1519b15

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.
1 parent fa69a19 commit 1519b15

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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 crate::lsps5::msgs::WebhookNotificationMethod;
14+
use crate::prelude::String;
15+
use crate::prelude::Vec;
16+
use bitcoin::secp256k1::PublicKey;
17+
18+
/// Events emitted by the LSPS5 webhook service (LSP side)
19+
#[derive(Debug, Clone, PartialEq, Eq)]
20+
pub enum LSPS5ServiceEvent {
21+
/// A webhook was registered by a client
22+
WebhookRegistered {
23+
/// Client node ID
24+
client: PublicKey,
25+
/// App name
26+
app_name: String,
27+
/// Webhook URL
28+
url: String,
29+
/// Request ID for tracking
30+
request_id: LSPSRequestId,
31+
/// Whether this was a new registration or an update to existing one
32+
no_change: bool,
33+
},
34+
35+
/// Webhooks were listed for a client
36+
WebhooksListed {
37+
/// Client node ID
38+
client: PublicKey,
39+
/// App names with registered webhooks
40+
app_names: Vec<String>,
41+
/// Maximum number of webhooks allowed
42+
max_webhooks: u32,
43+
/// Request ID for tracking
44+
request_id: LSPSRequestId,
45+
},
46+
47+
/// A webhook was removed
48+
WebhookRemoved {
49+
/// Client node ID
50+
client: PublicKey,
51+
/// App name
52+
app_name: String,
53+
/// Request ID for tracking
54+
request_id: LSPSRequestId,
55+
},
56+
57+
/// A notification was sent to a webhook
58+
WebhookNotificationSent {
59+
/// Client node ID
60+
client: PublicKey,
61+
/// App name
62+
app_name: String,
63+
/// Webhook URL
64+
url: String,
65+
/// Notification method
66+
method: WebhookNotificationMethod,
67+
/// Timestamp of the notification
68+
timestamp: String,
69+
/// Signature of the notification
70+
signature: String,
71+
},
72+
}
73+
74+
/// Events emitted by the LSPS5 webhook client (Lightning node side)
75+
#[derive(Debug, Clone, PartialEq, Eq)]
76+
pub enum LSPS5ClientEvent {
77+
/// A webhook was successfully registered with the LSP
78+
WebhookRegistered {
79+
/// LSP node ID
80+
lsp: PublicKey,
81+
/// App name
82+
app_name: String,
83+
/// Webhook URL
84+
url: String,
85+
/// Number of webhooks now registered
86+
num_webhooks: u32,
87+
/// Maximum number of webhooks allowed
88+
max_webhooks: u32,
89+
/// Whether this was a new registration or an update to existing one
90+
no_change: bool,
91+
},
92+
93+
/// Failed to register a webhook with the LSP
94+
WebhookRegistrationFailed {
95+
/// LSP node ID
96+
lsp: PublicKey,
97+
/// App name
98+
app_name: String,
99+
/// Webhook URL
100+
url: String,
101+
/// Error code
102+
error_code: i32,
103+
/// Error message
104+
error_message: String,
105+
},
106+
107+
/// Received list of registered webhooks from the LSP
108+
WebhooksListed {
109+
/// LSP node ID
110+
lsp: PublicKey,
111+
/// App names with registered webhooks
112+
app_names: Vec<String>,
113+
/// Maximum number of webhooks allowed
114+
max_webhooks: u32,
115+
},
116+
117+
/// Failed to list webhooks
118+
WebhooksListFailed {
119+
/// LSP node ID
120+
lsp: PublicKey,
121+
/// Error code
122+
error_code: i32,
123+
/// Error message
124+
error_message: String,
125+
},
126+
127+
/// A webhook was successfully removed
128+
WebhookRemoved {
129+
/// LSP node ID
130+
lsp: PublicKey,
131+
/// App name
132+
app_name: String,
133+
},
134+
135+
/// Failed to remove a webhook
136+
WebhookRemovalFailed {
137+
/// LSP node ID
138+
lsp: PublicKey,
139+
/// App name
140+
app_name: String,
141+
/// Error code
142+
error_code: i32,
143+
/// Error message
144+
error_message: String,
145+
},
146+
147+
/// A webhook notification was received from the LSP
148+
WebhookNotificationReceived {
149+
/// LSP node ID
150+
lsp: PublicKey,
151+
/// The notification method that was received
152+
method: WebhookNotificationMethod,
153+
/// Timestamp of the notification
154+
timestamp: String,
155+
/// Whether the signature verification succeeded
156+
signature_valid: bool,
157+
/// The notification parameters (might be empty depending on method)
158+
parameters: Option<WebhookNotificationParams>,
159+
},
160+
}
161+
162+
/// Parameters for different webhook notification methods
163+
#[derive(Debug, Clone, PartialEq, Eq)]
164+
pub enum WebhookNotificationParams {
165+
/// Parameters for lsps5.expiry_soon notification
166+
ExpirySoon {
167+
/// Block height when timeout occurs
168+
timeout: u32,
169+
},
170+
/// For future extensions of other notification types that might have parameters
171+
Other,
172+
}

0 commit comments

Comments
 (0)