Skip to content

Commit

Permalink
address @t-bast comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pm47 committed Dec 19, 2024
1 parent 73d2155 commit 6a87282
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,25 +452,23 @@ sealed class OnChainOutgoingPayment : OutgoingPayment() {
abstract val lockedAt: Long?
override val completedAt: Long? get() = lockedAt

companion object {
/** Helper method to facilitate updating child classes */
fun OnChainOutgoingPayment.setLocked(lockedAt: Long): OnChainOutgoingPayment =
when (this) {
is SpliceOutgoingPayment -> copy(lockedAt = lockedAt)
is SpliceCpfpOutgoingPayment -> copy(lockedAt = lockedAt)
is InboundLiquidityOutgoingPayment -> copy(lockedAt = lockedAt)
is ChannelCloseOutgoingPayment -> copy(lockedAt = lockedAt)
}
/** Helper method to facilitate updating child classes */
fun OnChainOutgoingPayment.setLocked(lockedAt: Long): OnChainOutgoingPayment =
when (this) {
is SpliceOutgoingPayment -> copy(lockedAt = lockedAt)
is SpliceCpfpOutgoingPayment -> copy(lockedAt = lockedAt)
is InboundLiquidityOutgoingPayment -> copy(lockedAt = lockedAt)
is ChannelCloseOutgoingPayment -> copy(lockedAt = lockedAt)
}

/** Helper method to facilitate updating child classes */
fun OnChainOutgoingPayment.setConfirmed(confirmedAt: Long): OnChainOutgoingPayment =
when (this) {
is SpliceOutgoingPayment -> copy(confirmedAt = confirmedAt)
is SpliceCpfpOutgoingPayment -> copy(confirmedAt = confirmedAt)
is InboundLiquidityOutgoingPayment -> copy(confirmedAt = confirmedAt)
is ChannelCloseOutgoingPayment -> copy(confirmedAt = confirmedAt)
}
}
/** Helper method to facilitate updating child classes */
fun OnChainOutgoingPayment.setConfirmed(confirmedAt: Long): OnChainOutgoingPayment =
when (this) {
is SpliceOutgoingPayment -> copy(confirmedAt = confirmedAt)
is SpliceCpfpOutgoingPayment -> copy(confirmedAt = confirmedAt)
is InboundLiquidityOutgoingPayment -> copy(confirmedAt = confirmedAt)
is ChannelCloseOutgoingPayment -> copy(confirmedAt = confirmedAt)
}
}

data class SpliceOutgoingPayment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ class OutgoingPaymentHandler(val nodeParams: NodeParams, val walletParams: Walle
}

logger.info { "payment successfully sent (fees=${payment.fees})" }
db.completeLightningOutgoingPaymentPart(payment.request.paymentId, event.paymentId, LightningOutgoingPayment.Part.Status.Succeeded(preimage))
db.completeLightningOutgoingPayment(payment.request.paymentId, LightningOutgoingPayment.Status.Succeeded(preimage))
db.completeLightningOutgoingPaymentPart(payment.request.paymentId, event.paymentId, preimage)
db.completeLightningOutgoingPayment(payment.request.paymentId, preimage)
removeFromState(payment.request.paymentId)
val status = LightningOutgoingPayment.Status.Succeeded(preimage)
val part = payment.pending.copy(status = LightningOutgoingPayment.Part.Status.Succeeded(preimage))
Expand All @@ -248,10 +248,10 @@ class OutgoingPaymentHandler(val nodeParams: NodeParams, val walletParams: Walle
}
else -> {
val logger = MDCLogger(logger, staticMdc = mapOf("childPaymentId" to partId) + payment.mdc())
db.completeLightningOutgoingPaymentPart(payment.id, partId, LightningOutgoingPayment.Part.Status.Succeeded(preimage))
db.completeLightningOutgoingPaymentPart(payment.id, partId, preimage)
logger.info { "payment successfully sent (wallet restart)" }
val request = PayInvoice(payment.id, payment.recipientAmount, payment.details)
db.completeLightningOutgoingPayment(payment.id, LightningOutgoingPayment.Status.Succeeded(preimage))
db.completeLightningOutgoingPayment(payment.id, preimage)
removeFromState(payment.id)
// NB: we reload the payment to ensure all parts status are updated
// this payment cannot be null
Expand Down Expand Up @@ -330,6 +330,12 @@ class OutgoingPaymentHandler(val nodeParams: NodeParams, val walletParams: Walle
}
}

private suspend fun OutgoingPaymentsDb.completeLightningOutgoingPayment(id: UUID, preimage: ByteVector32) =
completeLightningOutgoingPayment(id, LightningOutgoingPayment.Status.Succeeded(preimage))

private suspend fun OutgoingPaymentsDb.completeLightningOutgoingPaymentPart(id: UUID, partId: UUID, preimage: ByteVector32) =
completeLightningOutgoingPaymentPart(id, partId, LightningOutgoingPayment.Part.Status.Succeeded(preimage))

private suspend fun OutgoingPaymentsDb.completeLightningOutgoingPayment(id: UUID, failure: FinalFailure) =
completeLightningOutgoingPayment(id, LightningOutgoingPayment.Status.Failed(failure))

Expand Down

0 comments on commit 6a87282

Please sign in to comment.