1use std::net::AddrParseError;
2
3use downcast::DowncastError;
4use kaspa_wallet_core::error::Error as WalletError;
5use workflow_core::channel::ChannelError;
6use workflow_terminal::error::Error as TerminalError;
7
8use thiserror::Error;
9
10#[derive(Debug, Error)]
11pub enum Error {
12 #[error("{0}")]
13 Custom(String),
14
15 #[error("aborting")]
16 UserAbort,
17
18 #[error("platform is not supported")]
19 Platform,
20
21 #[error(transparent)]
22 WalletError(#[from] WalletError),
23
24 #[error("Cli error {0}")]
25 TerminalError(#[from] TerminalError),
26
27 #[error("Channel error")]
28 ChannelError(String),
29
30 #[error(transparent)]
31 WrpcError(#[from] kaspa_wrpc_client::error::Error),
32
33 #[error(transparent)]
34 RpcError(#[from] kaspa_rpc_core::RpcError),
35
36 #[error(transparent)]
37 SerdeJsonError(#[from] serde_json::Error),
38
39 #[error(transparent)]
40 ParseFloatError(#[from] std::num::ParseFloatError),
41
42 #[error(transparent)]
43 ParseIntError(#[from] std::num::ParseIntError),
44
45 #[error("invalid hex string: {0}")]
46 ParseHexError(#[from] faster_hex::Error),
47
48 #[error(transparent)]
49 AddrParseError(#[from] AddrParseError),
50
51 #[error("account '{0}' not found")]
52 AccountNotFound(String),
53
54 #[error("ambiguous selection, pattern '{0}' matches too many accounts, please be more specific")]
55 AmbiguousAccount(String),
56
57 #[error("please create a wallet")]
58 WalletDoesNotExist,
59
60 #[error("please open a wallet")]
61 WalletIsNotOpen,
62
63 #[error("unrecognized argument '{0}', accepted arguments are: {1}")]
64 UnrecognizedArgument(String, String),
65
66 #[error("multiple matches for argument '{0}'; please be more specific.")]
67 MultipleMatches(String),
68
69 #[error("account type must be <bip32|multisig|legacy>")]
70 InvalidAccountKind,
71
72 #[error("wallet secret is required")]
73 WalletSecretRequired,
74
75 #[error("watch-only wallet kpub is required")]
76 WalletBip32WatchXpubRequired,
77
78 #[error("wallet secrets do not match")]
79 WalletSecretMatch,
80
81 #[error("payment secret is required")]
82 PaymentSecretRequired,
83
84 #[error("payment secrets do not match")]
85 PaymentSecretMatch,
86
87 #[error("key data not found")]
88 KeyDataNotFound,
89
90 #[error("no key data to export for watch-only account")]
91 WatchOnlyAccountNoKeyData,
92
93 #[error("no accounts found, please create an account to continue")]
94 NoAccounts,
95
96 #[error("no private keys found in this wallet, please create a private key to continue")]
97 NoKeys,
98
99 #[error(transparent)]
100 AddressError(#[from] kaspa_addresses::AddressError),
101
102 #[error("{0}")]
103 DowncastError(String),
104
105 #[error(transparent)]
106 Store(#[from] workflow_store::error::Error),
107
108 #[error(transparent)]
109 NodeJs(#[from] workflow_node::error::Error),
110
111 #[error(transparent)]
112 Daemon(#[from] kaspa_daemon::error::Error),
113
114 #[error(transparent)]
115 Dom(#[from] workflow_dom::error::Error),
116
117 #[error(transparent)]
118 NetworkId(#[from] kaspa_consensus_core::network::NetworkIdError),
119
120 #[error(transparent)]
121 Bip32(#[from] kaspa_bip32::Error),
122
123 #[error("private key {0} already exists")]
124 PrivateKeyAlreadyExists(String),
125
126 #[error(transparent)]
127 MetricsError(kaspa_metrics_core::error::Error),
128
129 #[error(transparent)]
130 KaspaWalletKeys(#[from] kaspa_wallet_keys::error::Error),
131
132 #[error(transparent)]
133 PskbLockScriptSigError(#[from] kaspa_wallet_pskt::error::Error),
134
135 #[error("To hex serialization error")]
136 PskbSerializeToHexError,
137}
138
139impl Error {
140 pub fn custom<T: Into<String>>(msg: T) -> Self {
141 Error::Custom(msg.into())
142 }
143}
144
145impl From<Error> for TerminalError {
146 fn from(e: Error) -> TerminalError {
147 TerminalError::Custom(e.to_string())
148 }
149}
150
151impl<T> From<ChannelError<T>> for Error {
152 fn from(e: ChannelError<T>) -> Error {
153 Error::ChannelError(e.to_string())
154 }
155}
156
157impl From<String> for Error {
158 fn from(err: String) -> Self {
159 Self::Custom(err)
160 }
161}
162
163impl From<&str> for Error {
164 fn from(err: &str) -> Self {
165 Self::Custom(err.to_string())
166 }
167}
168
169impl<T> From<DowncastError<T>> for Error {
170 fn from(e: DowncastError<T>) -> Self {
171 Error::DowncastError(e.to_string())
172 }
173}