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::component_spec().ok().and_then(|component_spec| {
27                EnvOps::canister_role().ok().and_then(|canister_role| {
28                    cfg.component_specs
29                        .get(&component_spec)?
30                        .get_canister(&canister_role)
31                        .map(|canister_cfg| canister_cfg.standards)
32                })
33            });
34
35            global_standards.is_some_and(|standards| standards.icrc21)
36                && canister_standards.is_some_and(|standards| standards.icrc21)
37        });
38
39        supported_standards(icrc21_enabled)
40    }
41}
42
43///
44/// Icrc21Query
45///
46
47pub struct Icrc21Query;
48
49impl Icrc21Query {
50    #[must_use]
51    pub fn consent_message(req: ConsentMessageRequest) -> ConsentMessageResponse {
52        Icrc21Dispatcher::consent_message(req)
53    }
54}