From 867998afcda6e1a46928bd253780b01093616bf8 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Padiou Date: Mon, 15 Jul 2024 13:35:15 +0200 Subject: [PATCH] Support multiple webhooks (#72) The `webhook` option can now be used multiple times. Fixes #71. --- src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt | 4 ++-- src/commonMain/kotlin/fr/acinq/lightning/bin/Main.kt | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt index 92feded..eebb0b5 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt @@ -64,7 +64,7 @@ class Api( private val peer: Peer, private val eventsFlow: SharedFlow, private val password: String, - private val webhookUrl: Url?, + private val webhookUrls: List, private val webhookSecret: String, private val loggerFactory: LoggerFactory, ) { @@ -372,7 +372,7 @@ class Api( } } - webhookUrl?.let { url -> + webhookUrls.forEach { url -> val client = HttpClient { install(io.ktor.client.plugins.contentnegotiation.ContentNegotiation) { json(json = Json { diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/Main.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/Main.kt index 526de5a..20c5e8e 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/Main.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/Main.kt @@ -111,8 +111,9 @@ class Phoenixd : CliktCommand() { terminal.println(white("done")) value } - private val webHookUrl by option("--webhook", help = "Webhook http endpoint for push notifications (alternative to websocket)") + private val webHookUrls by option("--webhook", help = "Webhook http endpoint for push notifications (alternative to websocket)") .convert { Url(it) } + .multiple() private val webHookSecret by option("--webhook-secret", help = "Secret used to authenticate webhook calls") .defaultLazy { // if we are here then no value is defined in phoenix.conf @@ -364,7 +365,7 @@ class Phoenixd : CliktCommand() { reuseAddress = true }, module = { - Api(nodeParams, peer, eventsFlow, httpPassword, webHookUrl, webHookSecret, loggerFactory).run { module() } + Api(nodeParams, peer, eventsFlow, httpPassword, webHookUrls, webHookSecret, loggerFactory).run { module() } } ) val serverJob = scope.launch {