Skip to content

Commit 3c8c6d3

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 00ee0ef commit 3c8c6d3

File tree

1 file changed

+170
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)