ic_query/system/cmc/
mod.rs1#[cfg(feature = "host")]
4mod build;
5mod model;
6#[cfg(feature = "host")]
7mod source;
8mod text;
9#[cfg(feature = "host")]
10mod wire;
11
12#[cfg(feature = "host")]
13use crate::runtime::RuntimeError;
14#[cfg(feature = "host")]
15use thiserror::Error as ThisError;
16
17#[cfg(feature = "host")]
18pub use build::{
19 build_cmc_cycles_report, build_cmc_cycles_report_with_source, build_cmc_xdr_report,
20 build_cmc_xdr_report_with_source,
21};
22#[cfg(feature = "host")]
23pub use model::CmcCertifiedRate;
24pub use model::{
25 CmcCertification, CmcCyclesReport, CmcIcpXdrConversionRate, CmcReportContext, CmcXdrReport,
26};
27#[cfg(feature = "host")]
28pub use source::{CmcSource, CmcSourceRequest, LiveCmcSource};
29pub use text::{cmc_cycles_report_text, cmc_xdr_report_text};
30
31pub const MAINNET_CMC_CANISTER_ID: &str = "rkp4c-7iaaa-aaaaa-aaaca-cai";
33
34pub const DEFAULT_CMC_SOURCE_ENDPOINT: &str = "https://icp-api.io";
36
37pub const CYCLES_PER_XDR: u128 = 1_000_000_000_000;
39
40#[cfg(feature = "host")]
41const ICP_XDR_PERMYRIAD_DENOMINATOR: u128 = 10_000;
42#[cfg(feature = "host")]
43const CMC_REPORT_SCHEMA_VERSION: u32 = 1;
44
45#[cfg(feature = "host")]
52#[derive(Debug, ThisError)]
53pub enum CmcHostError {
54 #[error(
56 "`icq system` supports only the mainnet `ic` network\n\nThese reports query the Internet Computer mainnet Cycle Minting Canister.\n\nTry:\n icq --network ic system xdr"
57 )]
58 UnsupportedNetwork {
59 network: String,
61 },
62
63 #[error("failed to build IC agent for {endpoint}: {reason}")]
65 AgentBuild {
66 endpoint: String,
68 reason: String,
70 },
71
72 #[error("invalid built-in CMC canister principal: {reason}")]
74 CanisterId {
75 reason: String,
77 },
78
79 #[error("CMC agent call {method} failed: {reason}")]
81 AgentCall {
82 method: &'static str,
84 reason: String,
86 },
87
88 #[error("failed to encode Candid {message}: {reason}")]
90 CandidEncode {
91 message: &'static str,
93 reason: String,
95 },
96
97 #[error("failed to decode Candid {message}: {reason}")]
99 CandidDecode {
100 message: &'static str,
102 reason: String,
104 },
105
106 #[error("CMC certified-rate authentication failed: {reason}")]
108 CertificateAuthentication {
109 reason: String,
111 },
112
113 #[error("invalid CMC certified-rate evidence: {reason}")]
115 InvalidCertifiedRate {
116 reason: String,
118 },
119
120 #[error("invalid CMC source data: {reason}")]
122 InvalidSourceData {
123 reason: String,
125 },
126
127 #[error(transparent)]
129 Runtime(#[from] RuntimeError),
130}
131
132#[cfg(feature = "host")]
133fn enforce_mainnet_network(network: &str) -> Result<(), CmcHostError> {
134 crate::network::enforce_mainnet_network_with(network, |network| {
135 CmcHostError::UnsupportedNetwork { network }
136 })
137}
138
139#[cfg(all(test, feature = "host"))]
140mod tests;