pub type MintResult<T> = std::result::Result<T, MintError>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum MintError {
#[error("insufficient funds: need a confirmed coin of at least {required} mojos, largest is {available}")]
InsufficientFunds {
required: u64,
available: u64,
},
#[error("the coin that would fund this mint is reserved by an in-flight spend: it needs {required} mojos, the wallet's largest confirmed coin is {available} and is busy")]
CoinsReserved {
required: u64,
available: u64,
},
#[error("{0}")]
ReservationUnusable(String),
#[error("spend rejected by the network: {0}")]
Rejected(String),
#[error("chain unreachable: {0}")]
ChainUnreachable(String),
#[error("could not build the mint spend: {0}")]
Build(String),
#[error("account is locked")]
Locked,
#[error("mint fee of {fee} mojos is above the {ceiling} mojo ceiling")]
FeeAboveCeiling {
fee: u64,
ceiling: u64,
},
#[error("the profile registry refused this mint: {0}")]
Journal(String),
#[error("refusing to sign the mint spend: {0}")]
Refused(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_three_wizard_outcomes_are_distinct_variants() {
let broke = MintError::InsufficientFunds {
required: 2,
available: 1,
};
let refused = MintError::Rejected("DOUBLE_SPEND".into());
let offline = MintError::ChainUnreachable("connection refused".into());
assert!(matches!(broke, MintError::InsufficientFunds { .. }));
assert!(matches!(refused, MintError::Rejected(_)));
assert!(matches!(offline, MintError::ChainUnreachable(_)));
assert!(broke.to_string().contains("insufficient funds"));
assert_eq!(
refused.to_string(),
"spend rejected by the network: DOUBLE_SPEND"
);
assert_eq!(offline.to_string(), "chain unreachable: connection refused");
}
}