bitcoin_validation/state.rs
1crate::ix!();
2
3/**
4 | Template for capturing information
5 | about block/transaction validation.
6 | This is instantiated by TxValidationState
7 | and BlockValidationState for validation
8 | information on transactions and blocks
9 | respectively.
10 |
11 */
12#[derive(Default)]
13pub struct ValidationState<R> {
14 mode: validation_state::ModeState, //{ModeState::M_VALID};
15 result: R,
16 reject_reason: String,
17 debug_message: String,
18}
19
20pub mod validation_state {
21
22 pub enum ModeState {
23
24 /**
25 | everything ok
26 |
27 */
28 M_VALID,
29
30 /**
31 | network rule violation (DoS value may
32 | be set)
33 |
34 */
35 M_INVALID,
36
37 /**
38 | run-time error
39 |
40 */
41 M_ERROR,
42 }
43
44 impl Default for ModeState {
45 fn default() -> Self {
46 ModeState::M_VALID
47 }
48 }
49}
50
51impl<R> ValidationState<R> {
52
53 pub fn invalid(&mut self,
54 result: R,
55 reject_reason: Option<&str>,
56 debug_message: Option<&str>) -> bool {
57
58 let reject_reason: &str = reject_reason.unwrap_or("");
59 let debug_message: &str = debug_message.unwrap_or("");
60
61 todo!();
62 /*
63 m_result = result;
64 m_reject_reason = reject_reason;
65 m_debug_message = debug_message;
66 if (m_mode != ModeState::M_ERROR) m_mode = ModeState::M_INVALID;
67 return false;
68 */
69 }
70
71 pub fn error(&mut self, reject_reason: &String) -> bool {
72
73 todo!();
74 /*
75 if (m_mode == ModeState::M_VALID)
76 m_reject_reason = reject_reason;
77 m_mode = ModeState::M_ERROR;
78 return false;
79 */
80 }
81
82 pub fn is_valid(&self) -> bool {
83
84 todo!();
85 /*
86 return m_mode == ModeState::M_VALID;
87 */
88 }
89
90 pub fn is_invalid(&self) -> bool {
91
92 todo!();
93 /*
94 return m_mode == ModeState::M_INVALID;
95 */
96 }
97
98 pub fn is_error(&self) -> bool {
99
100 todo!();
101 /*
102 return m_mode == ModeState::M_ERROR;
103 */
104 }
105
106 pub fn get_result(&self) -> R {
107
108 todo!();
109 /*
110 return m_result;
111 */
112 }
113
114 pub fn get_reject_reason(&self) -> String {
115
116 todo!();
117 /*
118 return m_reject_reason;
119 */
120 }
121
122 pub fn get_debug_message(&self) -> String {
123
124 todo!();
125 /*
126 return m_debug_message;
127 */
128 }
129
130 pub fn to_string(&self) -> String {
131
132 todo!();
133 /*
134 if (IsValid()) {
135 return "Valid";
136 }
137
138 if (!m_debug_message.empty()) {
139 return m_reject_reason + ", " + m_debug_message;
140 }
141
142 return m_reject_reason;
143 */
144 }
145}