error.rs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 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 = "semver")]
  48. #[error("semver parse error: {0}")]
  49. SemverError(String),
  50. // ===============
  51. // Encoding errors
  52. // ===============
  53. #[error("decode failed: {0}")]
  54. DecodeError(&'static str),
  55. #[error("encode failed: {0}")]
  56. EncodeError(&'static str),
  57. #[error("VarInt was encoded in a non-minimal way")]
  58. NonMinimalVarInt,
  59. #[error(transparent)]
  60. Utf8Error(#[from] std::string::FromUtf8Error),
  61. #[error(transparent)]
  62. StrUtf8Error(#[from] std::str::Utf8Error),
  63. #[cfg(feature = "tinyjson")]
  64. #[error("JSON parse error: {0}")]
  65. JsonParseError(String),
  66. #[cfg(feature = "tinyjson")]
  67. #[error("JSON generate error: {0}")]
  68. JsonGenerateError(String),
  69. #[cfg(feature = "toml")]
  70. #[error(transparent)]
  71. TomlDeserializeError(#[from] toml::de::Error),
  72. #[cfg(feature = "bs58")]
  73. #[error(transparent)]
  74. Bs58DecodeError(#[from] bs58::decode::Error),
  75. #[error("Bad operation type byte")]
  76. BadOperationType,
  77. // ======================
  78. // Network-related errors
  79. // ======================
  80. #[error("Invalid Dialer scheme")]
  81. InvalidDialerScheme,
  82. #[error("Invalid Listener scheme")]
  83. InvalidListenerScheme,
  84. #[error("Unsupported network transport: {0}")]
  85. UnsupportedTransport(String),
  86. #[error("Unsupported network transport upgrade: {0}")]
  87. UnsupportedTransportUpgrade(String),
  88. #[error("Transport request exceeds number of accepted transports")]
  89. InvalidTransportRequest,
  90. #[error("Connection failed")]
  91. ConnectFailed,
  92. #[cfg(feature = "system")]
  93. #[error(transparent)]
  94. TimeoutError(#[from] crate::system::timeout::TimeoutError),
  95. #[error("Connection timed out")]
  96. ConnectTimeout,
  97. #[error("Channel stopped")]
  98. ChannelStopped,
  99. #[error("Channel timed out")]
  100. ChannelTimeout,
  101. #[error("Failed to reach any seeds")]
  102. SeedFailed,
  103. #[error("Network service stopped")]
  104. NetworkServiceStopped,
  105. #[error("Create listener bound to {0} failed")]
  106. BindFailed(String),
  107. #[error("Accept a new incoming connection from the listener {0} failed")]
  108. AcceptConnectionFailed(String),
  109. #[error("Accept a new tls connection from the listener {0} failed")]
  110. AcceptTlsConnectionFailed(String),
  111. #[error("Connector stopped")]
  112. ConnectorStopped,
  113. #[error("Network operation failed")]
  114. NetworkOperationFailed,
  115. #[error("Missing P2P message dispatcher")]
  116. MissingDispatcher,
  117. #[cfg(feature = "arti-client")]
  118. #[error(transparent)]
  119. ArtiError(#[from] arti_client::Error),
  120. #[error("Malformed packet")]
  121. MalformedPacket,
  122. #[error("Error decoding packet: {0}")]
  123. DecodePacket(String),
  124. #[error("Socks proxy error: {0}")]
  125. SocksError(String),
  126. #[error("No Socks5 URL found")]
  127. NoSocks5UrlFound,
  128. #[error("No URL found")]
  129. NoUrlFound,
  130. #[error("Tor error: {0}")]
  131. TorError(String),
  132. #[error("Node is not connected to other nodes.")]
  133. NetworkNotConnected,
  134. #[error("P2P network stopped")]
  135. P2PNetworkStopped,
  136. #[error("No such host color exists")]
  137. InvalidHostColor,
  138. #[error("No matching hostlist entry")]
  139. HostDoesNotExist,
  140. #[error("Invalid state transition: current_state={0}, end_state={1}")]
  141. HostStateBlocked(String, String),
  142. // =============
  143. // Crypto errors
  144. // =============
  145. #[cfg(feature = "halo2_proofs")]
  146. #[error("halo2 plonk error: {0}")]
  147. PlonkError(String),
  148. #[error("Wrong witness type at index: {0}")]
  149. WrongWitnessType(usize),
  150. #[error("Wrong witnesses count")]
  151. WrongWitnessesCount,
  152. #[error("Wrong public inputs count")]
  153. WrongPublicInputsCount,
  154. #[error("Unable to decrypt mint note: {0}")]
  155. NoteDecryptionFailed(String),
  156. #[error("No keypair file detected")]
  157. KeypairPathNotFound,
  158. #[error("Failed converting bytes to PublicKey")]
  159. PublicKeyFromBytes,
  160. #[error("Failed converting bytes to Coin")]
  161. CoinFromBytes,
  162. #[error("Failed converting bytes to SecretKey")]
  163. SecretKeyFromBytes,
  164. #[error("Failed converting b58 string to PublicKey")]
  165. PublicKeyFromStr,
  166. #[error("Failed converting bs58 string to SecretKey")]
  167. SecretKeyFromStr,
  168. #[error("Invalid DarkFi address")]
  169. InvalidAddress,
  170. #[error("unable to decrypt rcpt")]
  171. TxRcptDecryptionError,
  172. #[cfg(feature = "blake3")]
  173. #[error(transparent)]
  174. Blake3FromHexError(#[from] blake3::HexError),
  175. // =======================
  176. // Protocol-related errors
  177. // =======================
  178. #[error("Unsupported chain")]
  179. UnsupportedChain,
  180. #[error("JSON-RPC error: {0:?}")]
  181. JsonRpcError((i32, String)),
  182. #[cfg(feature = "rpc")]
  183. #[error(transparent)]
  184. RpcServerError(RpcError),
  185. #[cfg(feature = "rpc")]
  186. #[error("JSON-RPC connections exhausted")]
  187. RpcConnectionsExhausted,
  188. #[cfg(feature = "rpc")]
  189. #[error("JSON-RPC server stopped")]
  190. RpcServerStopped,
  191. #[cfg(feature = "rpc")]
  192. #[error("JSON-RPC client stopped")]
  193. RpcClientStopped,
  194. #[error("Unexpected JSON-RPC data received: {0}")]
  195. UnexpectedJsonRpc(String),
  196. #[error("Received proposal from unknown node")]
  197. UnknownNodeError,
  198. #[error("Public inputs are invalid")]
  199. InvalidPublicInputsError,
  200. #[error("Signature could not be verified")]
  201. InvalidSignature,
  202. #[error("State transition failed")]
  203. StateTransitionError,
  204. #[error("No forks exist")]
  205. ForksNotFound,
  206. #[error("Check if proposal extends any existing fork chains failed")]
  207. ExtendedChainIndexNotFound,
  208. #[error("Proposal contains missmatched hashes")]
  209. ProposalHashesMissmatchError,
  210. #[error("Proposal contains missmatched headers")]
  211. ProposalHeadersMissmatchError,
  212. #[error("Unable to verify transfer transaction")]
  213. TransferTxVerification,
  214. #[error("Erroneous transactions detected")]
  215. ErroneousTxsDetected,
  216. #[error("Proposal task stopped")]
  217. ProposalTaskStopped,
  218. #[error("Proposal already exists")]
  219. ProposalAlreadyExists,
  220. #[error("Consensus task stopped")]
  221. ConsensusTaskStopped,
  222. #[error("Miner task stopped")]
  223. MinerTaskStopped,
  224. #[error("Garbage collection task stopped")]
  225. GarbageCollectionTaskStopped,
  226. #[error("Calculated total work is zero")]
  227. PoWTotalWorkIsZero,
  228. #[error("Erroneous cutoff calculation")]
  229. PoWCuttofCalculationError,
  230. #[error("Provided timestamp is invalid")]
  231. PoWInvalidTimestamp,
  232. #[error("Provided output hash is greater than current target")]
  233. PoWInvalidOutHash,
  234. // ===============
  235. // Database errors
  236. // ===============
  237. #[cfg(feature = "rusqlite")]
  238. #[error("rusqlite error: {0}")]
  239. RusqliteError(String),
  240. #[cfg(feature = "sled")]
  241. #[error(transparent)]
  242. SledError(#[from] sled::Error),
  243. #[cfg(feature = "sled")]
  244. #[error(transparent)]
  245. SledTransactionError(#[from] sled::transaction::TransactionError),
  246. #[error("Transaction {0} not found in database")]
  247. TransactionNotFound(String),
  248. #[error("Transaction already seen")]
  249. TransactionAlreadySeen,
  250. #[error("Input vectors have different length")]
  251. InvalidInputLengths,
  252. #[error("Header {0} not found in database")]
  253. HeaderNotFound(String),
  254. #[error("Block {0} is invalid")]
  255. BlockIsInvalid(String),
  256. #[error("Block version {0} is invalid")]
  257. BlockVersionIsInvalid(u8),
  258. #[error("Block {0} already in database")]
  259. BlockAlreadyExists(String),
  260. #[error("Block {0} not found in database")]
  261. BlockNotFound(String),
  262. #[error("Block with height number {0} not found in database")]
  263. BlockHeightNotFound(u32),
  264. #[error("Block difficulty for height number {0} not found in database")]
  265. BlockDifficultyNotFound(u32),
  266. #[error("Block {0} contains 0 transactions")]
  267. BlockContainsNoTransactions(String),
  268. #[error("Contract {0} not found in database")]
  269. ContractNotFound(String),
  270. #[error("Contract state tree not found")]
  271. ContractStateNotFound,
  272. #[error("Contract already initialized")]
  273. ContractAlreadyInitialized,
  274. #[error("zkas bincode not found in sled database")]
  275. ZkasBincodeNotFound,
  276. // ===================
  277. // wasm runtime errors
  278. // ===================
  279. #[cfg(feature = "wasm-runtime")]
  280. #[error("Wasmer compile error: {0}")]
  281. WasmerCompileError(String),
  282. #[cfg(feature = "wasm-runtime")]
  283. #[error("Wasmer export error: {0}")]
  284. WasmerExportError(String),
  285. #[cfg(feature = "wasm-runtime")]
  286. #[error("Wasmer runtime error: {0}")]
  287. WasmerRuntimeError(String),
  288. #[cfg(feature = "wasm-runtime")]
  289. #[error("Wasmer instantiation error: {0}")]
  290. WasmerInstantiationError(String),
  291. #[cfg(feature = "wasm-runtime")]
  292. #[error("wasm memory error")]
  293. WasmerMemoryError(String),
  294. #[cfg(feature = "wasm-runtime")]
  295. #[error("wasm runtime out of memory")]
  296. WasmerOomError(String),
  297. #[cfg(feature = "darkfi-sdk")]
  298. #[error("Contract execution failed: {0}")]
  299. ContractError(darkfi_sdk::error::ContractError),
  300. #[cfg(feature = "darkfi-sdk")]
  301. #[error("Invalid DarkTree: {0}")]
  302. DarkTreeError(darkfi_sdk::error::DarkTreeError),
  303. #[cfg(feature = "blockchain")]
  304. #[error("contract wasm bincode not found")]
  305. WasmBincodeNotFound,
  306. #[cfg(feature = "wasm-runtime")]
  307. #[error("contract initialize error")]
  308. ContractInitError(u64),
  309. #[cfg(feature = "wasm-runtime")]
  310. #[error("contract execution error")]
  311. ContractExecError(u64),
  312. #[cfg(feature = "wasm-runtime")]
  313. #[error("wasm function ACL denied")]
  314. WasmFunctionAclDenied,
  315. // ====================
  316. // Event Graph errors
  317. // ====================
  318. #[error("Event is not found in tree: {0}")]
  319. EventNotFound(String),
  320. #[error("Event is invalid")]
  321. EventIsInvalid,
  322. // ====================
  323. // Miscellaneous errors
  324. // ====================
  325. #[error("IO error: {0}")]
  326. Io(std::io::ErrorKind),
  327. #[error("Infallible error: {0}")]
  328. InfallibleError(String),
  329. #[cfg(feature = "smol")]
  330. #[error("async_channel sender error: {0}")]
  331. AsyncChannelSendError(String),
  332. #[cfg(feature = "smol")]
  333. #[error("async_channel receiver error: {0}")]
  334. AsyncChannelRecvError(String),
  335. #[error("SetLogger (log crate) failed: {0}")]
  336. SetLoggerError(String),
  337. #[error("ValueIsNotObject")]
  338. ValueIsNotObject,
  339. #[error("No config file detected")]
  340. ConfigNotFound,
  341. #[error("Invalid config file detected")]
  342. ConfigInvalid,
  343. #[error("Failed decoding bincode: {0}")]
  344. ZkasDecoderError(String),
  345. #[cfg(feature = "util")]
  346. #[error("System clock is not correct!")]
  347. InvalidClock,
  348. #[error("Unsupported OS")]
  349. UnsupportedOS,
  350. #[error("System clock went backwards")]
  351. BackwardsTime(std::time::SystemTimeError),
  352. #[error("Detached task stopped")]
  353. DetachedTaskStopped,
  354. #[error("Addition overflow")]
  355. AdditionOverflow,
  356. #[error("Subtraction underflow")]
  357. SubtractionUnderflow,
  358. // ==============================================
  359. // Wrappers for other error types in this library
  360. // ==============================================
  361. #[error(transparent)]
  362. ClientFailed(#[from] ClientFailed),
  363. #[cfg(feature = "tx")]
  364. #[error(transparent)]
  365. TxVerifyFailed(#[from] TxVerifyFailed),
  366. //=============
  367. // clock
  368. //=============
  369. #[error("clock out of sync with peers: {0}")]
  370. ClockOutOfSync(String),
  371. // ================
  372. // DHT/Geode errors
  373. // ================
  374. #[error("Geode needs garbage collection")]
  375. GeodeNeedsGc,
  376. #[error("Geode file not found")]
  377. GeodeFileNotFound,
  378. #[error("Geode chunk not found")]
  379. GeodeChunkNotFound,
  380. #[error("Geode file route not found")]
  381. GeodeFileRouteNotFound,
  382. #[error("Geode chunk route not found")]
  383. GeodeChunkRouteNotFound,
  384. // ==================
  385. // Event Graph errors
  386. // ==================
  387. #[error("DAG sync failed")]
  388. DagSyncFailed,
  389. // =========
  390. // Catch-all
  391. // =========
  392. #[error("{0}")]
  393. Custom(String),
  394. }
  395. #[cfg(feature = "tx")]
  396. impl Error {
  397. /// Auxiliary function to retrieve the vector of erroneous
  398. /// transactions from a TxVerifyFailed error.
  399. /// In any other case, we return the error itself.
  400. pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
  401. if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
  402. return Ok(erroneous_txs.clone())
  403. };
  404. Err(self.clone())
  405. }
  406. }
  407. #[cfg(feature = "tx")]
  408. /// Transaction verification errors
  409. #[derive(Debug, Clone, thiserror::Error)]
  410. pub enum TxVerifyFailed {
  411. #[error("Transaction {0} already exists")]
  412. AlreadySeenTx(String),
  413. #[error("Invalid transaction signature")]
  414. InvalidSignature,
  415. #[error("Missing signatures in transaction")]
  416. MissingSignatures,
  417. #[error("Missing contract calls in transaction")]
  418. MissingCalls,
  419. #[error("Invalid ZK proof in transaction")]
  420. InvalidZkProof,
  421. #[error("Missing Money::Fee call in transaction")]
  422. MissingFee,
  423. #[error("Invalid Money::Fee call in transaction")]
  424. InvalidFee,
  425. #[error("Insufficient fee paid")]
  426. InsufficientFee,
  427. #[error("Erroneous transactions found")]
  428. ErroneousTxs(Vec<crate::tx::Transaction>),
  429. }
  430. /// Client module errors
  431. #[derive(Debug, Clone, thiserror::Error)]
  432. pub enum ClientFailed {
  433. #[error("IO error: {0}")]
  434. Io(std::io::ErrorKind),
  435. #[error("Not enough value: {0}")]
  436. NotEnoughValue(u64),
  437. #[error("Invalid address: {0}")]
  438. InvalidAddress(String),
  439. #[error("Invalid amount: {0}")]
  440. InvalidAmount(u64),
  441. #[error("Invalid token ID: {0}")]
  442. InvalidTokenId(String),
  443. #[error("Internal error: {0}")]
  444. InternalError(String),
  445. #[error("Verify error: {0}")]
  446. VerifyError(String),
  447. }
  448. #[cfg(feature = "rpc")]
  449. #[derive(Clone, Debug, thiserror::Error)]
  450. pub enum RpcError {
  451. #[error("Connection closed: {0}")]
  452. ConnectionClosed(String),
  453. #[error("Invalid JSON: {0}")]
  454. InvalidJson(String),
  455. #[error("IO Error: {0}")]
  456. IoError(std::io::ErrorKind),
  457. }
  458. #[cfg(feature = "rpc")]
  459. impl From<std::io::Error> for RpcError {
  460. fn from(err: std::io::Error) -> Self {
  461. Self::IoError(err.kind())
  462. }
  463. }
  464. #[cfg(feature = "rpc")]
  465. impl From<RpcError> for Error {
  466. fn from(err: RpcError) -> Self {
  467. Self::RpcServerError(err)
  468. }
  469. }
  470. impl From<Error> for ClientFailed {
  471. fn from(err: Error) -> Self {
  472. Self::InternalError(err.to_string())
  473. }
  474. }
  475. impl From<std::io::Error> for ClientFailed {
  476. fn from(err: std::io::Error) -> Self {
  477. Self::Io(err.kind())
  478. }
  479. }
  480. impl From<std::io::Error> for Error {
  481. fn from(err: std::io::Error) -> Self {
  482. Self::Io(err.kind())
  483. }
  484. }
  485. impl From<std::time::SystemTimeError> for Error {
  486. fn from(err: std::time::SystemTimeError) -> Self {
  487. Self::BackwardsTime(err)
  488. }
  489. }
  490. impl From<std::convert::Infallible> for Error {
  491. fn from(err: std::convert::Infallible) -> Self {
  492. Self::InfallibleError(err.to_string())
  493. }
  494. }
  495. impl From<()> for Error {
  496. fn from(_err: ()) -> Self {
  497. Self::InfallibleError("Infallible".into())
  498. }
  499. }
  500. #[cfg(feature = "net")]
  501. impl From<std::collections::TryReserveError> for Error {
  502. fn from(err: std::collections::TryReserveError) -> Self {
  503. Self::DecodePacket(err.to_string())
  504. }
  505. }
  506. #[cfg(feature = "smol")]
  507. impl<T> From<smol::channel::SendError<T>> for Error {
  508. fn from(err: smol::channel::SendError<T>) -> Self {
  509. Self::AsyncChannelSendError(err.to_string())
  510. }
  511. }
  512. #[cfg(feature = "smol")]
  513. impl From<smol::channel::RecvError> for Error {
  514. fn from(err: smol::channel::RecvError) -> Self {
  515. Self::AsyncChannelRecvError(err.to_string())
  516. }
  517. }
  518. impl From<log::SetLoggerError> for Error {
  519. fn from(err: log::SetLoggerError) -> Self {
  520. Self::SetLoggerError(err.to_string())
  521. }
  522. }
  523. #[cfg(feature = "rusqlite")]
  524. impl From<rusqlite::Error> for Error {
  525. fn from(err: rusqlite::Error) -> Self {
  526. Self::RusqliteError(err.to_string())
  527. }
  528. }
  529. #[cfg(feature = "halo2_proofs")]
  530. impl From<halo2_proofs::plonk::Error> for Error {
  531. fn from(err: halo2_proofs::plonk::Error) -> Self {
  532. Self::PlonkError(err.to_string())
  533. }
  534. }
  535. #[cfg(feature = "semver")]
  536. impl From<semver::Error> for Error {
  537. fn from(err: semver::Error) -> Self {
  538. Self::SemverError(err.to_string())
  539. }
  540. }
  541. #[cfg(feature = "tinyjson")]
  542. impl From<tinyjson::JsonParseError> for Error {
  543. fn from(err: tinyjson::JsonParseError) -> Self {
  544. Self::JsonParseError(err.to_string())
  545. }
  546. }
  547. #[cfg(feature = "tinyjson")]
  548. impl From<tinyjson::JsonGenerateError> for Error {
  549. fn from(err: tinyjson::JsonGenerateError) -> Self {
  550. Self::JsonGenerateError(err.to_string())
  551. }
  552. }
  553. #[cfg(feature = "wasm-runtime")]
  554. impl From<wasmer::CompileError> for Error {
  555. fn from(err: wasmer::CompileError) -> Self {
  556. Self::WasmerCompileError(err.to_string())
  557. }
  558. }
  559. #[cfg(feature = "wasm-runtime")]
  560. impl From<wasmer::ExportError> for Error {
  561. fn from(err: wasmer::ExportError) -> Self {
  562. Self::WasmerExportError(err.to_string())
  563. }
  564. }
  565. #[cfg(feature = "wasm-runtime")]
  566. impl From<wasmer::RuntimeError> for Error {
  567. fn from(err: wasmer::RuntimeError) -> Self {
  568. Self::WasmerRuntimeError(err.to_string())
  569. }
  570. }
  571. #[cfg(feature = "wasm-runtime")]
  572. impl From<wasmer::InstantiationError> for Error {
  573. fn from(err: wasmer::InstantiationError) -> Self {
  574. Self::WasmerInstantiationError(err.to_string())
  575. }
  576. }
  577. #[cfg(feature = "wasm-runtime")]
  578. impl From<wasmer::MemoryAccessError> for Error {
  579. fn from(err: wasmer::MemoryAccessError) -> Self {
  580. Self::WasmerMemoryError(err.to_string())
  581. }
  582. }
  583. #[cfg(feature = "wasm-runtime")]
  584. impl From<wasmer::MemoryError> for Error {
  585. fn from(err: wasmer::MemoryError) -> Self {
  586. Self::WasmerOomError(err.to_string())
  587. }
  588. }
  589. #[cfg(feature = "darkfi-sdk")]
  590. impl From<darkfi_sdk::error::ContractError> for Error {
  591. fn from(err: darkfi_sdk::error::ContractError) -> Self {
  592. Self::ContractError(err)
  593. }
  594. }
  595. #[cfg(feature = "darkfi-sdk")]
  596. impl From<darkfi_sdk::error::DarkTreeError> for Error {
  597. fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
  598. Self::DarkTreeError(err)
  599. }
  600. }