Add support for optional payer note (#63)

Usage:

```shell
./phoenix-cli payoffer --offer lnoxxxxxx --amountSat 2100 --message "Hello from phoenixd!"
```
This commit is contained in:
Pierre-Marie Padiou 2024-07-02 14:56:34 +02:00 committed by GitHub
parent 18ade318cd
commit c2bd9f287c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 5 deletions

View File

@ -138,7 +138,7 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va
call.respond(GeneratedInvoice(invoice.amount?.truncateToSatoshi(), invoice.paymentHash, serialized = invoice.write()))
}
get("getoffer") {
call.respond(nodeParams.defaultOffer(peer.walletParams.trampolineNode.id).encode())
call.respond(nodeParams.defaultOffer(peer.walletParams.trampolineNode.id).first.encode())
}
get("payments/incoming") {
val listAll = call.parameters["all"]?.toBoolean() ?: false // by default, only list incoming payments that have been received
@ -197,7 +197,8 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va
val overrideAmount = formParameters["amountSat"]?.let { it.toLongOrNull() ?: invalidType("amountSat", "integer") }?.sat?.toMilliSatoshi()
val offer = formParameters.getOffer("offer")
val amount = (overrideAmount ?: offer.amount) ?: missing("amountSat")
when (val event = peer.payOffer(amount, offer, randomKey(), fetchInvoiceTimeout = 30.seconds)) {
val note = formParameters["message"]
when (val event = peer.payOffer(amount, offer, payerKey = nodeParams.defaultOffer(peer.walletParams.trampolineNode.id).second, payerNote = note, fetchInvoiceTimeout = 30.seconds)) {
is fr.acinq.lightning.io.PaymentSent -> call.respond(PaymentSent(event))
is fr.acinq.lightning.io.PaymentNotSent -> call.respond(PaymentFailed(event))
is fr.acinq.lightning.io.OfferNotPaid -> call.respond(PaymentFailed(event))

View File

@ -242,7 +242,7 @@ class Phoenixd : CliktCommand() {
liquidityPolicy = MutableStateFlow(liquidityPolicy),
)
consoleLog(cyan("nodeid: ${nodeParams.nodeId}"))
consoleLog(cyan("offer: ${nodeParams.defaultOffer(lsp.walletParams.trampolineNode.id)}"))
consoleLog(cyan("offer: ${nodeParams.defaultOffer(lsp.walletParams.trampolineNode.id).first}"))
val driver = createAppDbDriver(datadir, chain, nodeParams.nodeId)
val database = PhoenixDatabase(

View File

@ -235,13 +235,15 @@ class PayInvoice : PhoenixCliCommand(name = "payinvoice", help = "Pay a Lightnin
class PayOffer : PhoenixCliCommand(name = "payoffer", help = "Pay a Lightning offer", printHelpOnEmptyArgs = true) {
private val amountSat by option("--amountSat").long()
private val invoice by option("--offer").required().check { OfferTypes.Offer.decode(it).isSuccess }
private val offer by option("--offer").required().check { OfferTypes.Offer.decode(it).isSuccess }
private val message by option("--message").help { "Optional payer note" }
override suspend fun httpRequest() = commonOptions.httpClient.use {
it.submitForm(
url = (commonOptions.baseUrl / "payoffer").toString(),
formParameters = parameters {
amountSat?.let { append("amountSat", amountSat.toString()) }
append("offer", invoice)
append("offer", offer)
message?.let { append("message", message.toString()) }
}
)
}