From 6bc10b57751399de73f2eb2537c88ed8e275852d Mon Sep 17 00:00:00 2001 From: Braydon Date: Fri, 10 May 2024 18:32:24 -0700 Subject: [PATCH] Accept descriptionHash for createinvoice API endpoint. --- src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt index 243c93c..702ae8a 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt @@ -113,8 +113,16 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va post("createinvoice") { val formParameters = call.receiveParameters() val amount = formParameters.getOptionalLong("amountSat")?.sat - val description = formParameters.getString("description") - val invoice = peer.createInvoice(randomBytes32(), amount?.toMilliSatoshi(), Either.Left(description)) + var invoice : Bolt11Invoice + + if ((formParameters["descriptionHash"]?.isNotBlank()) ?: false) { + val hash = formParameters.getByteVector32("descriptionHash") + invoice = peer.createInvoice(randomBytes32(), amount?.toMilliSatoshi(), Either.Right(hash)) + } else { + val description = formParameters.getString("description") + invoice = peer.createInvoice(randomBytes32(), amount?.toMilliSatoshi(), Either.Left(description)) + } + formParameters["externalId"]?.takeUnless { it.isBlank() }?.let { externalId -> paymentDb.metadataQueries.insertExternalId(WalletPaymentId.IncomingPaymentId(invoice.paymentHash), externalId) }