Bruno BELANYI
6d98a05cee
It is unclear whether or deposits should be disputable, or only withdrawals. At the moment, both are disputable, but that does mean we can get into "weird" states by disputing a deposit: the held funds being negative. In turn, this means that there is relatively little error-checking for those balance values, the only clear thing is that withdrawing more than is currently available is absolutely an error. But is holding more than is available also an error? What about having a negative held funds balance? A negative total funds? Etc...
29 lines
958 B
Rust
29 lines
958 B
Rust
//! Error types for this crate.
|
|
use thiserror::Error;
|
|
|
|
use crate::{ClientId, TxId};
|
|
|
|
/// Any kind of error that can happen when processing a [crate::Transaction] in a [crate::Ledger].
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Error)]
|
|
pub enum LedgerError {
|
|
#[error("not enough funds available to run transaction")]
|
|
NotEnoughFunds,
|
|
#[error("unknown transaction with user '{0}', id '{1}'")]
|
|
UnknownTx(ClientId, TxId),
|
|
#[error("transaction has already been disputed")]
|
|
AlreadyDisputed,
|
|
#[error("transaction is not currently disputed")]
|
|
NotDisputed,
|
|
#[error("account is frozen")]
|
|
FrozenAccount,
|
|
}
|
|
|
|
/// Any kind of error that can happen when deserializing a [crate::Transaction] value.
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Error)]
|
|
pub enum ParseError {
|
|
#[error("amount not provided")]
|
|
MissingAmount,
|
|
#[error("unknown transaction type '{0}'")]
|
|
UnknownTx(String),
|
|
}
|