Skip to content

Commit

Permalink
Accept descriptionHash for createinvoice API endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed May 12, 2024
1 parent 1803556 commit baf7fc3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit baf7fc3

Please sign in to comment.