Fix for issue
The preimage must be different every time we generate an invoice
@@ -18,8 +18,6 @@ import kotlin.random.Random
@OptIn(ExperimentalCoroutinesApi::class)
class AppReceiveController(loggerFactory: LoggerFactory, private val peer: Peer) : AppController<Receive.Model, Receive.Intent>(loggerFactory, Receive.Model.Awaiting) {
- private val preimage = ByteVector32(Random.secure().nextBytes(32))
-
private val Receive.Intent.Ask.paymentAmountMsat: MilliSatoshi? get() = amount?.toMilliSatoshi(unit)
private val Receive.Intent.Ask.paymentDescription: String get() = desc ?: "Phoenix payment"
@@ -29,12 +27,24 @@ class AppReceiveController(loggerFactory: LoggerFactory, private val peer: Peer)
is Receive.Intent.Ask -> {
launch {
model(Receive.Model.Generating)
+ try {
val deferred = CompletableDeferred<PaymentRequest>()
- peer.send(ReceivePayment(preimage, intent.paymentAmountMsat, intent.paymentDescription, deferred))
+ val preimage = ByteVector32(Random.secure().nextBytes(32)) // must be different everytime
+ peer.send(
+ ReceivePayment(
+ preimage,
+ intent.paymentAmountMsat,
+ intent.paymentDescription,
+ deferred
+ )
+ )
val request = deferred.await()
check(request.amount == intent.paymentAmountMsat) { "Payment request amount not corresponding to expected" }
check(request.description == intent.paymentDescription) { "Payment request description not corresponding to expected" }
model(Receive.Model.Generated(request.write(), intent.amount, intent.unit, intent.desc))
+ } catch (e: Throwable) {
+ logger.error(e) { "failed to process intent=$intent" }
+ }
}
}
}
