tx_bakery/
error.rs

1use num_bigint::BigInt;
2use plutus_ledger_api::{
3    csl::{csl_to_pla::TryFromCSLError, lib as csl, pla_to_csl::TryFromPLAError},
4    v3::{
5        datum::DatumHash,
6        script::ScriptHash,
7        transaction::{TransactionInput, TxInInfo},
8    },
9};
10use thiserror::Error;
11
12use crate::{chain_query::ChainQueryError, submitter::SubmitterError, wallet::WalletError};
13
14pub type Result<T> = std::result::Result<T, Error>;
15
16#[derive(Error, Debug)]
17pub enum Error {
18    #[error("Unable to find redeemer for minting policy (hash: {0:?})")]
19    MissingMintRedeemer(ScriptHash),
20
21    #[error("Unable to find redeemer for datum (hash: {0:?})")]
22    MissingDatum(DatumHash),
23
24    #[error("Unable to find Plutus script in TxWithCtx (hash: {0:?})")]
25    MissingScript(ScriptHash),
26
27    #[error("Reference input containing script {0:?} is missing from the TransactionInfo reference input list.")]
28    MissingReferenceScript(TransactionInput, ScriptHash),
29
30    #[error(
31        "Couldn't find enough collaterals.
32         The total amount is {amount} while {required} was expected. Utxos: {utxos:?}"
33    )]
34    NotEnoughCollaterals {
35        amount: BigInt,
36        required: BigInt,
37        utxos: Vec<TxInInfo>,
38    },
39
40    #[error("Change strategy is set to LastOutput, but it is missing from the TransactionInfo.")]
41    MissingChangeOutput,
42
43    #[error("Execution units was not calculated for {0:?}.")]
44    MissingExUnits((csl::RedeemerTag, csl::BigNum)),
45
46    #[error("Protocol parameter {0} is missing")]
47    MissingProtocolParameter(String),
48
49    #[error(transparent)]
50    TryFromPLAError(#[from] TryFromPLAError),
51
52    #[error(transparent)]
53    TryFromCSLError(#[from] TryFromCSLError),
54
55    #[error(transparent)]
56    ConversionError(anyhow::Error),
57
58    #[error("Unsupported {0}.")]
59    Unsupported(String),
60
61    #[error("Internal error: {0}")]
62    Internal(anyhow::Error),
63
64    #[error("Transaction building failed: {0}")]
65    TransactionBuildError(anyhow::Error),
66
67    #[error("Chain query failed: {0}")]
68    ChainQueryError(#[from] ChainQueryError),
69
70    #[error("Chain query failed: {0}")]
71    WalletError(#[from] WalletError),
72
73    #[error("Chain query failed: {0}")]
74    SubmitterError(#[from] SubmitterError),
75
76    #[error("Error occurred due to a configuration for {0}")]
77    InvalidConfiguration(String),
78
79    #[error("A POSIX time value is invalid: {0}")]
80    InvalidPOSIXTime(String),
81}