Skip to main content

aura_agent/runtime/effects/
aura.rs

1use super::AuraEffectSystem;
2use async_trait::async_trait;
3use aura_core::AuthorityId;
4use aura_guards::GuardContextProvider;
5use aura_protocol::effects::AuraEffects;
6
7// Implementation of AuraEffects (composite trait)
8#[async_trait]
9impl AuraEffects for AuraEffectSystem {
10    fn execution_mode(&self) -> aura_core::effects::ExecutionMode {
11        self.execution_mode
12    }
13}
14
15impl GuardContextProvider for AuraEffectSystem {
16    fn authority_id(&self) -> AuthorityId {
17        self.authority_id
18    }
19
20    fn get_metadata(&self, key: &str) -> Option<String> {
21        match key {
22            "authority_id" => Some(self.authority_id.to_string()),
23            "execution_mode" => Some(format!("{:?}", AuraEffects::execution_mode(self))),
24            "device_id" => Some(self.config.device_id().to_string()),
25            "biscuit_token" => self
26                .biscuit_cache
27                .read()
28                .as_ref()
29                .map(|c| c.token_b64.clone()),
30            "biscuit_root_pk" => self
31                .biscuit_cache
32                .read()
33                .as_ref()
34                .map(|c| c.root_pk_b64.clone()),
35            _ => None,
36        }
37    }
38
39    fn execution_mode(&self) -> aura_core::effects::ExecutionMode {
40        AuraEffects::execution_mode(self)
41    }
42
43    fn can_perform_operation(&self, _operation: &str) -> bool {
44        true
45    }
46}
47
48// ============================================================================
49// RuntimeEffectsBundle Implementation (for simulator decoupling)
50// ============================================================================
51
52#[cfg(feature = "simulation")]
53impl aura_core::effects::RuntimeEffectsBundle for AuraEffectSystem {
54    fn is_simulation_mode(&self) -> bool {
55        matches!(
56            self.execution_mode,
57            aura_core::effects::ExecutionMode::Simulation { .. }
58        )
59    }
60
61    fn simulation_seed(&self) -> Option<u64> {
62        match self.execution_mode {
63            aura_core::effects::ExecutionMode::Simulation { seed } => Some(seed),
64            _ => None,
65        }
66    }
67}