darkfi/
error.rs

1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2026 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
19// Hello developer. Please add your error to the according subsection
20// that is commented, or make a new subsection. Keep it clean.
21
22/// Main result type used throughout the codebase.
23pub type Result<T> = std::result::Result<T, Error>;
24
25/// Result type used in the Client module
26pub type ClientResult<T> = std::result::Result<T, ClientFailed>;
27
28/// General library errors used throughout the codebase.
29#[derive(Debug, Clone, thiserror::Error)]
30pub enum Error {
31    // ==============
32    // Parsing errors
33    // ==============
34    #[error("Parse failed: {0}")]
35    ParseFailed(&'static str),
36
37    #[error(transparent)]
38    ParseIntError(#[from] std::num::ParseIntError),
39
40    #[error(transparent)]
41    ParseFloatError(#[from] std::num::ParseFloatError),
42
43    #[cfg(feature = "url")]
44    #[error(transparent)]
45    UrlParseError(#[from] url::ParseError),
46
47    #[error("URL parse error: {0}")]
48    UrlParse(String),
49
50    #[error(transparent)]
51    AddrParseError(#[from] std::net::AddrParseError),
52
53    #[error("Could not parse token parameter")]
54    TokenParseError,
55
56    #[error(transparent)]
57    TryFromSliceError(#[from] std::array::TryFromSliceError),
58
59    #[cfg(feature = "semver")]
60    #[error("semver parse error: {0}")]
61    SemverError(String),
62
63    // ===============
64    // Encoding errors
65    // ===============
66    #[error("decode failed: {0}")]
67    DecodeError(&'static str),
68
69    #[error("encode failed: {0}")]
70    EncodeError(&'static str),
71
72    #[error("VarInt was encoded in a non-minimal way")]
73    NonMinimalVarInt,
74
75    #[error(transparent)]
76    Utf8Error(#[from] std::string::FromUtf8Error),
77
78    #[error(transparent)]
79    StrUtf8Error(#[from] std::str::Utf8Error),
80
81    #[cfg(feature = "tinyjson")]
82    #[error("JSON parse error: {0}")]
83    JsonParseError(String),
84
85    #[cfg(feature = "tinyjson")]
86    #[error("JSON generate error: {0}")]
87    JsonGenerateError(String),
88
89    #[cfg(feature = "toml")]
90    #[error(transparent)]
91    TomlDeserializeError(#[from] toml::de::Error),
92
93    #[cfg(feature = "bs58")]
94    #[error(transparent)]
95    Bs58DecodeError(#[from] bs58::decode::Error),
96
97    #[cfg(feature = "hex")]
98    #[error(transparent)]
99    HexDecodeError(#[from] hex::FromHexError),
100
101    #[error("Bad operation type byte")]
102    BadOperationType,
103
104    // ======================
105    // Network-related errors
106    // ======================
107    #[error("Invalid Dialer scheme")]
108    InvalidDialerScheme,
109
110    #[error("Invalid Listener scheme")]
111    InvalidListenerScheme,
112
113    #[error("Unsupported network transport: {0}")]
114    UnsupportedTransport(String),
115
116    #[error("Unsupported network transport upgrade: {0}")]
117    UnsupportedTransportUpgrade(String),
118
119    #[error("Transport request exceeds number of accepted transports")]
120    InvalidTransportRequest,
121
122    #[error("Connection failed: {0}")]
123    ConnectFailed(String),
124
125    #[cfg(feature = "system")]
126    #[error(transparent)]
127    TimeoutError(#[from] crate::system::timeout::TimeoutError),
128
129    #[error("Connection timed out")]
130    ConnectTimeout,
131
132    #[error("Channel stopped")]
133    ChannelStopped,
134
135    #[error("Channel timed out")]
136    ChannelTimeout,
137
138    #[error("Failed to reach any seeds")]
139    SeedFailed,
140
141    #[error("Network service stopped")]
142    NetworkServiceStopped,
143
144    #[error("Create listener bound to {0} failed")]
145    BindFailed(String),
146
147    #[error("Accept a new incoming connection from the listener {0} failed")]
148    AcceptConnectionFailed(String),
149
150    #[error("Accept a new tls connection from the listener {0} failed")]
151    AcceptTlsConnectionFailed(String),
152
153    #[error("Connector stopped: {0}")]
154    ConnectorStopped(String),
155
156    #[error("Network operation failed")]
157    NetworkOperationFailed,
158
159    #[error("Missing P2P message dispatcher")]
160    MissingDispatcher,
161
162    #[error("P2P message is invalid")]
163    MessageInvalid,
164
165    #[error("P2P message subsystem over metering limit")]
166    MeteringLimitExceeded,
167
168    #[cfg(feature = "arti-client")]
169    #[error(transparent)]
170    ArtiError(#[from] arti_client::Error),
171
172    #[error("Malformed packet")]
173    MalformedPacket,
174
175    #[error("Error decoding packet: {0}")]
176    DecodePacket(String),
177
178    #[error("Socks proxy error: {0}")]
179    SocksError(String),
180
181    #[error("No Socks5 URL found")]
182    NoSocks5UrlFound,
183
184    #[error("No URL found")]
185    NoUrlFound,
186
187    #[error("Tor error: {0}")]
188    TorError(String),
189
190    #[error("Node is not connected to other nodes.")]
191    NetworkNotConnected,
192
193    #[error("P2P network stopped")]
194    P2PNetworkStopped,
195
196    #[error("No such host color exists")]
197    InvalidHostColor,
198
199    #[error("No matching hostlist entry")]
200    HostDoesNotExist,
201
202    #[error("Invalid state transition: current_state={0}, end_state={1}")]
203    HostStateBlocked(String, String),
204
205    #[cfg(feature = "upnp-igd")]
206    #[error(transparent)]
207    UpnpError(#[from] oxy_upnp_igd::Error),
208
209    // =============
210    // Crypto errors
211    // =============
212    #[cfg(feature = "halo2_proofs")]
213    #[error("halo2 plonk error: {0}")]
214    PlonkError(String),
215
216    #[error("Wrong witness type at index: {0}")]
217    WrongWitnessType(usize),
218
219    #[error("Wrong witnesses count")]
220    WrongWitnessesCount,
221
222    #[error("Wrong public inputs count")]
223    WrongPublicInputsCount,
224
225    #[error("Unable to decrypt mint note: {0}")]
226    NoteDecryptionFailed(String),
227
228    #[error("No keypair file detected")]
229    KeypairPathNotFound,
230
231    #[error("Failed converting bytes to PublicKey")]
232    PublicKeyFromBytes,
233
234    #[error("Failed converting bytes to Coin")]
235    CoinFromBytes,
236
237    #[error("Failed converting bytes to SecretKey")]
238    SecretKeyFromBytes,
239
240    #[error("Failed converting b58 string to PublicKey")]
241    PublicKeyFromStr,
242
243    #[error("Failed converting bs58 string to SecretKey")]
244    SecretKeyFromStr,
245
246    #[error("Invalid DarkFi address")]
247    InvalidAddress,
248
249    #[error("unable to decrypt rcpt")]
250    TxRcptDecryptionError,
251
252    #[cfg(feature = "blake3")]
253    #[error(transparent)]
254    Blake3FromHexError(#[from] blake3::HexError),
255
256    // =======================
257    // Protocol-related errors
258    // =======================
259    #[error("Unsupported chain")]
260    UnsupportedChain,
261
262    #[error("JSON-RPC error: {0:?}")]
263    JsonRpcError((i32, String)),
264
265    #[cfg(feature = "rpc")]
266    #[error(transparent)]
267    RpcServerError(RpcError),
268
269    #[cfg(feature = "rpc")]
270    #[error("JSON-RPC connections exhausted")]
271    RpcConnectionsExhausted,
272
273    #[cfg(feature = "rpc")]
274    #[error("JSON-RPC server stopped")]
275    RpcServerStopped,
276
277    #[cfg(feature = "rpc")]
278    #[error("JSON-RPC client stopped")]
279    RpcClientStopped,
280
281    #[error("Unexpected JSON-RPC data received: {0}")]
282    UnexpectedJsonRpc(String),
283
284    #[error("Received proposal from unknown node")]
285    UnknownNodeError,
286
287    #[error("Public inputs are invalid")]
288    InvalidPublicInputsError,
289
290    #[error("Signature could not be verified")]
291    InvalidSignature,
292
293    #[error("State transition failed")]
294    StateTransitionError,
295
296    #[error("No forks exist")]
297    ForksNotFound,
298
299    #[error("Check if proposal extends any existing fork chains failed")]
300    ExtendedChainIndexNotFound,
301
302    #[error("Proposal contains missmatched hashes")]
303    ProposalHashesMissmatchError,
304
305    #[error("Proposal contains missmatched headers")]
306    ProposalHeadersMissmatchError,
307
308    #[error("Unable to verify transfer transaction")]
309    TransferTxVerification,
310
311    #[error("Erroneous transactions detected")]
312    ErroneousTxsDetected,
313
314    #[error("Proposal task stopped")]
315    ProposalTaskStopped,
316
317    #[error("Proposal already exists")]
318    ProposalAlreadyExists,
319
320    #[error("Consensus task stopped")]
321    ConsensusTaskStopped,
322
323    #[error("Miner task stopped")]
324    MinerTaskStopped,
325
326    #[error("Garbage collection task stopped")]
327    GarbageCollectionTaskStopped,
328
329    #[error("Calculated total work is zero")]
330    PoWTotalWorkIsZero,
331
332    #[error("Erroneous cutoff calculation")]
333    PoWCuttofCalculationError,
334
335    #[error("Provided timestamp is invalid")]
336    PoWInvalidTimestamp,
337
338    #[error("Provided output hash is greater than current target")]
339    PoWInvalidOutHash,
340
341    #[error("Contracts states monotree root missing")]
342    ContractsStatesRootNotFoundError,
343
344    #[error("Contracts states monotree root missmatch: {0} - {1}")]
345    ContractsStatesRootError(String, String),
346
347    #[error("Hashing of Monero data failed: {0}")]
348    MoneroHashingError(String),
349
350    #[error("Cannot have zero merge-mining chains")]
351    MoneroNumberOfChainZero,
352
353    #[error("MergeMineError: {0}")]
354    MoneroMergeMineError(String),
355
356    #[cfg(feature = "randomx")]
357    #[error("RandomX Error: {0}")]
358    RandomXError(String),
359
360    // ===============
361    // Database errors
362    // ===============
363    #[error("Database error: {0}")]
364    DatabaseError(String),
365
366    #[cfg(feature = "sled-overlay")]
367    #[error(transparent)]
368    SledError(#[from] sled_overlay::sled::Error),
369
370    #[cfg(feature = "sled-overlay")]
371    #[error(transparent)]
372    SledTransactionError(#[from] sled_overlay::sled::transaction::TransactionError),
373
374    #[error("Transaction {0} not found in database")]
375    TransactionNotFound(String),
376
377    #[error("Transaction already seen")]
378    TransactionAlreadySeen,
379
380    #[error("Input vectors have different length")]
381    InvalidInputLengths,
382
383    #[error("Header {0} not found in database")]
384    HeaderNotFound(String),
385
386    #[error("Block {0} is invalid")]
387    BlockIsInvalid(String),
388
389    #[error("Block version {0} is invalid")]
390    BlockVersionIsInvalid(u8),
391
392    #[error("Block {0} already in database")]
393    BlockAlreadyExists(String),
394
395    #[error("Block {0} not found in database")]
396    BlockNotFound(String),
397
398    #[error("Block with height number {0} not found in database")]
399    BlockHeightNotFound(u32),
400
401    #[error("Block difficulty for height number {0} not found in database")]
402    BlockDifficultyNotFound(u32),
403
404    #[error("Block state inverse diff for height number {0} not found in database")]
405    BlockStateInverseDiffNotFound(u32),
406
407    #[error("Block {0} contains 0 transactions")]
408    BlockContainsNoTransactions(String),
409
410    #[error("Contract {0} not found in database")]
411    ContractNotFound(String),
412
413    #[error("Contract state tree not found")]
414    ContractStateNotFound,
415
416    #[error("Contract already initialized")]
417    ContractAlreadyInitialized,
418
419    #[error("zkas bincode not found in sled database")]
420    ZkasBincodeNotFound,
421
422    // ===================
423    // wasm runtime errors
424    // ===================
425    #[cfg(feature = "wasm-runtime")]
426    #[error("Wasmer compile error: {0}")]
427    WasmerCompileError(String),
428
429    #[cfg(feature = "wasm-runtime")]
430    #[error("Wasmer export error: {0}")]
431    WasmerExportError(String),
432
433    #[cfg(feature = "wasm-runtime")]
434    #[error("Wasmer runtime error: {0}")]
435    WasmerRuntimeError(String),
436
437    #[cfg(feature = "wasm-runtime")]
438    #[error("Wasmer instantiation error: {0}")]
439    WasmerInstantiationError(String),
440
441    #[cfg(feature = "wasm-runtime")]
442    #[error("wasm memory error")]
443    WasmerMemoryError(String),
444
445    #[cfg(feature = "wasm-runtime")]
446    #[error("wasm runtime out of memory")]
447    WasmerOomError(String),
448
449    #[cfg(feature = "darkfi-sdk")]
450    #[error("Contract execution failed: {0}")]
451    ContractError(darkfi_sdk::error::ContractError),
452
453    #[cfg(feature = "darkfi-sdk")]
454    #[error("Invalid DarkTree: {0}")]
455    DarkTreeError(darkfi_sdk::error::DarkTreeError),
456
457    #[cfg(feature = "blockchain")]
458    #[error("contract wasm bincode not found")]
459    WasmBincodeNotFound,
460
461    #[cfg(feature = "wasm-runtime")]
462    #[error("contract initialize error")]
463    ContractInitError(u64),
464
465    #[cfg(feature = "wasm-runtime")]
466    #[error("contract execution error")]
467    ContractExecError(u64),
468
469    #[cfg(feature = "wasm-runtime")]
470    #[error("wasm function ACL denied")]
471    WasmFunctionAclDenied,
472
473    // ====================
474    // Event Graph errors
475    // ====================
476    #[error("Event is not found in tree: {0}")]
477    EventNotFound(String),
478
479    #[error("Event is invalid")]
480    EventIsInvalid,
481
482    // ====================
483    // Miscellaneous errors
484    // ====================
485    #[error("IO error: {0}")]
486    Io(std::io::ErrorKind),
487
488    #[error("Infallible error: {0}")]
489    InfallibleError(String),
490
491    #[cfg(feature = "smol")]
492    #[error("async_channel sender error: {0}")]
493    AsyncChannelSendError(String),
494
495    #[cfg(feature = "smol")]
496    #[error("async_channel receiver error: {0}")]
497    AsyncChannelRecvError(String),
498
499    #[cfg(feature = "util")]
500    #[error("tracing-subscriber init failed: {0}")]
501    LogInitError(String),
502
503    #[error("ValueIsNotObject")]
504    ValueIsNotObject,
505
506    #[error("No config file detected")]
507    ConfigNotFound,
508
509    #[error("Invalid config file detected")]
510    ConfigInvalid,
511
512    #[error("Configuration error: {0}")]
513    ConfigError(String),
514
515    #[error("Failed decoding bincode: {0}")]
516    ZkasDecoderError(String),
517
518    #[cfg(feature = "util")]
519    #[error("System clock is not correct!")]
520    InvalidClock,
521
522    #[error("Unsupported OS")]
523    UnsupportedOS,
524
525    #[error("System clock went backwards")]
526    BackwardsTime(std::time::SystemTimeError),
527
528    #[error("Detached task stopped")]
529    DetachedTaskStopped,
530
531    #[error("Addition overflow")]
532    AdditionOverflow,
533
534    #[error("Subtraction underflow")]
535    SubtractionUnderflow,
536
537    // ==============================================
538    // Wrappers for other error types in this library
539    // ==============================================
540    #[error(transparent)]
541    ClientFailed(#[from] ClientFailed),
542
543    #[cfg(feature = "tx")]
544    #[error(transparent)]
545    TxVerifyFailed(#[from] TxVerifyFailed),
546
547    //=============
548    // clock
549    //=============
550    #[error("clock out of sync with peers: {0}")]
551    ClockOutOfSync(String),
552
553    // ================
554    // DHT/Geode errors
555    // ================
556    #[error("Geode needs garbage collection")]
557    GeodeNeedsGc,
558
559    #[error("Geode file not found")]
560    GeodeFileNotFound,
561
562    #[error("Geode chunk not found")]
563    GeodeChunkNotFound,
564
565    #[error("Geode file route not found")]
566    GeodeFileRouteNotFound,
567
568    #[error("Geode chunk route not found")]
569    GeodeChunkRouteNotFound,
570
571    // ==================
572    // Event Graph errors
573    // ==================
574    #[error("DAG sync failed")]
575    DagSyncFailed,
576
577    #[error("Malicious flood detected")]
578    MaliciousFlood,
579
580    // =========
581    // Catch-all
582    // =========
583    #[error("{0}")]
584    Custom(String),
585}
586
587#[cfg(feature = "tx")]
588impl Error {
589    /// Auxiliary function to retrieve the vector of erroneous
590    /// transactions from a TxVerifyFailed error.
591    /// In any other case, we return the error itself.
592    pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
593        if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
594            return Ok(erroneous_txs.clone())
595        };
596
597        Err(self.clone())
598    }
599}
600
601#[cfg(feature = "tx")]
602/// Transaction verification errors
603#[derive(Debug, Clone, thiserror::Error)]
604pub enum TxVerifyFailed {
605    #[error("Transaction {0} already exists")]
606    AlreadySeenTx(String),
607
608    #[error("Invalid transaction signature")]
609    InvalidSignature,
610
611    #[error("Missing signatures in transaction")]
612    MissingSignatures,
613
614    #[error("Missing contract calls in transaction")]
615    MissingCalls,
616
617    #[error("Invalid ZK proof in transaction")]
618    InvalidZkProof,
619
620    #[error("Missing Money::Fee call in transaction")]
621    MissingFee,
622
623    #[error("Invalid Money::Fee call in transaction")]
624    InvalidFee,
625
626    #[error("Insufficient fee paid")]
627    InsufficientFee,
628
629    #[error("Erroneous transactions found")]
630    ErroneousTxs(Vec<crate::tx::Transaction>),
631}
632
633/// Client module errors
634#[derive(Debug, Clone, thiserror::Error)]
635pub enum ClientFailed {
636    #[error("IO error: {0}")]
637    Io(std::io::ErrorKind),
638
639    #[error("Not enough value: {0}")]
640    NotEnoughValue(u64),
641
642    #[error("Invalid address: {0}")]
643    InvalidAddress(String),
644
645    #[error("Invalid amount: {0}")]
646    InvalidAmount(u64),
647
648    #[error("Invalid token ID: {0}")]
649    InvalidTokenId(String),
650
651    #[error("Internal error: {0}")]
652    InternalError(String),
653
654    #[error("Verify error: {0}")]
655    VerifyError(String),
656}
657
658#[cfg(feature = "rpc")]
659#[derive(Clone, Debug, thiserror::Error)]
660pub enum RpcError {
661    #[error("Connection closed: {0}")]
662    ConnectionClosed(String),
663
664    #[error("Invalid JSON: {0}")]
665    InvalidJson(String),
666
667    #[error("IO Error: {0}")]
668    IoError(std::io::ErrorKind),
669
670    #[error("Method not found: {0}")]
671    MethodNotFound(String),
672
673    #[error("Server-side Error: {0}")]
674    ServerError(#[from] std::sync::Arc<dyn std::error::Error + Send + Sync + 'static>),
675}
676
677#[cfg(feature = "rpc")]
678impl From<std::io::Error> for RpcError {
679    fn from(err: std::io::Error) -> Self {
680        Self::IoError(err.kind())
681    }
682}
683
684#[cfg(feature = "rpc")]
685impl From<RpcError> for Error {
686    fn from(err: RpcError) -> Self {
687        Self::RpcServerError(err)
688    }
689}
690
691impl From<Error> for ClientFailed {
692    fn from(err: Error) -> Self {
693        Self::InternalError(err.to_string())
694    }
695}
696
697impl From<std::io::Error> for ClientFailed {
698    fn from(err: std::io::Error) -> Self {
699        Self::Io(err.kind())
700    }
701}
702
703impl From<std::io::Error> for Error {
704    fn from(err: std::io::Error) -> Self {
705        Self::Io(err.kind())
706    }
707}
708
709impl From<std::time::SystemTimeError> for Error {
710    fn from(err: std::time::SystemTimeError) -> Self {
711        Self::BackwardsTime(err)
712    }
713}
714
715impl From<std::convert::Infallible> for Error {
716    fn from(err: std::convert::Infallible) -> Self {
717        Self::InfallibleError(err.to_string())
718    }
719}
720
721impl From<()> for Error {
722    fn from(_err: ()) -> Self {
723        Self::InfallibleError("Infallible".into())
724    }
725}
726
727#[cfg(feature = "net")]
728impl From<std::collections::TryReserveError> for Error {
729    fn from(err: std::collections::TryReserveError) -> Self {
730        Self::DecodePacket(err.to_string())
731    }
732}
733#[cfg(feature = "smol")]
734impl<T> From<smol::channel::SendError<T>> for Error {
735    fn from(err: smol::channel::SendError<T>) -> Self {
736        Self::AsyncChannelSendError(err.to_string())
737    }
738}
739
740#[cfg(feature = "smol")]
741impl From<smol::channel::RecvError> for Error {
742    fn from(err: smol::channel::RecvError) -> Self {
743        Self::AsyncChannelRecvError(err.to_string())
744    }
745}
746
747#[cfg(feature = "halo2_proofs")]
748impl From<halo2_proofs::plonk::Error> for Error {
749    fn from(err: halo2_proofs::plonk::Error) -> Self {
750        Self::PlonkError(err.to_string())
751    }
752}
753
754#[cfg(feature = "semver")]
755impl From<semver::Error> for Error {
756    fn from(err: semver::Error) -> Self {
757        Self::SemverError(err.to_string())
758    }
759}
760
761#[cfg(feature = "tinyjson")]
762impl From<tinyjson::JsonParseError> for Error {
763    fn from(err: tinyjson::JsonParseError) -> Self {
764        Self::JsonParseError(err.to_string())
765    }
766}
767
768#[cfg(feature = "tinyjson")]
769impl From<tinyjson::JsonGenerateError> for Error {
770    fn from(err: tinyjson::JsonGenerateError) -> Self {
771        Self::JsonGenerateError(err.to_string())
772    }
773}
774
775#[cfg(feature = "wasm-runtime")]
776impl From<wasmer::CompileError> for Error {
777    fn from(err: wasmer::CompileError) -> Self {
778        Self::WasmerCompileError(err.to_string())
779    }
780}
781
782#[cfg(feature = "wasm-runtime")]
783impl From<wasmer::ExportError> for Error {
784    fn from(err: wasmer::ExportError) -> Self {
785        Self::WasmerExportError(err.to_string())
786    }
787}
788
789#[cfg(feature = "wasm-runtime")]
790impl From<wasmer::RuntimeError> for Error {
791    fn from(err: wasmer::RuntimeError) -> Self {
792        Self::WasmerRuntimeError(err.to_string())
793    }
794}
795
796#[cfg(feature = "wasm-runtime")]
797impl From<wasmer::InstantiationError> for Error {
798    fn from(err: wasmer::InstantiationError) -> Self {
799        Self::WasmerInstantiationError(err.to_string())
800    }
801}
802
803#[cfg(feature = "wasm-runtime")]
804impl From<wasmer::MemoryAccessError> for Error {
805    fn from(err: wasmer::MemoryAccessError) -> Self {
806        Self::WasmerMemoryError(err.to_string())
807    }
808}
809
810#[cfg(feature = "wasm-runtime")]
811impl From<wasmer::MemoryError> for Error {
812    fn from(err: wasmer::MemoryError) -> Self {
813        Self::WasmerOomError(err.to_string())
814    }
815}
816
817#[cfg(feature = "darkfi-sdk")]
818impl From<darkfi_sdk::error::ContractError> for Error {
819    fn from(err: darkfi_sdk::error::ContractError) -> Self {
820        Self::ContractError(err)
821    }
822}
823
824#[cfg(feature = "darkfi-sdk")]
825impl From<darkfi_sdk::error::DarkTreeError> for Error {
826    fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
827        Self::DarkTreeError(err)
828    }
829}
830
831#[cfg(feature = "util")]
832impl From<tracing_subscriber::util::TryInitError> for Error {
833    fn from(err: tracing_subscriber::util::TryInitError) -> Self {
834        Self::LogInitError(err.to_string())
835    }
836}
837
838#[cfg(feature = "randomx")]
839impl From<randomx::RandomXError> for Error {
840    fn from(err: randomx::RandomXError) -> Self {
841        Self::RandomXError(err.to_string())
842    }
843}