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
use cardano_serialization_lib as csl;
use plutus_ledger_api::v2::{datum::DatumHash, script::ScriptHash, transaction::TransactionInput};
use thiserror::Error;

use crate::{
    chain_query::ChainQueryError,
    submitter::SubmitterError,
    utils::{csl_to_pla::TryFromCSLError, pla_to_csl::TryFromPLAError},
    wallet::WalletError,
};

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Error, Debug)]
pub enum Error {
    #[error("Unable to find redeemer for minting policy (hash: {0:?})")]
    MissingMintRedeemer(ScriptHash),

    #[error("Unable to find redeemer for datum (hash: {0:?})")]
    MissingDatum(DatumHash),

    #[error("Unable to find Plutus script in TxWithCtx (hash: {0:?})")]
    MissingScript(ScriptHash),

    #[error("Reference input containing script {0:?} is missing from the TransactionInfo reference input list.")]
    MissingReferenceScript(TransactionInput, ScriptHash),

    #[error("Couldn't find suitable collateral.")]
    MissingCollateral,

    #[error("Change strategy is set to LastOutput, but it is missing from the TransactionInfo.")]
    MissingChangeOutput,

    #[error("Execution units was not calculated for {0:?}.")]
    MissingExUnits((csl::RedeemerTag, csl::BigNum)),

    #[error("Protocol parameter {0} is missing")]
    MissingProtocolParameter(String),

    #[error(transparent)]
    TryFromPLAError(#[from] TryFromPLAError),

    #[error(transparent)]
    TryFromCSLError(#[from] TryFromCSLError),

    #[error(transparent)]
    ConversionError(anyhow::Error),

    #[error("Unsupported {0}.")]
    Unsupported(String),

    #[error("Internal error: {0}")]
    Internal(anyhow::Error),

    #[error("Transaction building failed: {0}")]
    TransactionBuildError(anyhow::Error),

    #[error("Chain query failed: {0}")]
    ChainQueryError(#[from] ChainQueryError),

    #[error("Chain query failed: {0}")]
    WalletError(#[from] WalletError),

    #[error("Chain query failed: {0}")]
    SubmitterError(#[from] SubmitterError),

    #[error("Error occurred due to a configuration for {0}")]
    InvalidConfiguration(String),

    #[error("A POSIX time value is invalid: {0}")]
    InvalidPOSIXTime(String),
}