-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathErrors.kt
More file actions
125 lines (114 loc) · 7.67 KB
/
Copy pathErrors.kt
File metadata and controls
125 lines (114 loc) · 7.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// @file:Suppress("unused")
package to.bitkit.utils
import org.lightningdevkit.ldknode.BuildException
import org.lightningdevkit.ldknode.NodeException
open class AppError(
override val message: String? = null,
cause: Throwable? = null,
) : Exception(message, cause) {
constructor(cause: Throwable) : this(cause.message, cause)
}
sealed class ServiceError(message: String) : AppError(message) {
class NodeNotSetup : ServiceError("Node is not setup")
class NodeNotStarted : ServiceError("Node is not started")
class MnemonicNotFound : ServiceError("Mnemonic not found")
class NodeStillRunning : ServiceError("Node is still running")
class InvalidNodeSigningMessage : ServiceError("Invalid node signing message")
class CurrencyRateUnavailable : ServiceError("Currency rate unavailable")
class BlocktankInfoUnavailable : ServiceError("Blocktank info not available")
class GeoBlocked : ServiceError("Geo blocked user")
class GiftClaimPaymentNotReceived : ServiceError("Gift claim payment not received")
}
class HttpError(message: String, val code: Int = 500, cause: Throwable? = null) : AppError(message, cause)
// region ldk
class LdkError(private val inner: LdkException) : AppError("Unknown LDK error.") {
constructor(inner: BuildException) : this(LdkException.Build(inner))
constructor(inner: NodeException) : this(LdkException.Node(inner))
override val message get() = inner.message ?: super.message
sealed interface LdkException {
val message: String?
class Build(exception: BuildException) : LdkException {
override val message = when (exception) {
is BuildException.InvalidChannelMonitor -> "Invalid channel monitor."
is BuildException.InvalidSystemTime -> "Invalid system time."
is BuildException.InvalidListeningAddresses -> "Invalid listening addresses."
is BuildException.ReadFailed -> "Read failed."
is BuildException.WriteFailed -> "Write failed."
is BuildException.StoragePathAccessFailed -> "Storage path access failed."
is BuildException.KvStoreSetupFailed -> "KV store setup failed."
is BuildException.WalletSetupFailed -> "Wallet setup failed."
is BuildException.LoggerSetupFailed -> "Logger setup failed."
is BuildException.InvalidAnnouncementAddresses -> "Invalid announcement addresses"
is BuildException.InvalidNodeAlias -> "Invalid node alias"
is BuildException.NetworkMismatch -> "Network mismatch"
is BuildException.DangerousValue -> "Dangerous value"
else -> exception.message
}?.let { "LDK Build error: $it" }
}
class Node(exception: NodeException) : LdkException {
override val message = when (exception) {
is NodeException.AlreadyRunning -> "The node is already running."
is NodeException.NotRunning -> "The node is not running."
is NodeException.OnchainTxCreationFailed -> "Failed to create on-chain transaction."
is NodeException.ConnectionFailed -> "Connection failed."
is NodeException.InvoiceCreationFailed -> "Invoice creation failed."
is NodeException.InvoiceRequestCreationFailed -> "Invoice request creation failed."
is NodeException.OfferCreationFailed -> "Offer creation failed."
is NodeException.RefundCreationFailed -> "Refund creation failed."
is NodeException.PaymentSendingFailed -> "Payment sending failed."
is NodeException.ProbeSendingFailed -> "Probe sending failed."
is NodeException.ChannelCreationFailed -> "Channel creation failed."
is NodeException.ChannelClosingFailed -> "Channel closing failed."
is NodeException.ChannelConfigUpdateFailed -> "Channel configuration update failed."
is NodeException.PersistenceFailed -> "Persistence failed."
is NodeException.FeerateEstimationUpdateFailed -> "Feerate estimation update failed."
is NodeException.FeerateEstimationUpdateTimeout -> "Feerate estimation update timeout."
is NodeException.WalletOperationFailed -> "Wallet operation failed."
is NodeException.WalletOperationTimeout -> "Wallet operation timeout."
is NodeException.OnchainTxSigningFailed -> "On-chain transaction signing failed."
is NodeException.TxSyncFailed -> "Transaction synchronization failed."
is NodeException.TxSyncTimeout -> "Transaction synchronization timeout."
is NodeException.GossipUpdateFailed -> "Gossip update failed."
is NodeException.GossipUpdateTimeout -> "Gossip update timeout."
is NodeException.LiquidityRequestFailed -> "Liquidity request failed."
is NodeException.InvalidAddress -> "Invalid address."
is NodeException.InvalidSocketAddress -> "Invalid socket address."
is NodeException.InvalidPublicKey -> "Invalid public key."
is NodeException.InvalidSecretKey -> "Invalid secret key."
is NodeException.InvalidOfferId -> "Invalid offer ID."
is NodeException.InvalidNodeId -> "Invalid node ID."
is NodeException.InvalidPaymentId -> "Invalid payment ID."
is NodeException.InvalidPaymentHash -> "Invalid payment hash."
is NodeException.InvalidPaymentPreimage -> "Invalid payment preimage."
is NodeException.InvalidPaymentSecret -> "Invalid payment secret."
is NodeException.InvalidAmount -> "Invalid amount."
is NodeException.InvalidInvoice -> "Invalid invoice."
is NodeException.InvalidOffer -> "Invalid offer."
is NodeException.InvalidRefund -> "Invalid refund."
is NodeException.InvalidChannelId -> "Invalid channel ID."
is NodeException.InvalidNetwork -> "Invalid network."
is NodeException.DuplicatePayment -> "Duplicate payment."
is NodeException.UnsupportedCurrency -> "Unsupported currency."
is NodeException.InsufficientFunds -> "Insufficient funds."
is NodeException.LiquiditySourceUnavailable -> "Liquidity source unavailable."
is NodeException.LiquidityFeeTooHigh -> "Liquidity fee too high."
is NodeException.UriParameterParsingFailed -> "URI parameter parsing failed."
is NodeException.InvalidUri -> "Invalid URI."
is NodeException.InvalidQuantity -> "Invalid quantity."
is NodeException.InvalidNodeAlias -> "Invalid node alias."
is NodeException.InvalidCustomTlvs -> "Invalid custom TLVs"
is NodeException.InvalidDateTime -> "Invalid date time"
is NodeException.InvalidFeeRate -> "Invalid fee rate"
is NodeException.CannotRbfFundingTransaction -> "Cannot RBF funding transaction"
is NodeException.CoinSelectionFailed -> "Coin selection failed"
is NodeException.NoSpendableOutputs -> "No spendable outputs"
is NodeException.TransactionAlreadyConfirmed -> "Transaction already confirmed"
is NodeException.TransactionNotFound -> "Transaction not found"
is NodeException.RouteNotFound -> "Failed to find a route for fee estimation."
else -> exception.message
}?.let { "LDK Node error: $it" }
}
}
}
// endregion
fun Throwable.isTxSyncTimeout(): Boolean = this is NodeException.TxSyncTimeout || cause is NodeException.TxSyncTimeout