Skip to content

Commit

Permalink
Add an optional expiry for bolt11 invoices (#102)
Browse files Browse the repository at this point in the history
Example:

```bash
./phoenix-cli createinvoice  --description="expiry test" --expirySeconds=60
```

Suggested by @sixside in #99.
  • Loading branch information
pm47 authored Aug 27, 2024
1 parent 05fb84e commit 82339b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class Api(
description == null && descriptionHash != null -> Either.Right(descriptionHash)
else -> badRequest("Must provide either a description or descriptionHash")
}
val invoice = peer.createInvoice(randomBytes32(), amount?.toMilliSatoshi(), eitherDesc)
val expirySeconds = formParameters.getOptionalLong("expirySeconds")
val invoice = peer.createInvoice(randomBytes32(), amount?.toMilliSatoshi(), eitherDesc, expirySeconds)
val externalId = formParameters["externalId"]
val webhookUrl = formParameters.getOptionalUrl("webhookUrl")
if (externalId != null || webhookUrl != null) {
Expand Down
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/fr/acinq/lightning/cli/PhoenixCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class CreateInvoice : PhoenixCliCommand(name = "createinvoice", help = "Create a
option("--description", "--desc").convert { Either.Left(it) },
option("--descriptionHash", "--desc-hash").convert { Either.Right(it.toByteVector32()) }
).single().required()
private val expirySeconds by option("--expirySeconds").long()

private val externalId by option("--externalId")
private val webhookUrl by option("--webhookUrl")
Expand All @@ -217,6 +218,7 @@ class CreateInvoice : PhoenixCliCommand(name = "createinvoice", help = "Create a
is Either.Left -> append("description", d.value)
is Either.Right -> append("descriptionHash", d.value.toHex())
}
expirySeconds?.let { append("expirySeconds", it.toString()) }
externalId?.let { append("externalId", it) }
webhookUrl?.let { append("webhookUrl", it) }
}
Expand Down

0 comments on commit 82339b6

Please sign in to comment.