snark/user_command_verify/
snark_user_command_verify_actions.rs1use ledger::scan_state::transaction_logic::{valid, verifiable, WithStatus};
2use redux::Callback;
3use serde::{Deserialize, Serialize};
4
5use openmina_core::{transaction::TransactionPoolMessageSource, ActionEvent};
6
7use super::{SnarkUserCommandVerifyError, SnarkUserCommandVerifyId};
8
9pub type SnarkUserCommandVerifyActionWithMeta = redux::ActionWithMeta<SnarkUserCommandVerifyAction>;
10pub type SnarkUserCommandVerifyActionWithMetaRef<'a> =
11 redux::ActionWithMeta<&'a SnarkUserCommandVerifyAction>;
12
13pub(super) type OnSuccess = Callback<(
15 SnarkUserCommandVerifyId,
16 Vec<valid::UserCommand>,
17 TransactionPoolMessageSource,
18)>;
19
20#[derive(Serialize, Deserialize, Debug, Clone, ActionEvent)]
21#[action_event(level = trace, fields(display(req_id), display(error)))]
22pub enum SnarkUserCommandVerifyAction {
23 #[action_event(level = info)]
24 Init {
25 req_id: SnarkUserCommandVerifyId,
26 commands: Vec<WithStatus<verifiable::UserCommand>>,
27 from_source: TransactionPoolMessageSource,
28 on_success: OnSuccess,
29 on_error: Callback<(SnarkUserCommandVerifyId, Vec<String>)>,
30 },
31 Pending {
32 req_id: SnarkUserCommandVerifyId,
33 },
34 Error {
35 req_id: SnarkUserCommandVerifyId,
36 error: SnarkUserCommandVerifyError,
37 },
38 #[action_event(level = info)]
39 Success {
40 req_id: SnarkUserCommandVerifyId,
41 commands: Vec<valid::UserCommand>,
42 },
43 Finish {
44 req_id: SnarkUserCommandVerifyId,
45 },
46}
47
48impl redux::EnablingCondition<crate::SnarkState> for SnarkUserCommandVerifyAction {
49 fn is_enabled(&self, state: &crate::SnarkState, _time: redux::Timestamp) -> bool {
50 match self {
51 SnarkUserCommandVerifyAction::Init {
52 req_id, commands, ..
53 } => !commands.is_empty() && state.user_command_verify.jobs.next_req_id() == *req_id,
54 SnarkUserCommandVerifyAction::Pending { req_id } => state
55 .user_command_verify
56 .jobs
57 .get(*req_id)
58 .is_some_and(|v| v.is_init()),
59 SnarkUserCommandVerifyAction::Error { req_id, .. } => state
60 .user_command_verify
61 .jobs
62 .get(*req_id)
63 .is_some_and(|v| v.is_pending()),
64 SnarkUserCommandVerifyAction::Success { req_id, .. } => state
65 .user_command_verify
66 .jobs
67 .get(*req_id)
68 .is_some_and(|v| v.is_pending()),
69 SnarkUserCommandVerifyAction::Finish { req_id } => state
70 .user_command_verify
71 .jobs
72 .get(*req_id)
73 .is_some_and(|v| v.is_finished()),
74 }
75 }
76}