kona_protocol/batch/
validity.rs1#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum BatchValidity {
7 Drop,
9 Accept,
11 Undecided,
13 Future,
15 Past,
18}
19
20impl core::fmt::Display for BatchValidity {
21 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22 match self {
23 Self::Drop => write!(f, "Drop"),
24 Self::Accept => write!(f, "Accept"),
25 Self::Undecided => write!(f, "Undecided"),
26 Self::Future => write!(f, "Future"),
27 Self::Past => write!(f, "Past"),
28 }
29 }
30}
31
32impl BatchValidity {
33 pub const fn is_accept(&self) -> bool {
35 matches!(self, Self::Accept)
36 }
37
38 pub const fn is_drop(&self) -> bool {
40 matches!(self, Self::Drop)
41 }
42
43 pub const fn is_outdated(&self) -> bool {
45 matches!(self, Self::Past)
46 }
47
48 pub const fn is_future(&self) -> bool {
50 matches!(self, Self::Future)
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_batch_validity() {
60 assert!(BatchValidity::Accept.is_accept());
61 assert!(BatchValidity::Drop.is_drop());
62 assert!(BatchValidity::Past.is_outdated());
63 assert!(BatchValidity::Future.is_future());
64 }
65}