Skip to content

Commit cba7e7e

Browse files
authored
Make FinalFailure serializable for database storage (#239)
1 parent 524ab2e commit cba7e7e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/commonMain/kotlin/fr/acinq/eclair/payment/OutgoingPaymentFailure.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ import fr.acinq.eclair.db.OutgoingPayment
55
import fr.acinq.eclair.utils.Either
66
import fr.acinq.eclair.utils.currentTimestampMillis
77
import fr.acinq.eclair.wire.*
8+
import kotlinx.serialization.Serializable
89

910
/** A fatal failure that stops payment attempts. */
11+
@Serializable
1012
sealed class FinalFailure {
1113

1214
/** Use this function when no payment attempts have been made (e.g. when a precondition failed). */
1315
fun toPaymentFailure(): OutgoingPaymentFailure = OutgoingPaymentFailure(this, listOf<OutgoingPayment.Part.Status.Failed>())
1416

1517
// @formatter:off
16-
object InvalidPaymentAmount : FinalFailure() { override fun toString(): String = "payment amount must be positive" }
17-
object InvalidPaymentId : FinalFailure() { override fun toString(): String = "payment ID must be unique" }
18-
object NoAvailableChannels : FinalFailure() { override fun toString(): String = "no channels available to send payment" }
19-
object InsufficientBalance : FinalFailure() { override fun toString(): String = "not enough funds in wallet to afford payment" }
20-
object NoRouteToRecipient : FinalFailure() { override fun toString(): String = "unable to route payment to recipient" }
21-
object RecipientUnreachable : FinalFailure() { override fun toString(): String = "the recipient was offline or did not have enough liquidity to receive the payment" }
22-
object RetryExhausted: FinalFailure() { override fun toString(): String = "payment attempts exhausted without success" }
23-
object WalletRestarted: FinalFailure() { override fun toString(): String = "wallet restarted while a payment was ongoing" }
24-
object UnknownError : FinalFailure() { override fun toString(): String = "an unknown error occurred" }
18+
@Serializable object InvalidPaymentAmount : FinalFailure() { override fun toString(): String = "payment amount must be positive" }
19+
@Serializable object InvalidPaymentId : FinalFailure() { override fun toString(): String = "payment ID must be unique" }
20+
@Serializable object NoAvailableChannels : FinalFailure() { override fun toString(): String = "no channels available to send payment" }
21+
@Serializable object InsufficientBalance : FinalFailure() { override fun toString(): String = "not enough funds in wallet to afford payment" }
22+
@Serializable object NoRouteToRecipient : FinalFailure() { override fun toString(): String = "unable to route payment to recipient" }
23+
@Serializable object RecipientUnreachable : FinalFailure() { override fun toString(): String = "the recipient was offline or did not have enough liquidity to receive the payment" }
24+
@Serializable object RetryExhausted: FinalFailure() { override fun toString(): String = "payment attempts exhausted without success" }
25+
@Serializable object WalletRestarted: FinalFailure() { override fun toString(): String = "wallet restarted while a payment was ongoing" }
26+
@Serializable object UnknownError : FinalFailure() { override fun toString(): String = "an unknown error occurred" }
2527
// @formatter:on
2628
}
2729

0 commit comments

Comments
 (0)