pub mod query;
use crate::{
InternalError,
dto::state::{AppCommand, AppCommandResponse},
ops::{runtime::env::EnvOps, storage::state::app::AppStateOps},
workflow::cascade::{snapshot::StateSnapshotBuilder, state::StateCascadeWorkflow},
};
pub struct AppStateWorkflow;
impl AppStateWorkflow {
pub async fn execute_command(cmd: AppCommand) -> Result<AppCommandResponse, InternalError> {
EnvOps::require_root()?;
let response = AppStateOps::apply_command(cmd);
if !app_command_response_changed(response) {
return Ok(response);
}
let snapshot = StateSnapshotBuilder::new()?
.with_app_state()
.with_subnet_state()
.build();
StateCascadeWorkflow::root_cascade_state(&snapshot).await?;
Ok(response)
}
}
const fn app_command_response_changed(response: AppCommandResponse) -> bool {
match response {
AppCommandResponse::Status(status) => status.changed,
AppCommandResponse::CyclesFundingEnabled(enabled) => enabled.changed,
}
}