rules.rs

benches/rrt/canister/src/workflows/sequence/rules.rs

rules.rs64 lines← Benchmarks
1#![allow(non_snake_case, non_upper_case_globals)]2use super::memory::current as M;3use cdk_rsx::Principal;4use cdk_rsx::wire::Nat;5use cdk_rsx_takt as flow;6#[derive(Clone, Debug, cdk_rsx::WireType, serde::Deserialize, serde::Serialize)]7pub struct Done {8    pub blocks: Vec<Nat>,9    pub caller: Principal,10}11#[derive(Clone, Debug, cdk_rsx::WireType, serde::Deserialize, serde::Serialize)]12pub enum Status {13    Pending,14    Done(Done),15    Failed,16    Changed,17}18pub fn status(snapshot: &flow::Snapshot<M::Progress, M::Error>) -> Status {19    match &snapshot.status {20        flow::Status::Succeeded(M::Progress::Request(r)) => Status::Done(Done {21            blocks: r.blocks.iter().copied().map(Nat::from).collect(),22            caller: r.caller,23        }),24        flow::Status::Failed(_) => Status::Failed,25        flow::Status::DefinitionChanged => Status::Changed,26        _ => Status::Pending,27    }28}29pub fn authorized(caller: Principal, snapshot: &flow::Snapshot<M::Progress, M::Error>) -> bool {30    matches!(&snapshot.input,M::Progress::Request(r) if r.caller==caller)31}32pub fn error(value: &M::Error) -> String {33    format!("{value:?}")34}35pub fn retryable(value: &M::Error) -> bool {36    matches!(value, M::Error::Unavailable)37}38pub const contract: flow::ParticipantContract = flow::ParticipantContract {39    id: "work.dispatch.v1",40    safety: flow::Safety::Idempotent,41    evidence: flow::Evidence::Receipt,42};43pub fn details(value: &M::Progress) -> Vec<flow::InspectionField> {44    let M::Progress::Request(r) = value;45    vec![46        flow::InspectionField {47            name: "Job".into(),48            text: r.job.to_string(),49        },50        flow::InspectionField {51            name: "Block references".into(),52            text: r.blocks.len().to_string(),53        },54    ]55}56pub fn rejected(value: &M::Error) -> bool {57    matches!(value, M::Error::Rejected)58}59pub fn failed(value: &M::Request, _: &M::Error) -> M::Request {60    value.clone()61}62pub fn rejection(_: &M::Request) -> M::Error {63    M::Error::Rejected64}