|
| 1 | +use gloo_storage::errors::StorageError; |
| 2 | +use std::fmt; |
| 3 | + |
| 4 | +#[derive(Debug)] |
| 5 | +#[allow(dead_code)] |
| 6 | +// copied from LDK lite |
| 7 | +/// An error that possibly needs to be handled by the user. |
| 8 | +pub enum Error { |
| 9 | + /// Returned when trying to start Mutiny while it is already running. |
| 10 | + AlreadyRunning, |
| 11 | + /// Returned when trying to stop Mutiny while it is not running. |
| 12 | + NotRunning, |
| 13 | + /// The funding transaction could not be created. |
| 14 | + FundingTxCreationFailed, |
| 15 | + /// A network connection has been closed. |
| 16 | + ConnectionFailed, |
| 17 | + /// Payment of the given invoice has already been initiated. |
| 18 | + NonUniquePaymentHash, |
| 19 | + /// The given invoice is invalid. |
| 20 | + InvoiceInvalid, |
| 21 | + /// Invoice creation failed. |
| 22 | + InvoiceCreationFailed, |
| 23 | + /// No route for the given target could be found. |
| 24 | + RoutingFailed, |
| 25 | + /// A given peer info could not be parsed. |
| 26 | + PeerInfoParseFailed, |
| 27 | + /// A channel could not be opened. |
| 28 | + ChannelCreationFailed, |
| 29 | + /// A channel could not be closed. |
| 30 | + ChannelClosingFailed, |
| 31 | + /// Persistence failed. |
| 32 | + PersistenceFailed, |
| 33 | + /// A wallet operation failed. |
| 34 | + WalletOperationFailed, |
| 35 | + /// A signing operation failed. |
| 36 | + WalletSigningFailed, |
| 37 | + /// A chain access operation failed. |
| 38 | + ChainAccessFailed, |
| 39 | +} |
| 40 | + |
| 41 | +impl fmt::Display for Error { |
| 42 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 43 | + match *self { |
| 44 | + Self::AlreadyRunning => write!(f, "Mutiny is already running."), |
| 45 | + Self::NotRunning => write!(f, "Mutiny is not running."), |
| 46 | + Self::FundingTxCreationFailed => { |
| 47 | + write!(f, "Funding transaction could not be created.") |
| 48 | + } |
| 49 | + Self::ConnectionFailed => write!(f, "Network connection closed."), |
| 50 | + Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."), |
| 51 | + Self::InvoiceInvalid => write!(f, "The given invoice is invalid."), |
| 52 | + Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."), |
| 53 | + Self::RoutingFailed => write!(f, "Failed to find route."), |
| 54 | + Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."), |
| 55 | + Self::ChannelCreationFailed => write!(f, "Failed to create channel."), |
| 56 | + Self::ChannelClosingFailed => write!(f, "Failed to close channel."), |
| 57 | + Self::PersistenceFailed => write!(f, "Failed to persist data."), |
| 58 | + Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."), |
| 59 | + Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."), |
| 60 | + Self::ChainAccessFailed => write!(f, "Failed to conduct chain access operation."), |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +impl std::error::Error for Error {} |
| 66 | + |
| 67 | +impl From<bdk::Error> for Error { |
| 68 | + fn from(e: bdk::Error) -> Self { |
| 69 | + match e { |
| 70 | + bdk::Error::Signer(_) => Self::WalletSigningFailed, |
| 71 | + _ => Self::WalletOperationFailed, |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +// todo uncomment when we add esplora stuff |
| 77 | +// impl From<esplora::EsploraError> for Error { |
| 78 | +// fn from(_e: esplora::EsploraError) -> Self { |
| 79 | +// Self::ChainAccessFailed |
| 80 | +// } |
| 81 | +// } |
| 82 | + |
| 83 | +impl From<StorageError> for Error { |
| 84 | + fn from(_e: StorageError) -> Self { |
| 85 | + Self::PersistenceFailed |
| 86 | + } |
| 87 | +} |
0 commit comments