1use thiserror::Error;
7
8#[derive(Error, Debug, Clone, PartialEq, Eq)]
10pub enum TenzroError {
11 #[error("Invalid hash: {0}")]
13 InvalidHash(String),
14
15 #[error("Invalid address: {0}")]
16 InvalidAddress(String),
17
18 #[error("Invalid signature: {0}")]
19 InvalidSignature(String),
20
21 #[error("Invalid transaction: {0}")]
23 InvalidTransaction(String),
24
25 #[error("Transaction verification failed: {0}")]
26 TransactionVerificationFailed(String),
27
28 #[error("Insufficient balance: required {required}, available {available}")]
29 InsufficientBalance { required: u64, available: u64 },
30
31 #[error("Invalid nonce: expected {expected}, got {actual}")]
32 InvalidNonce { expected: u64, actual: u64 },
33
34 #[error("Gas limit exceeded: limit {limit}, used {used}")]
35 GasLimitExceeded { limit: u64, used: u64 },
36
37 #[error("Invalid block: {0}")]
39 InvalidBlock(String),
40
41 #[error("Block verification failed: {0}")]
42 BlockVerificationFailed(String),
43
44 #[error("Invalid block height: expected {expected}, got {actual}")]
45 InvalidBlockHeight { expected: u64, actual: u64 },
46
47 #[error("Account not found: {0}")]
49 AccountNotFound(String),
50
51 #[error("Account already exists: {0}")]
52 AccountAlreadyExists(String),
53
54 #[error("Insufficient stake: required {required}, staked {staked}")]
55 InsufficientStake { required: u128, staked: u128 },
56
57 #[error("Asset not found: {0}")]
59 AssetNotFound(String),
60
61 #[error("Invalid asset: {0}")]
62 InvalidAsset(String),
63
64 #[error("Unsupported stablecoin: {0}")]
65 UnsupportedStablecoin(String),
66
67 #[error("Network error: {0}")]
69 NetworkError(String),
70
71 #[error("Peer not found: {0}")]
72 PeerNotFound(String),
73
74 #[error("Connection failed: {0}")]
75 ConnectionFailed(String),
76
77 #[error("Protocol version mismatch: local {local}, remote {remote}")]
78 ProtocolVersionMismatch { local: u32, remote: u32 },
79
80 #[error("TEE attestation failed: {0}")]
82 TeeAttestationFailed(String),
83
84 #[error("Invalid attestation report: {0}")]
85 InvalidAttestationReport(String),
86
87 #[error("TEE provider not found: {0}")]
88 TeeProviderNotFound(String),
89
90 #[error("TEE capacity exceeded")]
91 TeeCapacityExceeded,
92
93 #[error("Unsupported TEE vendor: {0}")]
94 UnsupportedTeeVendor(String),
95
96 #[error("Agent not found: {0}")]
98 AgentNotFound(String),
99
100 #[error("Invalid agent configuration: {0}")]
101 InvalidAgentConfig(String),
102
103 #[error("Agent execution failed: {0}")]
104 AgentExecutionFailed(String),
105
106 #[error("Capability not supported: {0}")]
107 CapabilityNotSupported(String),
108
109 #[error("Agent resource limit exceeded: {0}")]
110 AgentResourceLimitExceeded(String),
111
112 #[error("Model not found: {0}")]
114 ModelNotFound(String),
115
116 #[error("Invalid model: {0}")]
117 InvalidModel(String),
118
119 #[error("Model inference failed: {0}")]
120 ModelInferenceFailed(String),
121
122 #[error("Provider not found: {0}")]
123 ProviderNotFound(String),
124
125 #[error("Provider capacity exceeded")]
126 ProviderCapacityExceeded,
127
128 #[error("Invalid inference parameters: {0}")]
129 InvalidInferenceParameters(String),
130
131 #[error("Settlement request not found: {0}")]
133 SettlementRequestNotFound(String),
134
135 #[error("Settlement failed: {0}")]
136 SettlementFailed(String),
137
138 #[error("Invalid service proof: {0}")]
139 InvalidServiceProof(String),
140
141 #[error("Settlement expired")]
142 SettlementExpired,
143
144 #[error("Payment failed: {0}")]
145 PaymentFailed(String),
146
147 #[error("Invalid token configuration: {0}")]
149 InvalidTokenConfig(String),
150
151 #[error("Staking failed: {0}")]
152 StakingFailed(String),
153
154 #[error("Unstaking failed: {0}")]
155 UnstakingFailed(String),
156
157 #[error("Stake is locked until {0}")]
158 StakeLocked(i64),
159
160 #[error("Treasury operation failed: {0}")]
161 TreasuryOperationFailed(String),
162
163 #[error("Proposal not found: {0}")]
165 ProposalNotFound(String),
166
167 #[error("Invalid proposal: {0}")]
168 InvalidProposal(String),
169
170 #[error("Voting failed: {0}")]
171 VotingFailed(String),
172
173 #[error("Voting period ended")]
174 VotingPeriodEnded,
175
176 #[error("Voting period not started")]
177 VotingPeriodNotStarted,
178
179 #[error("Insufficient voting power: required {required}, available {available}")]
180 InsufficientVotingPower { required: u64, available: u64 },
181
182 #[error("Quorum not met")]
183 QuorumNotMet,
184
185 #[error("Bridge message not found: {0}")]
187 BridgeMessageNotFound(String),
188
189 #[error("Bridge transfer failed: {0}")]
190 BridgeTransferFailed(String),
191
192 #[error("Invalid bridge proof: {0}")]
193 InvalidBridgeProof(String),
194
195 #[error("Unsupported chain: {0}")]
196 UnsupportedChain(String),
197
198 #[error("Bridge relayer not found: {0}")]
199 BridgeRelayerNotFound(String),
200
201 #[error("Route not supported: {source_chain} -> {destination}")]
202 RouteNotSupported {
203 source_chain: String,
204 destination: String,
205 },
206
207 #[error("Wallet not found: {0}")]
209 WalletNotFound(String),
210
211 #[error("Invalid wallet configuration: {0}")]
212 InvalidWalletConfig(String),
213
214 #[error("Multi-sig threshold not met: required {required}, got {actual}")]
215 MultiSigThresholdNotMet { required: u32, actual: u32 },
216
217 #[error("Storage error: {0}")]
219 StorageError(String),
220
221 #[error("Item not found in storage: {0}")]
222 StorageItemNotFound(String),
223
224 #[error("Serialization error: {0}")]
225 SerializationError(String),
226
227 #[error("Deserialization error: {0}")]
228 DeserializationError(String),
229
230 #[error("Consensus error: {0}")]
232 ConsensusError(String),
233
234 #[error("Invalid consensus proof: {0}")]
235 InvalidConsensusProof(String),
236
237 #[error("Validator not found: {0}")]
238 ValidatorNotFound(String),
239
240 #[error("VM execution failed: {0}")]
242 VmExecutionFailed(String),
243
244 #[error("Contract deployment failed: {0}")]
245 ContractDeploymentFailed(String),
246
247 #[error("Contract call failed: {0}")]
248 ContractCallFailed(String),
249
250 #[error("Cryptographic operation failed: {0}")]
252 CryptoError(String),
253
254 #[error("Key derivation failed: {0}")]
255 KeyDerivationFailed(String),
256
257 #[error("Invalid configuration: {0}")]
259 InvalidConfig(String),
260
261 #[error("Configuration not found: {0}")]
262 ConfigNotFound(String),
263
264 #[error("Internal error: {0}")]
266 InternalError(String),
267
268 #[error("Not implemented: {0}")]
269 NotImplemented(String),
270
271 #[error("Operation not permitted: {0}")]
272 OperationNotPermitted(String),
273
274 #[error("Timeout: {0}")]
275 Timeout(String),
276}
277
278impl TenzroError {
279 pub fn internal(msg: impl Into<String>) -> Self {
281 Self::InternalError(msg.into())
282 }
283
284 pub fn not_implemented(msg: impl Into<String>) -> Self {
286 Self::NotImplemented(msg.into())
287 }
288
289 pub fn not_permitted(msg: impl Into<String>) -> Self {
291 Self::OperationNotPermitted(msg.into())
292 }
293}
294
295impl From<serde_json::Error> for TenzroError {
297 fn from(err: serde_json::Error) -> Self {
298 Self::SerializationError(err.to_string())
299 }
300}
301
302impl From<std::io::Error> for TenzroError {
303 fn from(err: std::io::Error) -> Self {
304 Self::InternalError(err.to_string())
305 }
306}
307
308impl From<hex::FromHexError> for TenzroError {
309 fn from(err: hex::FromHexError) -> Self {
310 Self::InvalidHash(err.to_string())
311 }
312}