radix_transactions/
errors.rs

1use crate::internal_prelude::*;
2use sbor::*;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum HeaderValidationError {
6    InvalidEpochRange,
7    InvalidTimestampRange,
8    InvalidNetwork,
9    InvalidTip,
10    NoValidEpochRangeAcrossAllIntents,
11    NoValidTimestampRangeAcrossAllIntents,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub enum SignatureValidationError {
16    TooManySignatures { total: usize, limit: usize },
17    InvalidIntentSignature,
18    InvalidNotarySignature,
19    DuplicateSigner,
20    NotaryIsSignatorySoShouldNotAlsoBeASigner,
21    SerializationError(EncodeError),
22    IncorrectNumberOfSubintentSignatureBatches,
23}
24
25impl SignatureValidationError {
26    pub fn located(
27        self,
28        location: TransactionValidationErrorLocation,
29    ) -> TransactionValidationError {
30        TransactionValidationError::SignatureValidationError(location, self)
31    }
32}
33
34impl From<EncodeError> for SignatureValidationError {
35    fn from(err: EncodeError) -> Self {
36        Self::SerializationError(err)
37    }
38}
39
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub enum ManifestIdValidationError {
42    BucketNotFound(ManifestBucket),
43    ProofNotFound(ManifestProof),
44    BucketLocked(ManifestBucket),
45    AddressReservationNotFound(ManifestAddressReservation),
46    AddressNotFound(ManifestNamedAddress),
47    IntentNotFound(ManifestNamedIntent),
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub enum ManifestBasicValidatorError {
52    ManifestIdValidationError(ManifestIdValidationError),
53}
54
55impl From<ManifestIdValidationError> for ManifestBasicValidatorError {
56    fn from(value: ManifestIdValidationError) -> Self {
57        Self::ManifestIdValidationError(value)
58    }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub enum TransactionValidationError {
63    TransactionVersionNotPermitted(usize),
64    TransactionTooLarge,
65    EncodeError(EncodeError),
66    PrepareError(PrepareError),
67    SubintentStructureError(TransactionValidationErrorLocation, SubintentStructureError),
68    IntentValidationError(TransactionValidationErrorLocation, IntentValidationError),
69    SignatureValidationError(TransactionValidationErrorLocation, SignatureValidationError),
70}
71
72pub enum IntentSpecifier {
73    RootTransactionIntent(TransactionIntentHash),
74    RootSubintent(SubintentHash),
75    NonRootSubintent(SubintentIndex, SubintentHash),
76}
77
78#[derive(Debug, Clone, PartialEq, Eq)]
79pub enum TransactionValidationErrorLocation {
80    RootTransactionIntent(TransactionIntentHash),
81    RootSubintent(SubintentHash),
82    NonRootSubintent(SubintentIndex, SubintentHash),
83    AcrossTransaction,
84    Unlocatable,
85}
86
87impl TransactionValidationErrorLocation {
88    pub fn for_root(intent_hash: IntentHash) -> Self {
89        match intent_hash {
90            IntentHash::Transaction(hash) => Self::RootTransactionIntent(hash),
91            IntentHash::Subintent(hash) => Self::RootSubintent(hash),
92        }
93    }
94}
95
96impl From<PrepareError> for TransactionValidationError {
97    fn from(value: PrepareError) -> Self {
98        Self::PrepareError(value)
99    }
100}
101
102impl From<EncodeError> for TransactionValidationError {
103    fn from(value: EncodeError) -> Self {
104        Self::EncodeError(value)
105    }
106}
107
108#[derive(Debug, Clone, PartialEq, Eq)]
109pub enum IntentValidationError {
110    ManifestBasicValidatorError(ManifestBasicValidatorError),
111    ManifestValidationError(ManifestValidationError),
112    InvalidMessage(InvalidMessageError),
113    HeaderValidationError(HeaderValidationError),
114    TooManyReferences { total: usize, limit: usize },
115}
116
117impl From<HeaderValidationError> for IntentValidationError {
118    fn from(value: HeaderValidationError) -> Self {
119        Self::HeaderValidationError(value)
120    }
121}
122
123impl From<InvalidMessageError> for IntentValidationError {
124    fn from(value: InvalidMessageError) -> Self {
125        Self::InvalidMessage(value)
126    }
127}
128
129impl From<ManifestBasicValidatorError> for IntentValidationError {
130    fn from(value: ManifestBasicValidatorError) -> Self {
131        Self::ManifestBasicValidatorError(value)
132    }
133}
134
135impl From<ManifestValidationError> for IntentValidationError {
136    fn from(value: ManifestValidationError) -> Self {
137        Self::ManifestValidationError(value)
138    }
139}
140
141#[derive(Debug, Clone, PartialEq, Eq)]
142pub enum InvalidMessageError {
143    PlaintextMessageTooLong {
144        actual: usize,
145        permitted: usize,
146    },
147    MimeTypeTooLong {
148        actual: usize,
149        permitted: usize,
150    },
151    EncryptedMessageTooLong {
152        actual: usize,
153        permitted: usize,
154    },
155    NoDecryptors,
156    MismatchingDecryptorCurves {
157        actual: CurveType,
158        expected: CurveType,
159    },
160    TooManyDecryptors {
161        actual: usize,
162        permitted: usize,
163    },
164    NoDecryptorsForCurveType {
165        curve_type: CurveType,
166    },
167}
168
169#[derive(Debug, Clone, PartialEq, Eq)]
170pub enum SubintentStructureError {
171    DuplicateSubintent,
172    SubintentHasMultipleParents,
173    ChildSubintentNotIncludedInTransaction(SubintentHash),
174    SubintentExceedsMaxDepth,
175    SubintentIsNotReachableFromTheTransactionIntent,
176    MismatchingYieldChildAndYieldParentCountsForSubintent,
177}
178
179impl SubintentStructureError {
180    pub fn for_unindexed(self) -> TransactionValidationError {
181        TransactionValidationError::SubintentStructureError(
182            TransactionValidationErrorLocation::Unlocatable,
183            self,
184        )
185    }
186
187    pub fn for_subintent(
188        self,
189        index: SubintentIndex,
190        hash: SubintentHash,
191    ) -> TransactionValidationError {
192        TransactionValidationError::SubintentStructureError(
193            TransactionValidationErrorLocation::NonRootSubintent(index, hash),
194            self,
195        )
196    }
197}