1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#![allow(clippy::unit_arg)]
use anyhow::Result;
#[cfg(any(test, feature = "fuzzing"))]
use proptest::prelude::*;
#[cfg(any(test, feature = "fuzzing"))]
use proptest_derive::Arbitrary;
use std::{convert::TryFrom, fmt};
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
#[cfg_attr(any(test, feature = "fuzzing"), proptest(no_params))]
pub struct MempoolStatus {
pub code: MempoolStatusCode,
pub message: String,
}
impl MempoolStatus {
pub fn new(code: MempoolStatusCode) -> Self {
Self {
code,
message: "".to_string(),
}
}
pub fn with_message(mut self, message: String) -> Self {
self.message = message;
self
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
#[repr(u64)]
pub enum MempoolStatusCode {
Accepted = 0,
InvalidSeqNumber = 1,
MempoolIsFull = 2,
TooManyTransactions = 3,
InvalidUpdate = 4,
VmError = 5,
UnknownStatus = 6,
}
impl TryFrom<u64> for MempoolStatusCode {
type Error = &'static str;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
0 => Ok(MempoolStatusCode::Accepted),
1 => Ok(MempoolStatusCode::InvalidSeqNumber),
2 => Ok(MempoolStatusCode::MempoolIsFull),
3 => Ok(MempoolStatusCode::TooManyTransactions),
4 => Ok(MempoolStatusCode::InvalidUpdate),
5 => Ok(MempoolStatusCode::VmError),
6 => Ok(MempoolStatusCode::UnknownStatus),
_ => Err("invalid StatusCode"),
}
}
}
impl From<MempoolStatusCode> for u64 {
fn from(status: MempoolStatusCode) -> u64 {
status as u64
}
}
impl fmt::Display for MempoolStatusCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}