1use thiserror::Error;
2
3use crate::BigNumber;
4
5#[derive(Debug, Error)]
7pub enum EscrowError {
8 #[error("condition error: {0}")]
10 Condition(#[from] ConditionError),
11
12 #[error("invalid state transition")]
14 InvalidState,
15
16 #[error("identity error: {0}")]
18 Identity(#[from] IdentityError),
19
20 #[error("asset error: {0}")]
22 Asset(#[from] AssetError),
23
24 #[error("invalid chain operation: {0}")]
27 InvalidChainOp(String),
28
29 #[error("I/O error: {0}")]
31 Io(#[from] std::io::Error),
32
33 #[cfg(feature = "json")]
35 #[error("JSON error: {0}")]
36 Json(#[from] serde_json::Error),
37
38 #[error("unsupported chain specified")]
40 UnsupportedChain,
41}
42
43#[derive(Debug, Error)]
45pub enum ConditionError {
46 #[error("preimage (hashlock) failed: {0}")]
48 Hashlock(#[from] crate::condition::hashlock::Error),
49
50 #[error("ed25519 signature failed: {0}")]
52 Ed25519(#[from] crate::condition::ed25519::Error),
53
54 #[error("secp256k1 signature failed: {0}")]
56 Secp256k1(#[from] crate::condition::secp256k1::Error),
57
58 #[error("threshold check failed: {0}")]
60 Threshold(#[from] crate::condition::threshold::Error),
61}
62
63#[derive(Debug, Error)]
65pub enum IdentityError {
66 #[error("empty identity string")]
68 EmptyIdentity,
69
70 #[error("input length {len} exceeds maximum of {max} characters")]
72 InputTooLong {
73 len: usize,
75 max: usize,
77 },
78
79 #[error("hex decoding error: {0}")]
81 Hex(#[from] hex::FromHexError),
82
83 #[error("Base58 decoding error: {0}")]
85 Base58(#[from] bs58::decode::Error),
86
87 #[error("Base64 decoding error: {0}")]
89 Base64(#[from] base64::DecodeError),
90
91 #[error("unsupported identity format")]
93 UnsupportedFormat,
94}
95
96#[derive(Debug, Error)]
98pub enum AssetError {
99 #[error("could not serialize asset: {0}")]
101 Serialization(String),
102
103 #[error("could not parse asset: {0}")]
105 Parsing(String),
106
107 #[error("amount must be non-zero")]
109 ZeroAmount,
110
111 #[error("missing ID for asset, program, or contract")]
113 MissingId,
114
115 #[error("missing `total_supply` for specified token")]
117 MissingTotalSupply,
118
119 #[error("inalid ID for asset, program, or contract")]
121 InvalidId,
122
123 #[error("share must be non-zero and <= total supply (share={0}, total={1})")]
126 InvalidShare(BigNumber, BigNumber),
127
128 #[error("invalid decimals: {0}")]
130 InvalidDecimals(u8),
131
132 #[error("human formatting overflow: amount={0}, decimals={1}")]
134 FormatOverflow(BigNumber, u8),
135
136 #[error("unsupported asset string format")]
138 UnsupportedFormat,
139
140 #[error("integer parsing error: {0}")]
142 ParseInt(#[from] std::num::ParseIntError),
143}
144
145impl EscrowError {
146 pub fn to_str(&self) -> String {
149 self.to_string()
150 }
151}