Skip to content

Commit c5fda55

Browse files
authored
Support custom expiry when requesting a new payment invoice (#250)
1 parent eb4a5ca commit c5fda55

File tree

3 files changed

+23
-7
lines changed
  • src
    • commonMain/kotlin/fr/acinq/eclair/io
    • commonTest/kotlin/fr/acinq/eclair/io/peer
    • jvmTest/kotlin/fr/acinq/eclair

3 files changed

+23
-7
lines changed

src/commonMain/kotlin/fr/acinq/eclair/io/Peer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data class WrappedChannelEvent(val channelId: ByteVector32, val channelEvent: Ch
4141
object Disconnected : PeerEvent()
4242

4343
sealed class PaymentEvent : PeerEvent()
44-
data class ReceivePayment(val paymentPreimage: ByteVector32, val amount: MilliSatoshi?, val description: String, val result: CompletableDeferred<PaymentRequest>) : PaymentEvent()
44+
data class ReceivePayment(val paymentPreimage: ByteVector32, val amount: MilliSatoshi?, val description: String, val expirySeconds: Long? = null, val result: CompletableDeferred<PaymentRequest>) : PaymentEvent()
4545
object CheckPaymentsTimeout : PaymentEvent()
4646
data class PayToOpenResponseEvent(val payToOpenResponse: PayToOpenResponse) : PeerEvent()
4747
data class SendPayment(val paymentId: UUID, val amount: MilliSatoshi, val recipient: PublicKey, val details: OutgoingPayment.Details.Normal) : PaymentEvent() {
@@ -669,7 +669,7 @@ class Peer(
669669
)
670670
)
671671
)
672-
val pr = incomingPaymentHandler.createInvoice(event.paymentPreimage, event.amount, event.description, extraHops)
672+
val pr = incomingPaymentHandler.createInvoice(event.paymentPreimage, event.amount, event.description, extraHops, event.expirySeconds)
673673
listenerEventChannel.send(PaymentRequestGenerated(event, pr.write()))
674674
event.result.complete(pr)
675675
}

src/commonTest/kotlin/fr/acinq/eclair/io/peer/PeerTest.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,22 @@ class PeerTest : EclairTestSuite() {
168168
newPeers(this, Pair(alice0.staticParams.nodeParams, bob0.staticParams.nodeParams), Pair(TestConstants.Alice.walletParams, TestConstants.Bob.walletParams), listOf(alice0 to bob0))
169169
}
170170

171+
@Test
172+
fun `invoice parameters`() = runSuspendTest {
173+
val nodeParams = TestConstants.Alice.nodeParams
174+
val walletParams = TestConstants.Alice.walletParams
175+
val bob = newPeer(nodeParams, walletParams)
176+
177+
run {
178+
val deferredInvoice = CompletableDeferred<PaymentRequest>()
179+
bob.send(ReceivePayment(randomBytes32(), 1.msat, "A description: \uD83D\uDE2C", 3600 * 3, deferredInvoice))
180+
val invoice = deferredInvoice.await()
181+
assertEquals(1.msat, invoice.amount)
182+
assertEquals(3600 * 3, invoice.expirySeconds)
183+
assertEquals("A description: \uD83D\uDE2C", invoice.description)
184+
}
185+
}
186+
171187
@Test
172188
fun `invoice routing hints`() = runSuspendTest {
173189
val (alice0, bob0) = TestsHelper.reachNormal()
@@ -181,7 +197,7 @@ class PeerTest : EclairTestSuite() {
181197

182198
run {
183199
val deferredInvoice = CompletableDeferred<PaymentRequest>()
184-
bob.send(ReceivePayment(randomBytes32(), 15_000_000.msat, "default routing hints", deferredInvoice))
200+
bob.send(ReceivePayment(randomBytes32(), 15_000_000.msat, "default routing hints", null, deferredInvoice))
185201
val invoice = deferredInvoice.await()
186202
// The routing hint uses default values since no channel update has been sent by Alice yet.
187203
assertEquals(1, invoice.routingInfo.size)
@@ -194,7 +210,7 @@ class PeerTest : EclairTestSuite() {
194210
bob.forward(aliceUpdate)
195211

196212
val deferredInvoice = CompletableDeferred<PaymentRequest>()
197-
bob.send(ReceivePayment(randomBytes32(), 5_000_000.msat, "updated routing hints", deferredInvoice))
213+
bob.send(ReceivePayment(randomBytes32(), 5_000_000.msat, "updated routing hints", null, deferredInvoice))
198214
val invoice = deferredInvoice.await()
199215
// The routing hint uses values from Alice's channel update.
200216
assertEquals(1, invoice.routingInfo.size)
@@ -218,7 +234,7 @@ class PeerTest : EclairTestSuite() {
218234
val (alice, bob, alice2bob, bob2alice) = newPeers(this, nodeParams, walletParams, listOf(alice0 to bob0), automateMessaging = false)
219235

220236
val deferredInvoice = CompletableDeferred<PaymentRequest>()
221-
bob.send(ReceivePayment(randomBytes32(), 15_000_000.msat, "test invoice", deferredInvoice))
237+
bob.send(ReceivePayment(randomBytes32(), 15_000_000.msat, "test invoice", null, deferredInvoice))
222238
val invoice = deferredInvoice.await()
223239

224240
alice.send(SendPayment(UUID.randomUUID(), invoice.amount!!, alice.remoteNodeId, OutgoingPayment.Details.Normal(invoice)))
@@ -264,7 +280,7 @@ class PeerTest : EclairTestSuite() {
264280
val (alice, bob) = newPeers(this, nodeParams, walletParams, listOf(alice0 to bob0))
265281

266282
val deferredInvoice = CompletableDeferred<PaymentRequest>()
267-
bob.send(ReceivePayment(randomBytes32(), 15_000_000.msat, "test invoice", deferredInvoice))
283+
bob.send(ReceivePayment(randomBytes32(), 15_000_000.msat, "test invoice", null, deferredInvoice))
268284
val invoice = deferredInvoice.await()
269285

270286
alice.send(SendPayment(UUID.randomUUID(), invoice.amount!!, alice.remoteNodeId, OutgoingPayment.Details.Normal(invoice)))

src/jvmTest/kotlin/fr/acinq/eclair/Node.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ object Node {
233233
val paymentPreimage = Eclair.randomBytes32()
234234
val amount = MilliSatoshi(request.amount ?: 50000L)
235235
val result = CompletableDeferred<PaymentRequest>()
236-
peer.send(ReceivePayment(paymentPreimage, amount, request.description.orEmpty(), result))
236+
peer.send(ReceivePayment(paymentPreimage, amount, request.description.orEmpty(), null, result))
237237
call.respond(CreateInvoiceResponse(result.await().write()))
238238
}
239239
post("/invoice/pay") {

0 commit comments

Comments
 (0)