1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/* This file is part of DarkFi (https://dark.fi)
 *
 * Copyright (C) 2020-2024 Dyne.org foundation
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

// Hello developer. Please add your error to the according subsection
// that is commented, or make a new subsection. Keep it clean.

/// Main result type used throughout the codebase.
pub type Result<T> = std::result::Result<T, Error>;

/// Result type used in the Client module
pub type ClientResult<T> = std::result::Result<T, ClientFailed>;

/// General library errors used throughout the codebase.
#[derive(Debug, Clone, thiserror::Error)]
pub enum Error {
    // ==============
    // Parsing errors
    // ==============
    #[error("Parse failed: {0}")]
    ParseFailed(&'static str),

    #[error(transparent)]
    ParseIntError(#[from] std::num::ParseIntError),

    #[error(transparent)]
    ParseFloatError(#[from] std::num::ParseFloatError),

    #[cfg(feature = "url")]
    #[error(transparent)]
    UrlParseError(#[from] url::ParseError),

    #[error("URL parse error: {0}")]
    UrlParse(String),

    #[error(transparent)]
    AddrParseError(#[from] std::net::AddrParseError),

    #[error("Could not parse token parameter")]
    TokenParseError,

    #[error(transparent)]
    TryFromSliceError(#[from] std::array::TryFromSliceError),

    #[cfg(feature = "semver")]
    #[error("semver parse error: {0}")]
    SemverError(String),

    // ===============
    // Encoding errors
    // ===============
    #[error("decode failed: {0}")]
    DecodeError(&'static str),

    #[error("encode failed: {0}")]
    EncodeError(&'static str),

    #[error("VarInt was encoded in a non-minimal way")]
    NonMinimalVarInt,

    #[error(transparent)]
    Utf8Error(#[from] std::string::FromUtf8Error),

    #[error(transparent)]
    StrUtf8Error(#[from] std::str::Utf8Error),

    #[cfg(feature = "tinyjson")]
    #[error("JSON parse error: {0}")]
    JsonParseError(String),

    #[cfg(feature = "tinyjson")]
    #[error("JSON generate error: {0}")]
    JsonGenerateError(String),

    #[cfg(feature = "toml")]
    #[error(transparent)]
    TomlDeserializeError(#[from] toml::de::Error),

    #[cfg(feature = "bs58")]
    #[error(transparent)]
    Bs58DecodeError(#[from] bs58::decode::Error),

    #[error("Bad operation type byte")]
    BadOperationType,

    // ======================
    // Network-related errors
    // ======================
    #[error("Invalid Dialer scheme")]
    InvalidDialerScheme,

    #[error("Invalid Listener scheme")]
    InvalidListenerScheme,

    #[error("Unsupported network transport: {0}")]
    UnsupportedTransport(String),

    #[error("Unsupported network transport upgrade: {0}")]
    UnsupportedTransportUpgrade(String),

    #[error("Transport request exceeds number of accepted transports")]
    InvalidTransportRequest,

    #[error("Connection failed")]
    ConnectFailed,

    #[cfg(feature = "system")]
    #[error(transparent)]
    TimeoutError(#[from] crate::system::timeout::TimeoutError),

    #[error("Connection timed out")]
    ConnectTimeout,

    #[error("Channel stopped")]
    ChannelStopped,

    #[error("Channel timed out")]
    ChannelTimeout,

    #[error("Failed to reach any seeds")]
    SeedFailed,

    #[error("Network service stopped")]
    NetworkServiceStopped,

    #[error("Create listener bound to {0} failed")]
    BindFailed(String),

    #[error("Accept a new incoming connection from the listener {0} failed")]
    AcceptConnectionFailed(String),

    #[error("Accept a new tls connection from the listener {0} failed")]
    AcceptTlsConnectionFailed(String),

    #[error("Connector stopped")]
    ConnectorStopped,

    #[error("Network operation failed")]
    NetworkOperationFailed,

    #[error("Missing P2P message dispatcher")]
    MissingDispatcher,

    #[cfg(feature = "arti-client")]
    #[error(transparent)]
    ArtiError(#[from] arti_client::Error),

    #[error("Malformed packet")]
    MalformedPacket,

    #[error("Error decoding packet: {0}")]
    DecodePacket(String),

    #[error("Socks proxy error: {0}")]
    SocksError(String),

    #[error("No Socks5 URL found")]
    NoSocks5UrlFound,

    #[error("No URL found")]
    NoUrlFound,

    #[error("Tor error: {0}")]
    TorError(String),

    #[error("Node is not connected to other nodes.")]
    NetworkNotConnected,

    #[error("P2P network stopped")]
    P2PNetworkStopped,

    #[error("No such host color exists")]
    InvalidHostColor,

    #[error("No matching hostlist entry")]
    HostDoesNotExist,

    #[error("Invalid state transition: current_state={0}, end_state={1}")]
    HostStateBlocked(String, String),

    // =============
    // Crypto errors
    // =============
    #[cfg(feature = "halo2_proofs")]
    #[error("halo2 plonk error: {0}")]
    PlonkError(String),

    #[error("Wrong witness type at index: {0}")]
    WrongWitnessType(usize),

    #[error("Wrong witnesses count")]
    WrongWitnessesCount,

    #[error("Wrong public inputs count")]
    WrongPublicInputsCount,

    #[error("Unable to decrypt mint note: {0}")]
    NoteDecryptionFailed(String),

    #[error("No keypair file detected")]
    KeypairPathNotFound,

    #[error("Failed converting bytes to PublicKey")]
    PublicKeyFromBytes,

    #[error("Failed converting bytes to Coin")]
    CoinFromBytes,

    #[error("Failed converting bytes to SecretKey")]
    SecretKeyFromBytes,

    #[error("Failed converting b58 string to PublicKey")]
    PublicKeyFromStr,

    #[error("Failed converting bs58 string to SecretKey")]
    SecretKeyFromStr,

    #[error("Invalid DarkFi address")]
    InvalidAddress,

    #[error("unable to decrypt rcpt")]
    TxRcptDecryptionError,

    #[cfg(feature = "blake3")]
    #[error(transparent)]
    Blake3FromHexError(#[from] blake3::HexError),

    // =======================
    // Protocol-related errors
    // =======================
    #[error("Unsupported chain")]
    UnsupportedChain,

    #[error("JSON-RPC error: {0:?}")]
    JsonRpcError((i32, String)),

    #[cfg(feature = "rpc")]
    #[error(transparent)]
    RpcServerError(RpcError),

    #[cfg(feature = "rpc")]
    #[error("JSON-RPC connections exhausted")]
    RpcConnectionsExhausted,

    #[cfg(feature = "rpc")]
    #[error("JSON-RPC server stopped")]
    RpcServerStopped,

    #[cfg(feature = "rpc")]
    #[error("JSON-RPC client stopped")]
    RpcClientStopped,

    #[error("Unexpected JSON-RPC data received: {0}")]
    UnexpectedJsonRpc(String),

    #[error("Received proposal from unknown node")]
    UnknownNodeError,

    #[error("Public inputs are invalid")]
    InvalidPublicInputsError,

    #[error("Signature could not be verified")]
    InvalidSignature,

    #[error("State transition failed")]
    StateTransitionError,

    #[error("No forks exist")]
    ForksNotFound,

    #[error("Check if proposal extends any existing fork chains failed")]
    ExtendedChainIndexNotFound,

    #[error("Proposal contains missmatched hashes")]
    ProposalHashesMissmatchError,

    #[error("Proposal contains missmatched headers")]
    ProposalHeadersMissmatchError,

    #[error("Unable to verify transfer transaction")]
    TransferTxVerification,

    #[error("Erroneous transactions detected")]
    ErroneousTxsDetected,

    #[error("Proposal task stopped")]
    ProposalTaskStopped,

    #[error("Proposal already exists")]
    ProposalAlreadyExists,

    #[error("Consensus task stopped")]
    ConsensusTaskStopped,

    #[error("Miner task stopped")]
    MinerTaskStopped,

    #[error("Garbage collection task stopped")]
    GarbageCollectionTaskStopped,

    #[error("Calculated total work is zero")]
    PoWTotalWorkIsZero,

    #[error("Erroneous cutoff calculation")]
    PoWCuttofCalculationError,

    #[error("Provided timestamp is invalid")]
    PoWInvalidTimestamp,

    #[error("Provided output hash is greater than current target")]
    PoWInvalidOutHash,

    // ===============
    // Database errors
    // ===============
    #[cfg(feature = "rusqlite")]
    #[error("rusqlite error: {0}")]
    RusqliteError(String),

    #[cfg(feature = "sled")]
    #[error(transparent)]
    SledError(#[from] sled::Error),

    #[cfg(feature = "sled")]
    #[error(transparent)]
    SledTransactionError(#[from] sled::transaction::TransactionError),

    #[error("Transaction {0} not found in database")]
    TransactionNotFound(String),

    #[error("Transaction already seen")]
    TransactionAlreadySeen,

    #[error("Input vectors have different length")]
    InvalidInputLengths,

    #[error("Header {0} not found in database")]
    HeaderNotFound(String),

    #[error("Block {0} is invalid")]
    BlockIsInvalid(String),

    #[error("Block version {0} is invalid")]
    BlockVersionIsInvalid(u8),

    #[error("Block {0} already in database")]
    BlockAlreadyExists(String),

    #[error("Block {0} not found in database")]
    BlockNotFound(String),

    #[error("Block with height number {0} not found in database")]
    BlockHeightNotFound(u32),

    #[error("Block difficulty for height number {0} not found in database")]
    BlockDifficultyNotFound(u32),

    #[error("Block {0} contains 0 transactions")]
    BlockContainsNoTransactions(String),

    #[error("Contract {0} not found in database")]
    ContractNotFound(String),

    #[error("Contract state tree not found")]
    ContractStateNotFound,

    #[error("Contract already initialized")]
    ContractAlreadyInitialized,

    #[error("zkas bincode not found in sled database")]
    ZkasBincodeNotFound,

    // ===================
    // wasm runtime errors
    // ===================
    #[cfg(feature = "wasm-runtime")]
    #[error("Wasmer compile error: {0}")]
    WasmerCompileError(String),

    #[cfg(feature = "wasm-runtime")]
    #[error("Wasmer export error: {0}")]
    WasmerExportError(String),

    #[cfg(feature = "wasm-runtime")]
    #[error("Wasmer runtime error: {0}")]
    WasmerRuntimeError(String),

    #[cfg(feature = "wasm-runtime")]
    #[error("Wasmer instantiation error: {0}")]
    WasmerInstantiationError(String),

    #[cfg(feature = "wasm-runtime")]
    #[error("wasm memory error")]
    WasmerMemoryError(String),

    #[cfg(feature = "wasm-runtime")]
    #[error("wasm runtime out of memory")]
    WasmerOomError(String),

    #[cfg(feature = "darkfi-sdk")]
    #[error("Contract execution failed: {0}")]
    ContractError(darkfi_sdk::error::ContractError),

    #[cfg(feature = "darkfi-sdk")]
    #[error("Invalid DarkTree: {0}")]
    DarkTreeError(darkfi_sdk::error::DarkTreeError),

    #[cfg(feature = "blockchain")]
    #[error("contract wasm bincode not found")]
    WasmBincodeNotFound,

    #[cfg(feature = "wasm-runtime")]
    #[error("contract initialize error")]
    ContractInitError(u64),

    #[cfg(feature = "wasm-runtime")]
    #[error("contract execution error")]
    ContractExecError(u64),

    #[cfg(feature = "wasm-runtime")]
    #[error("wasm function ACL denied")]
    WasmFunctionAclDenied,

    // ====================
    // Event Graph errors
    // ====================
    #[error("Event is not found in tree: {0}")]
    EventNotFound(String),

    #[error("Event is invalid")]
    EventIsInvalid,

    // ====================
    // Miscellaneous errors
    // ====================
    #[error("IO error: {0}")]
    Io(std::io::ErrorKind),

    #[error("Infallible error: {0}")]
    InfallibleError(String),

    #[cfg(feature = "smol")]
    #[error("async_channel sender error: {0}")]
    AsyncChannelSendError(String),

    #[cfg(feature = "smol")]
    #[error("async_channel receiver error: {0}")]
    AsyncChannelRecvError(String),

    #[error("SetLogger (log crate) failed: {0}")]
    SetLoggerError(String),

    #[error("ValueIsNotObject")]
    ValueIsNotObject,

    #[error("No config file detected")]
    ConfigNotFound,

    #[error("Invalid config file detected")]
    ConfigInvalid,

    #[error("Failed decoding bincode: {0}")]
    ZkasDecoderError(String),

    #[cfg(feature = "util")]
    #[error("System clock is not correct!")]
    InvalidClock,

    #[error("Unsupported OS")]
    UnsupportedOS,

    #[error("System clock went backwards")]
    BackwardsTime(std::time::SystemTimeError),

    #[error("Detached task stopped")]
    DetachedTaskStopped,

    #[error("Addition overflow")]
    AdditionOverflow,

    #[error("Subtraction underflow")]
    SubtractionUnderflow,

    // ==============================================
    // Wrappers for other error types in this library
    // ==============================================
    #[error(transparent)]
    ClientFailed(#[from] ClientFailed),

    #[cfg(feature = "tx")]
    #[error(transparent)]
    TxVerifyFailed(#[from] TxVerifyFailed),

    //=============
    // clock
    //=============
    #[error("clock out of sync with peers: {0}")]
    ClockOutOfSync(String),

    // ================
    // DHT/Geode errors
    // ================
    #[error("Geode needs garbage collection")]
    GeodeNeedsGc,

    #[error("Geode file not found")]
    GeodeFileNotFound,

    #[error("Geode chunk not found")]
    GeodeChunkNotFound,

    #[error("Geode file route not found")]
    GeodeFileRouteNotFound,

    #[error("Geode chunk route not found")]
    GeodeChunkRouteNotFound,

    // ==================
    // Event Graph errors
    // ==================
    #[error("DAG sync failed")]
    DagSyncFailed,

    // =========
    // Catch-all
    // =========
    #[error("{0}")]
    Custom(String),
}

#[cfg(feature = "tx")]
impl Error {
    /// Auxiliary function to retrieve the vector of erroneous
    /// transactions from a TxVerifyFailed error.
    /// In any other case, we return the error itself.
    pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
        if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
            return Ok(erroneous_txs.clone())
        };

        Err(self.clone())
    }
}

#[cfg(feature = "tx")]
/// Transaction verification errors
#[derive(Debug, Clone, thiserror::Error)]
pub enum TxVerifyFailed {
    #[error("Transaction {0} already exists")]
    AlreadySeenTx(String),

    #[error("Invalid transaction signature")]
    InvalidSignature,

    #[error("Missing signatures in transaction")]
    MissingSignatures,

    #[error("Missing contract calls in transaction")]
    MissingCalls,

    #[error("Invalid ZK proof in transaction")]
    InvalidZkProof,

    #[error("Missing Money::Fee call in transaction")]
    MissingFee,

    #[error("Invalid Money::Fee call in transaction")]
    InvalidFee,

    #[error("Insufficient fee paid")]
    InsufficientFee,

    #[error("Erroneous transactions found")]
    ErroneousTxs(Vec<crate::tx::Transaction>),
}

/// Client module errors
#[derive(Debug, Clone, thiserror::Error)]
pub enum ClientFailed {
    #[error("IO error: {0}")]
    Io(std::io::ErrorKind),

    #[error("Not enough value: {0}")]
    NotEnoughValue(u64),

    #[error("Invalid address: {0}")]
    InvalidAddress(String),

    #[error("Invalid amount: {0}")]
    InvalidAmount(u64),

    #[error("Invalid token ID: {0}")]
    InvalidTokenId(String),

    #[error("Internal error: {0}")]
    InternalError(String),

    #[error("Verify error: {0}")]
    VerifyError(String),
}

#[cfg(feature = "rpc")]
#[derive(Clone, Debug, thiserror::Error)]
pub enum RpcError {
    #[error("Connection closed: {0}")]
    ConnectionClosed(String),

    #[error("Invalid JSON: {0}")]
    InvalidJson(String),

    #[error("IO Error: {0}")]
    IoError(std::io::ErrorKind),
}

#[cfg(feature = "rpc")]
impl From<std::io::Error> for RpcError {
    fn from(err: std::io::Error) -> Self {
        Self::IoError(err.kind())
    }
}

#[cfg(feature = "rpc")]
impl From<RpcError> for Error {
    fn from(err: RpcError) -> Self {
        Self::RpcServerError(err)
    }
}

impl From<Error> for ClientFailed {
    fn from(err: Error) -> Self {
        Self::InternalError(err.to_string())
    }
}

impl From<std::io::Error> for ClientFailed {
    fn from(err: std::io::Error) -> Self {
        Self::Io(err.kind())
    }
}

impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Self {
        Self::Io(err.kind())
    }
}

impl From<std::time::SystemTimeError> for Error {
    fn from(err: std::time::SystemTimeError) -> Self {
        Self::BackwardsTime(err)
    }
}

impl From<std::convert::Infallible> for Error {
    fn from(err: std::convert::Infallible) -> Self {
        Self::InfallibleError(err.to_string())
    }
}

impl From<()> for Error {
    fn from(_err: ()) -> Self {
        Self::InfallibleError("Infallible".into())
    }
}

#[cfg(feature = "net")]
impl From<std::collections::TryReserveError> for Error {
    fn from(err: std::collections::TryReserveError) -> Self {
        Self::DecodePacket(err.to_string())
    }
}
#[cfg(feature = "smol")]
impl<T> From<smol::channel::SendError<T>> for Error {
    fn from(err: smol::channel::SendError<T>) -> Self {
        Self::AsyncChannelSendError(err.to_string())
    }
}

#[cfg(feature = "smol")]
impl From<smol::channel::RecvError> for Error {
    fn from(err: smol::channel::RecvError) -> Self {
        Self::AsyncChannelRecvError(err.to_string())
    }
}

impl From<log::SetLoggerError> for Error {
    fn from(err: log::SetLoggerError) -> Self {
        Self::SetLoggerError(err.to_string())
    }
}

#[cfg(feature = "rusqlite")]
impl From<rusqlite::Error> for Error {
    fn from(err: rusqlite::Error) -> Self {
        Self::RusqliteError(err.to_string())
    }
}

#[cfg(feature = "halo2_proofs")]
impl From<halo2_proofs::plonk::Error> for Error {
    fn from(err: halo2_proofs::plonk::Error) -> Self {
        Self::PlonkError(err.to_string())
    }
}

#[cfg(feature = "semver")]
impl From<semver::Error> for Error {
    fn from(err: semver::Error) -> Self {
        Self::SemverError(err.to_string())
    }
}

#[cfg(feature = "tinyjson")]
impl From<tinyjson::JsonParseError> for Error {
    fn from(err: tinyjson::JsonParseError) -> Self {
        Self::JsonParseError(err.to_string())
    }
}

#[cfg(feature = "tinyjson")]
impl From<tinyjson::JsonGenerateError> for Error {
    fn from(err: tinyjson::JsonGenerateError) -> Self {
        Self::JsonGenerateError(err.to_string())
    }
}

#[cfg(feature = "wasm-runtime")]
impl From<wasmer::CompileError> for Error {
    fn from(err: wasmer::CompileError) -> Self {
        Self::WasmerCompileError(err.to_string())
    }
}

#[cfg(feature = "wasm-runtime")]
impl From<wasmer::ExportError> for Error {
    fn from(err: wasmer::ExportError) -> Self {
        Self::WasmerExportError(err.to_string())
    }
}

#[cfg(feature = "wasm-runtime")]
impl From<wasmer::RuntimeError> for Error {
    fn from(err: wasmer::RuntimeError) -> Self {
        Self::WasmerRuntimeError(err.to_string())
    }
}

#[cfg(feature = "wasm-runtime")]
impl From<wasmer::InstantiationError> for Error {
    fn from(err: wasmer::InstantiationError) -> Self {
        Self::WasmerInstantiationError(err.to_string())
    }
}

#[cfg(feature = "wasm-runtime")]
impl From<wasmer::MemoryAccessError> for Error {
    fn from(err: wasmer::MemoryAccessError) -> Self {
        Self::WasmerMemoryError(err.to_string())
    }
}

#[cfg(feature = "wasm-runtime")]
impl From<wasmer::MemoryError> for Error {
    fn from(err: wasmer::MemoryError) -> Self {
        Self::WasmerOomError(err.to_string())
    }
}

#[cfg(feature = "darkfi-sdk")]
impl From<darkfi_sdk::error::ContractError> for Error {
    fn from(err: darkfi_sdk::error::ContractError) -> Self {
        Self::ContractError(err)
    }
}

#[cfg(feature = "darkfi-sdk")]
impl From<darkfi_sdk::error::DarkTreeError> for Error {
    fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
        Self::DarkTreeError(err)
    }
}