Skip to main content

canic_core/workflow/icrc/
query.rs

1//! Module: workflow::icrc::query
2//!
3//! Responsibility: expose ICRC-10 supported standards and ICRC-21 consent-message queries.
4//! Does not own: endpoint authorization, dispatcher internals, or standards DTO schemas.
5//! Boundary: workflow query facade over ICRC registry and dispatcher services.
6
7use crate::{
8    cdk::spec::standards::icrc::icrc21::{ConsentMessageRequest, ConsentMessageResponse},
9    config::Config,
10    dispatch::icrc21::Icrc21Dispatcher,
11    domain::icrc::icrc10::Icrc10Registry,
12    ops::runtime::env::EnvOps,
13};
14
15///
16/// Icrc10Query
17///
18
19pub struct Icrc10Query;
20
21impl Icrc10Query {
22    #[must_use]
23    pub fn supported_standards() -> Vec<(String, String)> {
24        let (icrc21_enabled, icrc103_enabled) = Config::try_get().map_or((false, false), |cfg| {
25            let global_standards = cfg.standards.as_ref();
26            let canister_standards = EnvOps::subnet_role().ok().and_then(|subnet_role| {
27                EnvOps::canister_role().ok().and_then(|canister_role| {
28                    cfg.subnets
29                        .get(&subnet_role)?
30                        .canisters
31                        .get(&canister_role)
32                        .map(|canister_cfg| &canister_cfg.standards)
33                })
34            });
35
36            (
37                global_standards.is_some_and(|standards| standards.icrc21)
38                    && canister_standards.is_some_and(|standards| standards.icrc21),
39                global_standards.is_some_and(|standards| standards.icrc103),
40            )
41        });
42
43        Icrc10Registry::supported_standards(icrc21_enabled, icrc103_enabled)
44    }
45}
46
47///
48/// Icrc21Query
49///
50
51pub struct Icrc21Query;
52
53impl Icrc21Query {
54    #[must_use]
55    pub fn consent_message(req: ConsentMessageRequest) -> ConsentMessageResponse {
56        Icrc21Dispatcher::consent_message(req)
57    }
58}