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 the standards projection and dispatcher services.
6
7use crate::{
8    config::Config,
9    dispatch::icrc21::Icrc21Dispatcher,
10    domain::icrc::icrc10::supported_standards,
11    dto::icrc21::{ConsentMessageRequest, ConsentMessageResponse},
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 = Config::try_get().is_some_and(|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            global_standards.is_some_and(|standards| standards.icrc21)
37                && canister_standards.is_some_and(|standards| standards.icrc21)
38        });
39
40        supported_standards(icrc21_enabled)
41    }
42}
43
44///
45/// Icrc21Query
46///
47
48pub struct Icrc21Query;
49
50impl Icrc21Query {
51    #[must_use]
52    pub fn consent_message(req: ConsentMessageRequest) -> ConsentMessageResponse {
53        Icrc21Dispatcher::consent_message(req)
54    }
55}