elements_miniscript/descriptor/csfs_cov/
error.rs

1// Miniscript
2// Written in 2021 by
3//     Andrew Poelstra <apoelstra@wpsoftware.net>
4//     Sanket Kanjalkar <sanket1729@gmail.com>
5//
6// To the extent possible under law, the author(s) have dedicated all
7// copyright and related and neighboring rights to this software to
8// the public domain worldwide. This software is distributed without
9// any warranty.
10//
11// You should have received a copy of the CC0 Public Domain Dedication
12// along with this software.
13// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
14//
15//! Covenant Descriptor Errors
16
17use std::{error, fmt};
18
19use crate::Error;
20/// Covenant related Errors
21#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
22pub enum CovError {
23    /// Missing script code (segwit sighash)
24    MissingScriptCode,
25    /// Missing value (segwit sighash)
26    MissingValue,
27    /// Missing a sighash Item in satisfier,
28    MissingSighashItem(u8),
29    /// Missing Sighash Signature
30    /// This must be a secp signature serialized
31    /// in DER format *with* the sighash byte
32    MissingCovSignature,
33    /// Bad(Malformed) Covenant Descriptor
34    BadCovDescriptor,
35    /// Cannot lift a Covenant Descriptor
36    /// This is because the different components of the covenants
37    /// might interact across branches and thus is
38    /// not composable and could not be analyzed individually.
39    CovenantLift,
40    /// The Covenant Sighash type and the satisfier sighash
41    /// type must be the same
42    CovenantSighashTypeMismatch,
43}
44
45impl fmt::Display for CovError {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        match *self {
48            CovError::MissingScriptCode => write!(f, "Missing Script code"),
49            CovError::MissingValue => write!(f, "Missing value"),
50            CovError::BadCovDescriptor => write!(f, "Bad or Malformed covenant descriptor"),
51            CovError::CovenantLift => write!(f, "Cannot lift a covenant descriptor"),
52            CovError::MissingSighashItem(i) => {
53                write!(f, "Missing sighash item # : {} in satisfier", i)
54            }
55            CovError::MissingCovSignature => write!(f, "Missing signature over the covenant pk"),
56            CovError::CovenantSighashTypeMismatch => write!(
57                f,
58                "The sighash type provided in the witness must the same \
59                as the one used in signature"
60            ),
61        }
62    }
63}
64
65impl error::Error for CovError {}
66
67#[doc(hidden)]
68impl From<CovError> for Error {
69    fn from(e: CovError) -> Error {
70        Error::CovError(e)
71    }
72}