1use thiserror::Error;
10
11use crate::BigNumber;
12
13#[derive(Debug, Error)]
15#[non_exhaustive]
16pub enum EscrowError {
17 #[error("condition error: {0}")]
19 Condition(#[from] ConditionError),
20
21 #[error("invalid state transition")]
23 InvalidState,
24
25 #[error("identity error: {0}")]
27 Identity(#[from] IdentityError),
28
29 #[error("asset error: {0}")]
31 Asset(#[from] AssetError),
32
33 #[error("invalid chain operation: {0}")]
36 InvalidChainOp(String),
37
38 #[error("I/O error: {0}")]
40 Io(#[from] std::io::Error),
41
42 #[cfg(feature = "json")]
44 #[error("JSON error: {0}")]
45 Json(#[from] serde_json::Error),
46
47 #[error("unsupported chain specified")]
49 UnsupportedChain,
50}
51
52#[derive(Debug, Error)]
54#[non_exhaustive]
55pub enum ConditionError {
56 #[error("preimage (hashlock) failed: {0}")]
58 Hashlock(#[from] crate::condition::hashlock::Error),
59
60 #[error("ed25519 signature failed: {0}")]
62 Ed25519(#[from] crate::condition::ed25519::Error),
63
64 #[error("secp256k1 signature failed: {0}")]
66 Secp256k1(#[from] crate::condition::secp256k1::Error),
67
68 #[error("threshold check failed: {0}")]
70 Threshold(#[from] crate::condition::threshold::Error),
71}
72
73#[derive(Debug, Error)]
75#[non_exhaustive]
76pub enum IdentityError {
77 #[error("empty identity string")]
79 EmptyIdentity,
80
81 #[error("input length {len} exceeds maximum of {max} characters")]
83 InputTooLong {
84 len: usize,
86 max: usize,
88 },
89
90 #[error("hex decoding error: {0}")]
92 Hex(#[from] hex::FromHexError),
93
94 #[error("Base58 decoding error: {0}")]
96 Base58(#[from] bs58::decode::Error),
97
98 #[error("Base64 decoding error: {0}")]
100 Base64(#[from] base64::DecodeError),
101
102 #[error("unsupported identity format")]
104 UnsupportedFormat,
105}
106
107#[derive(Debug, Error)]
109#[non_exhaustive]
110pub enum AssetError {
111 #[error("could not serialize asset: {0}")]
113 Serialization(String),
114
115 #[error("could not parse asset: {0}")]
117 Parsing(String),
118
119 #[error("amount must be non-zero")]
121 ZeroAmount,
122
123 #[error("missing ID for asset, program, or contract")]
125 MissingId,
126
127 #[error("missing `total_supply` for specified token")]
129 MissingTotalSupply,
130
131 #[error("invalid ID for asset, program, or contract")]
133 InvalidId,
134
135 #[error("share must be non-zero and <= total supply (share={0}, total={1})")]
138 InvalidShare(BigNumber, BigNumber),
139
140 #[error("invalid decimals: {0}")]
142 InvalidDecimals(u8),
143
144 #[error("human formatting overflow: amount={0}, decimals={1}")]
146 FormatOverflow(BigNumber, u8),
147
148 #[error("unsupported asset string format")]
150 UnsupportedFormat,
151
152 #[error("integer parsing error: {0}")]
154 ParseInt(#[from] std::num::ParseIntError),
155}
156
157impl EscrowError {
158 pub fn to_str(&self) -> String {
161 self.to_string()
162 }
163}