error.rs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. // Hello developer. Please add your error to the according subsection
  19. // that is commented, or make a new subsection. Keep it clean.
  20. /// Main result type used throughout the codebase.
  21. pub type Result<T> = std::result::Result<T, Error>;
  22. /// Result type used in the Client module
  23. pub type ClientResult<T> = std::result::Result<T, ClientFailed>;
  24. /// General library errors used throughout the codebase.
  25. #[derive(Debug, Clone, thiserror::Error)]
  26. pub enum Error {
  27. // ==============
  28. // Parsing errors
  29. // ==============
  30. #[error("Parse failed: {0}")]
  31. ParseFailed(&'static str),
  32. #[error(transparent)]
  33. ParseIntError(#[from] std::num::ParseIntError),
  34. #[error(transparent)]
  35. ParseFloatError(#[from] std::num::ParseFloatError),
  36. #[cfg(feature = "url")]
  37. #[error(transparent)]
  38. UrlParseError(#[from] url::ParseError),
  39. #[error("URL parse error: {0}")]
  40. UrlParse(String),
  41. #[error(transparent)]
  42. AddrParseError(#[from] std::net::AddrParseError),
  43. #[error("Could not parse token parameter")]
  44. TokenParseError,
  45. #[error(transparent)]
  46. TryFromSliceError(#[from] std::array::TryFromSliceError),
  47. #[cfg(feature = "dashu")]
  48. #[error(transparent)]
  49. DashuConversionError(#[from] dashu::base::error::ConversionError),
  50. #[cfg(feature = "dashu")]
  51. #[error(transparent)]
  52. DashuParseError(#[from] dashu::base::error::ParseError),
  53. #[cfg(feature = "semver")]
  54. #[error("semver parse error: {0}")]
  55. SemverError(String),
  56. // ===============
  57. // Encoding errors
  58. // ===============
  59. #[error("decode failed: {0}")]
  60. DecodeError(&'static str),
  61. #[error("encode failed: {0}")]
  62. EncodeError(&'static str),
  63. #[error("VarInt was encoded in a non-minimal way")]
  64. NonMinimalVarInt,
  65. #[error(transparent)]
  66. Utf8Error(#[from] std::string::FromUtf8Error),
  67. #[error(transparent)]
  68. StrUtf8Error(#[from] std::str::Utf8Error),
  69. #[cfg(feature = "serde_json")]
  70. #[error("serde_json error: {0}")]
  71. SerdeJsonError(String),
  72. #[cfg(feature = "tinyjson")]
  73. #[error("JSON parse error: {0}")]
  74. JsonParseError(String),
  75. #[cfg(feature = "tinyjson")]
  76. #[error("JSON generate error: {0}")]
  77. JsonGenerateError(String),
  78. #[cfg(feature = "toml")]
  79. #[error(transparent)]
  80. TomlDeserializeError(#[from] toml::de::Error),
  81. #[cfg(feature = "bs58")]
  82. #[error(transparent)]
  83. Bs58DecodeError(#[from] bs58::decode::Error),
  84. #[error("Bad operation type byte")]
  85. BadOperationType,
  86. // ======================
  87. // Network-related errors
  88. // ======================
  89. #[error("Invalid Dialer scheme")]
  90. InvalidDialerScheme,
  91. #[error("Invalid Listener scheme")]
  92. InvalidListenerScheme,
  93. #[error("Unsupported network transport: {0}")]
  94. UnsupportedTransport(String),
  95. #[error("Unsupported network transport upgrade: {0}")]
  96. UnsupportedTransportUpgrade(String),
  97. #[error("Connection failed")]
  98. ConnectFailed,
  99. #[cfg(feature = "system")]
  100. #[error(transparent)]
  101. TimeoutError(#[from] crate::system::timeout::TimeoutError),
  102. #[error("Connection timed out")]
  103. ConnectTimeout,
  104. #[error("Channel stopped")]
  105. ChannelStopped,
  106. #[error("Channel timed out")]
  107. ChannelTimeout,
  108. #[error("Network service stopped")]
  109. NetworkServiceStopped,
  110. #[error("Create listener bound to {0} failed")]
  111. BindFailed(String),
  112. #[error("Accept a new incoming connection from the listener {0} failed")]
  113. AcceptConnectionFailed(String),
  114. #[error("Accept a new tls connection from the listener {0} failed")]
  115. AcceptTlsConnectionFailed(String),
  116. #[error("Network operation failed")]
  117. NetworkOperationFailed,
  118. #[cfg(feature = "arti-client")]
  119. #[error(transparent)]
  120. ArtiError(#[from] arti_client::Error),
  121. #[error("Malformed packet")]
  122. MalformedPacket,
  123. #[error("Socks proxy error: {0}")]
  124. SocksError(String),
  125. #[error("No Socks5 URL found")]
  126. NoSocks5UrlFound,
  127. #[error("No URL found")]
  128. NoUrlFound,
  129. #[cfg(feature = "async-tungstenite")]
  130. #[error("tungstenite error: {0}")]
  131. TungsteniteError(String),
  132. #[error("Tor error: {0}")]
  133. TorError(String),
  134. #[error("Node is not connected to other nodes.")]
  135. NetworkNotConnected,
  136. #[error("P2P network stopped")]
  137. P2PNetworkStopped,
  138. // =============
  139. // Crypto errors
  140. // =============
  141. #[cfg(feature = "halo2_proofs")]
  142. #[error("halo2 plonk error: {0}")]
  143. PlonkError(String),
  144. #[error("Unable to decrypt mint note: {0}")]
  145. NoteDecryptionFailed(String),
  146. #[error("No keypair file detected")]
  147. KeypairPathNotFound,
  148. #[error("Failed converting bytes to PublicKey")]
  149. PublicKeyFromBytes,
  150. #[error("Failed converting bytes to Coin")]
  151. CoinFromBytes,
  152. #[error("Failed converting bytes to SecretKey")]
  153. SecretKeyFromBytes,
  154. #[error("Failed converting b58 string to PublicKey")]
  155. PublicKeyFromStr,
  156. #[error("Failed converting bs58 string to SecretKey")]
  157. SecretKeyFromStr,
  158. #[error("Invalid DarkFi address")]
  159. InvalidAddress,
  160. #[cfg(feature = "async-rustls")]
  161. #[error(transparent)]
  162. RustlsError(#[from] async_rustls::rustls::Error),
  163. #[cfg(feature = "async-rustls")]
  164. #[error("Invalid DNS Name {0}")]
  165. RustlsInvalidDns(String),
  166. #[error("unable to decrypt rcpt")]
  167. TxRcptDecryptionError,
  168. #[cfg(feature = "blake3")]
  169. #[error(transparent)]
  170. Blake3FromHexError(#[from] blake3::HexError),
  171. // =======================
  172. // Protocol-related errors
  173. // =======================
  174. #[error("Unsupported chain")]
  175. UnsupportedChain,
  176. #[error("JSON-RPC error: {0:?}")]
  177. JsonRpcError((i32, String)),
  178. #[cfg(feature = "rpc")]
  179. #[error(transparent)]
  180. RpcServerError(RpcError),
  181. #[error("JSON-RPC server stopped")]
  182. RPCServerStopped,
  183. #[error("Unexpected JSON-RPC data received: {0}")]
  184. UnexpectedJsonRpc(String),
  185. #[error("Received proposal from unknown node")]
  186. UnknownNodeError,
  187. #[error("Public inputs are invalid")]
  188. InvalidPublicInputsError,
  189. #[error("Coin is not the slot block producer")]
  190. CoinIsNotSlotProducer,
  191. #[error("Error during leader proof verification")]
  192. LeaderProofVerification,
  193. #[error("Signature could not be verified")]
  194. InvalidSignature,
  195. #[error("State transition failed")]
  196. StateTransitionError,
  197. #[error("Check if proposal extends any existing fork chains failed")]
  198. ExtendedChainIndexNotFound,
  199. #[error("Proposal received after finalization sync period")]
  200. ProposalAfterFinalizationError,
  201. #[error("Proposal received not for current slot")]
  202. ProposalNotForCurrentSlotError,
  203. #[error("Proposal contains missmatched hashes")]
  204. ProposalHashesMissmatchError,
  205. #[error("Proposal contains unknown slots")]
  206. ProposalContainsUnknownSlots,
  207. #[error("Proposal contains missmatched headers")]
  208. ProposalHeadersMissmatchError,
  209. #[error("Proposal contains different coin creation eta")]
  210. ProposalDifferentCoinEtaError,
  211. #[error("Proposal contains spent coin")]
  212. ProposalIsSpent,
  213. #[error("Proposal contains more transactions than configured cap")]
  214. ProposalTxsExceedCapError,
  215. #[error("Unable to verify transfer transaction")]
  216. TransferTxVerification,
  217. #[error("Unable to verify proposed mu values")]
  218. ProposalPublicValuesMismatched,
  219. #[error("Proposer is not eligible to produce proposals")]
  220. ProposalProposerNotEligible,
  221. #[error("Erroneous transactions detected")]
  222. ErroneousTxsDetected,
  223. #[error("Proposal task stopped")]
  224. ProposalTaskStopped,
  225. // ===============
  226. // Database errors
  227. // ===============
  228. #[cfg(feature = "rusqlite")]
  229. #[error("rusqlite error: {0}")]
  230. RusqliteError(String),
  231. #[cfg(feature = "sled")]
  232. #[error(transparent)]
  233. SledError(#[from] sled::Error),
  234. #[cfg(feature = "sled")]
  235. #[error(transparent)]
  236. SledTransactionError(#[from] sled::transaction::TransactionError),
  237. #[error("Transaction {0} not found in database")]
  238. TransactionNotFound(String),
  239. #[error("Transaction already seen")]
  240. TransactionAlreadySeen,
  241. #[error("Input vectors have different length")]
  242. InvalidInputLengths,
  243. #[error("Header {0} not found in database")]
  244. HeaderNotFound(String),
  245. #[error("Block {0} is invalid")]
  246. BlockIsInvalid(String),
  247. #[error("Block {0} already in database")]
  248. BlockAlreadyExists(String),
  249. #[error("Block {0} not found in database")]
  250. BlockNotFound(String),
  251. #[error("Block with order number {0} not found in database")]
  252. BlockNumberNotFound(u64),
  253. #[error("Verifying slot missmatch")]
  254. VerifyingSlotMissmatch(),
  255. #[error("Slot {0} is invalid")]
  256. SlotIsInvalid(u64),
  257. #[error("Slot {0} not found in database")]
  258. SlotNotFound(u64),
  259. #[error("Future slot {0} was received")]
  260. FutureSlotReceived(u64),
  261. #[error("Contract {0} not found in database")]
  262. ContractNotFound(String),
  263. #[error("Contract state tree not found")]
  264. ContractStateNotFound,
  265. #[error("Contract already initialized")]
  266. ContractAlreadyInitialized,
  267. #[error("zkas bincode not found in sled database")]
  268. ZkasBincodeNotFound,
  269. // =============
  270. // Wallet errors
  271. // =============
  272. #[error("Wallet password is empty")]
  273. WalletEmptyPassword,
  274. #[error("Merkle tree already exists in wallet")]
  275. WalletTreeExists,
  276. #[error("Wallet insufficient balance")]
  277. WalletInsufficientBalance,
  278. // ===================
  279. // wasm runtime errors
  280. // ===================
  281. #[cfg(feature = "wasm-runtime")]
  282. #[error("Wasmer compile error: {0}")]
  283. WasmerCompileError(String),
  284. #[cfg(feature = "wasm-runtime")]
  285. #[error("Wasmer export error: {0}")]
  286. WasmerExportError(String),
  287. #[cfg(feature = "wasm-runtime")]
  288. #[error("Wasmer runtime error: {0}")]
  289. WasmerRuntimeError(String),
  290. #[cfg(feature = "wasm-runtime")]
  291. #[error("Wasmer instantiation error: {0}")]
  292. WasmerInstantiationError(String),
  293. #[cfg(feature = "wasm-runtime")]
  294. #[error("wasm memory error")]
  295. WasmerMemoryError(String),
  296. #[cfg(feature = "wasm-runtime")]
  297. #[error("wasm runtime out of memory")]
  298. WasmerOomError(String),
  299. #[cfg(feature = "darkfi-sdk")]
  300. #[error("Contract execution failed")]
  301. ContractError(darkfi_sdk::error::ContractError),
  302. #[cfg(feature = "wasm-runtime")]
  303. #[error("contract wasm bincode not found")]
  304. WasmBincodeNotFound,
  305. #[cfg(feature = "wasm-runtime")]
  306. #[error("contract initialize error")]
  307. ContractInitError(u64),
  308. #[cfg(feature = "wasm-runtime")]
  309. #[error("contract execution error")]
  310. ContractExecError(u64),
  311. // ====================
  312. // Miscellaneous errors
  313. // ====================
  314. #[error("IO error: {0}")]
  315. Io(std::io::ErrorKind),
  316. #[error("Infallible error: {0}")]
  317. InfallibleError(String),
  318. #[cfg(feature = "smol")]
  319. #[error("async_channel sender error: {0}")]
  320. AsyncChannelSendError(String),
  321. #[cfg(feature = "smol")]
  322. #[error("async_channel receiver error: {0}")]
  323. AsyncChannelRecvError(String),
  324. #[error("SetLogger (log crate) failed: {0}")]
  325. SetLoggerError(String),
  326. #[error("ValueIsNotObject")]
  327. ValueIsNotObject,
  328. #[error("No config file detected")]
  329. ConfigNotFound,
  330. #[error("Invalid config file detected")]
  331. ConfigInvalid,
  332. #[error("Failed decoding bincode: {0}")]
  333. ZkasDecoderError(String),
  334. #[cfg(feature = "util")]
  335. #[error("System clock is not correct!")]
  336. InvalidClock,
  337. #[error("Unsupported OS")]
  338. UnsupportedOS,
  339. #[error("System clock went backwards")]
  340. BackwardsTime(std::time::SystemTimeError),
  341. #[error("Detached task stopped")]
  342. DetachedTaskStopped,
  343. // ==============================================
  344. // Wrappers for other error types in this library
  345. // ==============================================
  346. #[error(transparent)]
  347. ClientFailed(#[from] ClientFailed),
  348. #[cfg(feature = "tx")]
  349. #[error(transparent)]
  350. TxVerifyFailed(#[from] TxVerifyFailed),
  351. //=============
  352. // clock
  353. //=============
  354. #[error("clock out of sync with peers: {0}")]
  355. ClockOutOfSync(String),
  356. // ================
  357. // DHT/Geode errors
  358. // ================
  359. #[error("Geode needs garbage collection")]
  360. GeodeNeedsGc,
  361. #[error("Geode file not found")]
  362. GeodeFileNotFound,
  363. #[error("Geode chunk not found")]
  364. GeodeChunkNotFound,
  365. #[error("Geode file route not found")]
  366. GeodeFileRouteNotFound,
  367. #[error("Geode chunk route not found")]
  368. GeodeChunkRouteNotFound,
  369. // =========
  370. // Catch-all
  371. // =========
  372. #[error("{0}")]
  373. Custom(String),
  374. }
  375. #[cfg(feature = "tx")]
  376. impl Error {
  377. /// Auxiliary function to retrieve the vector of erroneous
  378. /// transactions from a TxVerifyFailed error.
  379. /// In any other case, we return the error itself.
  380. pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
  381. if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
  382. return Ok(erroneous_txs.clone())
  383. };
  384. Err(self.clone())
  385. }
  386. }
  387. #[cfg(feature = "tx")]
  388. /// Transaction verification errors
  389. #[derive(Debug, Clone, thiserror::Error)]
  390. pub enum TxVerifyFailed {
  391. #[error("Transaction {0} already exists")]
  392. AlreadySeenTx(String),
  393. #[error("Invalid transaction signature")]
  394. InvalidSignature,
  395. #[error("Missing signatures in transaction")]
  396. MissingSignatures,
  397. #[error("Missing contract calls in transaction")]
  398. MissingCalls,
  399. #[error("Missing Money::Fee call in transaction")]
  400. MissingFee,
  401. #[error("Invalid ZK proof in transaction")]
  402. InvalidZkProof,
  403. #[error("Erroneous transactions found")]
  404. ErroneousTxs(Vec<crate::tx::Transaction>),
  405. }
  406. /// Client module errors
  407. #[derive(Debug, Clone, thiserror::Error)]
  408. pub enum ClientFailed {
  409. #[error("IO error: {0}")]
  410. Io(std::io::ErrorKind),
  411. #[error("Not enough value: {0}")]
  412. NotEnoughValue(u64),
  413. #[error("Invalid address: {0}")]
  414. InvalidAddress(String),
  415. #[error("Invalid amount: {0}")]
  416. InvalidAmount(u64),
  417. #[error("Invalid token ID: {0}")]
  418. InvalidTokenId(String),
  419. #[error("Internal error: {0}")]
  420. InternalError(String),
  421. #[error("Verify error: {0}")]
  422. VerifyError(String),
  423. }
  424. #[cfg(feature = "rpc")]
  425. #[derive(Clone, Debug, thiserror::Error)]
  426. pub enum RpcError {
  427. #[error("Connection closed: {0}")]
  428. ConnectionClosed(String),
  429. #[error("Invalid JSON: {0}")]
  430. InvalidJson(String),
  431. #[error("IO Error: {0}")]
  432. IoError(std::io::ErrorKind),
  433. }
  434. #[cfg(feature = "rpc")]
  435. impl From<std::io::Error> for RpcError {
  436. fn from(err: std::io::Error) -> Self {
  437. Self::IoError(err.kind())
  438. }
  439. }
  440. #[cfg(feature = "rpc")]
  441. impl From<RpcError> for Error {
  442. fn from(err: RpcError) -> Self {
  443. Self::RpcServerError(err)
  444. }
  445. }
  446. impl From<Error> for ClientFailed {
  447. fn from(err: Error) -> Self {
  448. Self::InternalError(err.to_string())
  449. }
  450. }
  451. impl From<std::io::Error> for ClientFailed {
  452. fn from(err: std::io::Error) -> Self {
  453. Self::Io(err.kind())
  454. }
  455. }
  456. impl From<std::io::Error> for Error {
  457. fn from(err: std::io::Error) -> Self {
  458. Self::Io(err.kind())
  459. }
  460. }
  461. impl From<std::time::SystemTimeError> for Error {
  462. fn from(err: std::time::SystemTimeError) -> Self {
  463. Self::BackwardsTime(err)
  464. }
  465. }
  466. impl From<std::convert::Infallible> for Error {
  467. fn from(err: std::convert::Infallible) -> Self {
  468. Self::InfallibleError(err.to_string())
  469. }
  470. }
  471. impl From<()> for Error {
  472. fn from(_err: ()) -> Self {
  473. Self::InfallibleError("Infallible".into())
  474. }
  475. }
  476. #[cfg(feature = "smol")]
  477. impl<T> From<smol::channel::SendError<T>> for Error {
  478. fn from(err: smol::channel::SendError<T>) -> Self {
  479. Self::AsyncChannelSendError(err.to_string())
  480. }
  481. }
  482. #[cfg(feature = "smol")]
  483. impl From<smol::channel::RecvError> for Error {
  484. fn from(err: smol::channel::RecvError) -> Self {
  485. Self::AsyncChannelRecvError(err.to_string())
  486. }
  487. }
  488. impl From<log::SetLoggerError> for Error {
  489. fn from(err: log::SetLoggerError) -> Self {
  490. Self::SetLoggerError(err.to_string())
  491. }
  492. }
  493. #[cfg(feature = "rusqlite")]
  494. impl From<rusqlite::Error> for Error {
  495. fn from(err: rusqlite::Error) -> Self {
  496. Self::RusqliteError(err.to_string())
  497. }
  498. }
  499. #[cfg(feature = "halo2_proofs")]
  500. impl From<halo2_proofs::plonk::Error> for Error {
  501. fn from(err: halo2_proofs::plonk::Error) -> Self {
  502. Self::PlonkError(err.to_string())
  503. }
  504. }
  505. #[cfg(feature = "semver")]
  506. impl From<semver::Error> for Error {
  507. fn from(err: semver::Error) -> Self {
  508. Self::SemverError(err.to_string())
  509. }
  510. }
  511. /*
  512. #[cfg(feature = "tungstenite")]
  513. impl From<tungstenite::Error> for Error {
  514. fn from(err: tungstenite::Error) -> Self {
  515. Self::TungsteniteError(err.to_string())
  516. }
  517. }
  518. */
  519. #[cfg(feature = "async-tungstenite")]
  520. impl From<async_tungstenite::tungstenite::Error> for Error {
  521. fn from(err: async_tungstenite::tungstenite::Error) -> Self {
  522. Self::TungsteniteError(err.to_string())
  523. }
  524. }
  525. #[cfg(feature = "async-rustls")]
  526. impl From<async_rustls::rustls::client::InvalidDnsNameError> for Error {
  527. fn from(err: async_rustls::rustls::client::InvalidDnsNameError) -> Self {
  528. Self::RustlsInvalidDns(err.to_string())
  529. }
  530. }
  531. #[cfg(feature = "serde_json")]
  532. impl From<serde_json::Error> for Error {
  533. fn from(err: serde_json::Error) -> Self {
  534. Self::SerdeJsonError(err.to_string())
  535. }
  536. }
  537. #[cfg(feature = "tinyjson")]
  538. impl From<tinyjson::JsonParseError> for Error {
  539. fn from(err: tinyjson::JsonParseError) -> Self {
  540. Self::JsonParseError(err.to_string())
  541. }
  542. }
  543. #[cfg(feature = "tinyjson")]
  544. impl From<tinyjson::JsonGenerateError> for Error {
  545. fn from(err: tinyjson::JsonGenerateError) -> Self {
  546. Self::JsonGenerateError(err.to_string())
  547. }
  548. }
  549. #[cfg(feature = "fast-socks5")]
  550. impl From<fast_socks5::SocksError> for Error {
  551. fn from(err: fast_socks5::SocksError) -> Self {
  552. Self::SocksError(err.to_string())
  553. }
  554. }
  555. #[cfg(feature = "wasm-runtime")]
  556. impl From<wasmer::CompileError> for Error {
  557. fn from(err: wasmer::CompileError) -> Self {
  558. Self::WasmerCompileError(err.to_string())
  559. }
  560. }
  561. #[cfg(feature = "wasm-runtime")]
  562. impl From<wasmer::ExportError> for Error {
  563. fn from(err: wasmer::ExportError) -> Self {
  564. Self::WasmerExportError(err.to_string())
  565. }
  566. }
  567. #[cfg(feature = "wasm-runtime")]
  568. impl From<wasmer::RuntimeError> for Error {
  569. fn from(err: wasmer::RuntimeError) -> Self {
  570. Self::WasmerRuntimeError(err.to_string())
  571. }
  572. }
  573. #[cfg(feature = "wasm-runtime")]
  574. impl From<wasmer::InstantiationError> for Error {
  575. fn from(err: wasmer::InstantiationError) -> Self {
  576. Self::WasmerInstantiationError(err.to_string())
  577. }
  578. }
  579. #[cfg(feature = "wasm-runtime")]
  580. impl From<wasmer::MemoryAccessError> for Error {
  581. fn from(err: wasmer::MemoryAccessError) -> Self {
  582. Self::WasmerMemoryError(err.to_string())
  583. }
  584. }
  585. #[cfg(feature = "wasm-runtime")]
  586. impl From<wasmer::MemoryError> for Error {
  587. fn from(err: wasmer::MemoryError) -> Self {
  588. Self::WasmerOomError(err.to_string())
  589. }
  590. }
  591. #[cfg(feature = "darkfi-sdk")]
  592. impl From<darkfi_sdk::error::ContractError> for Error {
  593. fn from(err: darkfi_sdk::error::ContractError) -> Self {
  594. Self::ContractError(err)
  595. }
  596. }