eth_valkyoth_protocol/
state.rs1use core::marker::PhantomData;
2
3use crate::ProtocolError;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub struct Decoded;
8
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub struct Canonical;
12
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15pub struct ForkValidated;
16
17#[derive(Clone, Copy, Debug, Eq, PartialEq)]
19pub struct SenderRecovered;
20
21#[derive(Debug, Eq, PartialEq)]
27pub struct CanonicalValidationProof {
28 _private: (),
29}
30
31impl CanonicalValidationProof {
32 #[must_use]
33 #[cfg(test)]
34 pub(crate) const fn new() -> Self {
35 Self { _private: () }
36 }
37}
38
39#[derive(Debug, Eq, PartialEq)]
45pub struct ForkValidationProof {
46 _private: (),
47}
48
49impl ForkValidationProof {
50 #[must_use]
51 #[cfg(test)]
52 pub(crate) const fn new() -> Self {
53 Self { _private: () }
54 }
55}
56
57#[derive(Debug, Eq, PartialEq)]
63pub struct SenderRecoveryProof {
64 _private: (),
65}
66
67impl SenderRecoveryProof {
68 #[must_use]
69 #[cfg(test)]
70 pub(crate) const fn new() -> Self {
71 Self { _private: () }
72 }
73}
74
75#[derive(Debug, Eq, PartialEq)]
77pub struct StateTransitionError<State> {
78 transaction: Transaction<State>,
79 error: ProtocolError,
80}
81
82impl<State> StateTransitionError<State> {
83 const fn new(transaction: Transaction<State>, error: ProtocolError) -> Self {
84 Self { transaction, error }
85 }
86
87 #[must_use]
89 pub const fn error(&self) -> ProtocolError {
90 self.error
91 }
92
93 #[must_use]
95 pub fn into_parts(self) -> (Transaction<State>, ProtocolError) {
96 (self.transaction, self.error)
97 }
98}
99
100#[derive(Debug, Eq, PartialEq)]
102pub struct Transaction<State> {
103 _state: PhantomData<State>,
104}
105
106impl<State> Transaction<State> {
107 const fn new() -> Self {
108 Self {
109 _state: PhantomData,
110 }
111 }
112}
113
114impl Transaction<Decoded> {
115 #[must_use]
120 #[cfg(test)]
121 pub(crate) const fn decoded() -> Self {
122 Self::new()
123 }
124
125 pub fn try_into_canonical(
127 self,
128 proof: Result<CanonicalValidationProof, ProtocolError>,
129 ) -> Result<Transaction<Canonical>, StateTransitionError<Decoded>> {
130 if let Err(error) = proof {
131 return Err(StateTransitionError::new(self, error));
132 }
133 Ok(Transaction::new())
134 }
135}
136
137impl Transaction<Canonical> {
138 pub fn try_into_fork_validated(
140 self,
141 proof: Result<ForkValidationProof, ProtocolError>,
142 ) -> Result<Transaction<ForkValidated>, StateTransitionError<Canonical>> {
143 if let Err(error) = proof {
144 return Err(StateTransitionError::new(self, error));
145 }
146 Ok(Transaction::new())
147 }
148}
149
150impl Transaction<ForkValidated> {
151 pub fn try_into_sender_recovered(
153 self,
154 proof: Result<SenderRecoveryProof, ProtocolError>,
155 ) -> Result<Transaction<SenderRecovered>, StateTransitionError<ForkValidated>> {
156 if let Err(error) = proof {
157 return Err(StateTransitionError::new(self, error));
158 }
159 Ok(Transaction::new())
160 }
161}
162
163#[cfg(test)]
164#[path = "state_tests.rs"]
165mod tests;