transaction_pool/
error.rs1use std::{error, fmt, result};
10
11#[derive(Debug)]
13pub enum Error<Hash: fmt::Debug + fmt::LowerHex> {
14 AlreadyImported(Hash),
16 TooCheapToEnter(Hash, String),
18 TooCheapToReplace(Hash, Hash),
20}
21
22pub type Result<T, H> = result::Result<T, Error<H>>;
24
25impl<H: fmt::Debug + fmt::LowerHex> fmt::Display for Error<H> {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Error::AlreadyImported(h) => write!(f, "[{:?}] already imported", h),
29 Error::TooCheapToEnter(hash, min_score) => {
30 write!(f, "[{:x}] too cheap to enter the pool. Min score: {}", hash, min_score)
31 }
32 Error::TooCheapToReplace(old_hash, hash) => write!(f, "[{:x}] too cheap to replace: {:x}", hash, old_hash),
33 }
34 }
35}
36
37impl<H: fmt::Debug + fmt::LowerHex> error::Error for Error<H> {}
38
39#[cfg(test)]
40impl<H: fmt::Debug + fmt::LowerHex> PartialEq for Error<H>
41where
42 H: PartialEq,
43{
44 fn eq(&self, other: &Self) -> bool {
45 use self::Error::*;
46
47 match (self, other) {
48 (&AlreadyImported(ref h1), &AlreadyImported(ref h2)) => h1 == h2,
49 (&TooCheapToEnter(ref h1, ref s1), &TooCheapToEnter(ref h2, ref s2)) => h1 == h2 && s1 == s2,
50 (&TooCheapToReplace(ref old1, ref new1), &TooCheapToReplace(ref old2, ref new2)) => {
51 old1 == old2 && new1 == new2
52 }
53 _ => false,
54 }
55 }
56}