#[cfg(feature = "host")]
mod build;
mod model;
#[cfg(feature = "host")]
mod source;
mod text;
#[cfg(feature = "host")]
mod wire;
#[cfg(feature = "host")]
use crate::runtime::RuntimeError;
#[cfg(feature = "host")]
use thiserror::Error as ThisError;
#[cfg(feature = "host")]
pub use build::{
build_cmc_cycles_report, build_cmc_cycles_report_with_source, build_cmc_xdr_report,
build_cmc_xdr_report_with_source,
};
#[cfg(feature = "host")]
pub use model::CmcCertifiedRate;
pub use model::{
CmcCertification, CmcCyclesReport, CmcIcpXdrConversionRate, CmcReportContext, CmcXdrReport,
};
#[cfg(feature = "host")]
pub use source::{CmcSource, CmcSourceRequest, LiveCmcSource};
pub use text::{cmc_cycles_report_text, cmc_xdr_report_text};
pub const MAINNET_CMC_CANISTER_ID: &str = "rkp4c-7iaaa-aaaaa-aaaca-cai";
pub const DEFAULT_CMC_SOURCE_ENDPOINT: &str = "https://icp-api.io";
pub const CYCLES_PER_XDR: u128 = 1_000_000_000_000;
#[cfg(feature = "host")]
const ICP_XDR_PERMYRIAD_DENOMINATOR: u128 = 10_000;
#[cfg(feature = "host")]
const CMC_REPORT_SCHEMA_VERSION: u32 = 1;
#[cfg(feature = "host")]
#[derive(Debug, ThisError)]
pub enum CmcHostError {
#[error(
"`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"
)]
UnsupportedNetwork {
network: String,
},
#[error("failed to build IC agent for {endpoint}: {reason}")]
AgentBuild {
endpoint: String,
reason: String,
},
#[error("invalid built-in CMC canister principal: {reason}")]
CanisterId {
reason: String,
},
#[error("CMC agent call {method} failed: {reason}")]
AgentCall {
method: &'static str,
reason: String,
},
#[error("failed to encode Candid {message}: {reason}")]
CandidEncode {
message: &'static str,
reason: String,
},
#[error("failed to decode Candid {message}: {reason}")]
CandidDecode {
message: &'static str,
reason: String,
},
#[error("CMC certified-rate authentication failed: {reason}")]
CertificateAuthentication {
reason: String,
},
#[error("invalid CMC certified-rate evidence: {reason}")]
InvalidCertifiedRate {
reason: String,
},
#[error("invalid CMC source data: {reason}")]
InvalidSourceData {
reason: String,
},
#[error(transparent)]
Runtime(#[from] RuntimeError),
}
#[cfg(feature = "host")]
fn enforce_mainnet_network(network: &str) -> Result<(), CmcHostError> {
crate::network::enforce_mainnet_network_with(network, |network| {
CmcHostError::UnsupportedNetwork { network }
})
}
#[cfg(all(test, feature = "host"))]
mod tests;