1use serde::{Deserialize, Serialize};
2
3use crate::{
4 block_verify_effectful::SnarkBlockVerifyEffectfulAction,
5 user_command_verify::SnarkUserCommandVerifyAction,
6 user_command_verify_effectful::SnarkUserCommandVerifyEffectfulAction,
7 work_verify_effectful::SnarkWorkVerifyEffectfulAction,
8};
9
10use super::{block_verify::SnarkBlockVerifyAction, work_verify::SnarkWorkVerifyAction};
11
12pub type SnarkActionWithMeta = redux::ActionWithMeta<SnarkAction>;
13pub type SnarkActionWithMetaRef<'a> = redux::ActionWithMeta<&'a SnarkAction>;
14
15#[derive(derive_more::From, Serialize, Deserialize, Debug, Clone)]
16pub enum SnarkAction {
17 BlockVerify(SnarkBlockVerifyAction),
18 BlockVerifyEffect(SnarkBlockVerifyEffectfulAction),
19 WorkVerify(SnarkWorkVerifyAction),
20 WorkVerifyEffect(SnarkWorkVerifyEffectfulAction),
21 UserCommandVerify(SnarkUserCommandVerifyAction),
22 UserCommandVerifyEffect(SnarkUserCommandVerifyEffectfulAction),
23}
24
25impl redux::EnablingCondition<crate::SnarkState> for SnarkAction {
26 fn is_enabled(&self, state: &crate::SnarkState, time: redux::Timestamp) -> bool {
27 match self {
28 SnarkAction::BlockVerify(a) => a.is_enabled(state, time),
29 SnarkAction::BlockVerifyEffect(a) => a.is_enabled(state, time),
30 SnarkAction::WorkVerify(a) => a.is_enabled(state, time),
31 SnarkAction::WorkVerifyEffect(a) => a.is_enabled(state, time),
32 SnarkAction::UserCommandVerify(a) => a.is_enabled(state, time),
33 SnarkAction::UserCommandVerifyEffect(a) => a.is_enabled(state, time),
34 }
35 }
36}
37
38impl From<redux::AnyAction> for SnarkAction {
39 fn from(action: redux::AnyAction) -> Self {
40 *action.0.downcast::<Self>().expect("Downcast failed")
41 }
42}