Skip to content

Commit c06aa96

Browse files
committed
Add a trivial helper to LSPS5's WebhookNotification
`LSPS5ServiceEvent::SendWebhookNotification`'s docs say to send the `WebhookNotification` as the HTTP request body "as JSON", which is great, but it leaves the dev to figure out how to do that. Its nice to have a helper to do that, which is trivial so we provide it here.
1 parent 62c5849 commit c06aa96

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lightning-liquidity/src/lsps5/event.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ pub enum LSPS5ServiceEvent {
3030
/// via their registered webhook.
3131
///
3232
/// The LSP should send an HTTP POST to the [`url`], using the
33-
/// JSON-serialized [`notification`] as the body and including the `headers`.
34-
/// If the HTTP request fails, the LSP may implement a retry policy according to its
35-
/// implementation preferences.
33+
/// JSON-serialized [`notification`] (via [`WebhookNotification::to_request_body`]) as the body
34+
/// and including the `headers`. If the HTTP request fails, the LSP may implement a retry
35+
/// policy according to its implementation preferences.
3636
///
3737
/// The notification is signed using the LSP's node ID to ensure authenticity
3838
/// when received by the client. The client verifies this signature using

lightning-liquidity/src/lsps5/msgs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ impl WebhookNotification {
565565
pub fn onion_message_incoming() -> Self {
566566
Self { method: WebhookNotificationMethod::LSPS5OnionMessageIncoming }
567567
}
568+
569+
/// Encodes this notification into JSON which can be sent as the body of an HTTP request to
570+
/// deliver the notification.
571+
pub fn to_request_body(&self) -> String {
572+
serde_json::to_string(self).unwrap()
573+
}
568574
}
569575

570576
impl Serialize for WebhookNotification {

0 commit comments

Comments
 (0)