|
| 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::prelude::String; |
| 14 | +use crate::prelude::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 | + SendWebhookNotifications { |
| 78 | + /// Client node ID to be notified |
| 79 | + counterparty_node_id: PublicKey, |
| 80 | + /// App name to be notified |
| 81 | + app_name: LSPS5AppName, |
| 82 | + /// URL that to be contacted |
| 83 | + url: LSPS5WebhookUrl, |
| 84 | + /// Notification method with its parameters |
| 85 | + notification: WebhookNotification, |
| 86 | + /// ISO8601 timestamp of the notification (YYYY-MM-DDThh:mm:ss.uuuZ format) |
| 87 | + timestamp: String, |
| 88 | + /// Signature of the notification using the LSP's node ID |
| 89 | + signature: String, |
| 90 | + /// Headers to be included in the HTTP POST request |
| 91 | + headers: Vec<(String, String)>, |
| 92 | + }, |
| 93 | +} |
| 94 | + |
| 95 | +/// An event which an LSPS5 client should take some action in response to. |
| 96 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 97 | +pub enum LSPS5ClientEvent { |
| 98 | + /// A webhook was successfully registered with the LSP |
| 99 | + /// |
| 100 | + /// This event is triggered when the LSP confirms successful registration |
| 101 | + /// of a webhook via `lsps5.set_webhook`. |
| 102 | + WebhookRegistered { |
| 103 | + /// The node id of the LSP that confirmed the registration |
| 104 | + counterparty_node_id: PublicKey, |
| 105 | + /// Current number of webhooks registered for this client |
| 106 | + num_webhooks: u32, |
| 107 | + /// Maximum number of webhooks allowed by LSP |
| 108 | + max_webhooks: u32, |
| 109 | + /// Whether this was an unchanged registration (same app_name and URL) |
| 110 | + /// If true, the LSP didn't send a webhook notification for this registration |
| 111 | + no_change: bool, |
| 112 | + /// The app name that was registered (up to 64 bytes in UTF-8 format) |
| 113 | + app_name: LSPS5AppName, |
| 114 | + /// The webhook URL that was registered (HTTPS protocol) |
| 115 | + url: LSPS5WebhookUrl, |
| 116 | + /// The identifier of the issued bLIP-55 / LSPS5 webhook registration request |
| 117 | + /// |
| 118 | + /// This can be used to track which request this event corresponds to. |
| 119 | + request_id: LSPSRequestId, |
| 120 | + }, |
| 121 | + |
| 122 | + /// A webhook registration attempt failed |
| 123 | + /// |
| 124 | + /// This event is triggered when the LSP rejects a webhook registration |
| 125 | + /// via `lsps5.set_webhook`. This can happen if the app_name or URL is too long, |
| 126 | + /// the URL uses an unsupported protocol, or the maximum number of webhooks is reached. |
| 127 | + WebhookRegistrationFailed { |
| 128 | + /// The node id of the LSP that rejected the registration |
| 129 | + counterparty_node_id: PublicKey, |
| 130 | + /// Error code from the LSP (500: too_long, 501: url_parse_error, |
| 131 | + /// 502: unsupported_protocol, 503: too_many_webhooks) |
| 132 | + error_code: i32, |
| 133 | + /// Error message from the LSP |
| 134 | + error_message: String, |
| 135 | + /// The app name that was attempted |
| 136 | + app_name: LSPS5AppName, |
| 137 | + /// The webhook URL that was attempted |
| 138 | + url: LSPS5WebhookUrl, |
| 139 | + /// The identifier of the issued bLIP-55 / LSPS5 webhook registration request |
| 140 | + /// |
| 141 | + /// This can be used to track which request this event corresponds to. |
| 142 | + request_id: LSPSRequestId, |
| 143 | + }, |
| 144 | + |
| 145 | + /// The list of registered webhooks was successfully retrieved |
| 146 | + /// |
| 147 | + /// This event is triggered when the LSP responds to a `lsps5.list_webhooks` request. |
| 148 | + WebhooksListed { |
| 149 | + /// The node id of the LSP that provided the list |
| 150 | + counterparty_node_id: PublicKey, |
| 151 | + /// List of app names with registered webhooks |
| 152 | + app_names: Vec<LSPS5AppName>, |
| 153 | + /// Maximum number of webhooks allowed by LSP |
| 154 | + max_webhooks: u32, |
| 155 | + /// The identifier of the issued bLIP-55 / LSPS5 list webhooks request |
| 156 | + /// |
| 157 | + /// This can be used to track which request this event corresponds to. |
| 158 | + request_id: LSPSRequestId, |
| 159 | + }, |
| 160 | + |
| 161 | + /// The attempt to list webhooks failed |
| 162 | + /// |
| 163 | + /// This event is triggered when the LSP rejects a `lsps5.list_webhooks` request. |
| 164 | + WebhooksListFailed { |
| 165 | + /// The node id of the LSP that rejected the request |
| 166 | + counterparty_node_id: PublicKey, |
| 167 | + /// Error code from the LSP |
| 168 | + error_code: i32, |
| 169 | + /// Error message from the LSP |
| 170 | + error_message: String, |
| 171 | + /// The identifier of the issued bLIP-55 / LSPS5 list webhooks request |
| 172 | + /// |
| 173 | + /// This can be used to track which request this event corresponds to. |
| 174 | + request_id: LSPSRequestId, |
| 175 | + }, |
| 176 | + |
| 177 | + /// A webhook was successfully removed |
| 178 | + /// |
| 179 | + /// This event is triggered when the LSP confirms successful removal |
| 180 | + /// of a webhook via `lsps5.remove_webhook`. |
| 181 | + WebhookRemoved { |
| 182 | + /// The node id of the LSP that confirmed the removal |
| 183 | + counterparty_node_id: PublicKey, |
| 184 | + /// The app name that was removed |
| 185 | + app_name: LSPS5AppName, |
| 186 | + /// The identifier of the issued bLIP-55 / LSPS5 remove webhook request |
| 187 | + /// |
| 188 | + /// This can be used to track which request this event corresponds to. |
| 189 | + request_id: LSPSRequestId, |
| 190 | + }, |
| 191 | + |
| 192 | + /// A webhook removal attempt failed |
| 193 | + /// |
| 194 | + /// This event is triggered when the LSP rejects a webhook removal |
| 195 | + /// via `lsps5.remove_webhook`. The most common error is app_name_not_found (1010). |
| 196 | + WebhookRemovalFailed { |
| 197 | + /// The node id of the LSP that rejected the removal |
| 198 | + counterparty_node_id: PublicKey, |
| 199 | + /// Error code from the LSP (1010: app_name_not_found) |
| 200 | + error_code: i32, |
| 201 | + /// Error message from the LSP |
| 202 | + error_message: String, |
| 203 | + /// The app name that was attempted to be removed |
| 204 | + app_name: LSPS5AppName, |
| 205 | + /// The identifier of the issued bLIP-55 / LSPS5 remove webhook request |
| 206 | + /// |
| 207 | + /// This can be used to track which request this event corresponds to. |
| 208 | + request_id: LSPSRequestId, |
| 209 | + }, |
| 210 | + |
| 211 | + /// A webhook notification was received from the LSP |
| 212 | + /// |
| 213 | + /// This event is triggered when the client receives a webhook notification |
| 214 | + /// from the LSP. This can happen for various reasons such as incoming payment, |
| 215 | + /// expiring HTLCs, liquidity management requests, or incoming onion messages. |
| 216 | + WebhookNotificationReceived { |
| 217 | + /// LSP node ID that sent the notification |
| 218 | + counterparty_node_id: PublicKey, |
| 219 | + /// The notification with its method and parameters |
| 220 | + notification: WebhookNotification, |
| 221 | + /// Timestamp of the notification in ISO8601 format (YYYY-MM-DDThh:mm:ss.uuuZ) |
| 222 | + timestamp: String, |
| 223 | + /// Whether the LSP's signature was successfully verified |
| 224 | + signature_valid: bool, |
| 225 | + }, |
| 226 | +} |
0 commit comments