Skip to content
Permalink
Browse files

Impl Display for account ledger error and remove unused variant

  • Loading branch information...
CodeSandwich committed May 14, 2019
1 parent fdc647b commit c1e96b6359c13c7415a21b6a61eec83a4dd150b9
Showing with 16 additions and 1 deletion.
  1. +16 −1 chain-impl-mockchain/src/accounting/account.rs
@@ -7,19 +7,34 @@
use crate::value::*;
use imhamt::{Hamt, InsertError, UpdateError};
use std::collections::hash_map::DefaultHasher;
use std::fmt::{self, Display, Formatter};
use std::hash::Hash;

/// Possible errors during an account operation
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LedgerError {
NonExistent,
AlreadyExists,
MismatchCounter,
NeedTotalWithdrawal,
NonZero,
ValueError(ValueError),
}

impl Display for LedgerError {
fn fmt(&self, formatter: &mut Formatter) -> Result<(), fmt::Error> {
match self {
LedgerError::NonExistent => "Account does not exist",
LedgerError::AlreadyExists => "Account already exists",
LedgerError::NeedTotalWithdrawal => {
"Operation counter reached its maximum and next operation must be full withdrawal"
}
LedgerError::NonZero => "Removed account is not empty",
LedgerError::ValueError(_) => "Value calculation failed",
}
.fmt(formatter)
}
}

impl From<ValueError> for LedgerError {
fn from(e: ValueError) -> Self {
LedgerError::ValueError(e)

0 comments on commit c1e96b6

Please sign in to comment.
You can’t perform that action at this time.