/
snark_user_command_verify_actions.rs
66 lines (61 loc) · 2.34 KB
/
snark_user_command_verify_actions.rs
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
use ledger::scan_state::transaction_logic::{verifiable, WithStatus};
use serde::{Deserialize, Serialize};
use openmina_core::{snark::Snark, ActionEvent};
use super::{SnarkUserCommandVerifyError, SnarkUserCommandVerifyId};
pub type SnarkUserCommandVerifyActionWithMeta = redux::ActionWithMeta<SnarkUserCommandVerifyAction>;
pub type SnarkUserCommandVerifyActionWithMetaRef<'a> =
redux::ActionWithMeta<&'a SnarkUserCommandVerifyAction>;
#[derive(Serialize, Deserialize, Debug, Clone, ActionEvent)]
#[action_event(level = trace, fields(display(req_id), display(error)))]
pub enum SnarkUserCommandVerifyAction {
#[action_event(level = info)]
Init {
req_id: SnarkUserCommandVerifyId,
#[serde(skip)] // TODO
commands: Vec<WithStatus<verifiable::UserCommand>>,
sender: String,
},
Pending {
req_id: SnarkUserCommandVerifyId,
},
Error {
req_id: SnarkUserCommandVerifyId,
error: SnarkUserCommandVerifyError,
},
#[action_event(level = info)]
Success {
req_id: SnarkUserCommandVerifyId,
},
Finish {
req_id: SnarkUserCommandVerifyId,
},
}
impl redux::EnablingCondition<crate::SnarkState> for SnarkUserCommandVerifyAction {
fn is_enabled(&self, state: &crate::SnarkState, _time: redux::Timestamp) -> bool {
match self {
SnarkUserCommandVerifyAction::Init {
req_id, commands, ..
} => !commands.is_empty() && state.user_command_verify.jobs.next_req_id() == *req_id,
SnarkUserCommandVerifyAction::Pending { req_id } => state
.user_command_verify
.jobs
.get(*req_id)
.map_or(false, |v| v.is_init()),
SnarkUserCommandVerifyAction::Error { req_id, .. } => state
.user_command_verify
.jobs
.get(*req_id)
.map_or(false, |v| v.is_pending()),
SnarkUserCommandVerifyAction::Success { req_id } => state
.user_command_verify
.jobs
.get(*req_id)
.map_or(false, |v| v.is_pending()),
SnarkUserCommandVerifyAction::Finish { req_id } => state
.user_command_verify
.jobs
.get(*req_id)
.map_or(false, |v| v.is_finished()),
}
}
}