ic-query 0.26.5

Internet Computer query library for NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
#[cfg(feature = "host")]
use crate::ic_registry::MAINNET_GOVERNANCE_CANISTER_ID;
use crate::{
    agent::build_ic_agent,
    ic_registry::{MainnetRegistryFetchRequest, RegistryFetchError},
    subnet_catalog::MAINNET_REGISTRY_CANISTER_ID,
};
use candid::Principal;
use ic_agent::Agent;

pub(in crate::ic_registry::source) fn mainnet_agent(
    request: &MainnetRegistryFetchRequest,
) -> Result<Agent, RegistryFetchError> {
    build_ic_agent(&request.endpoint, |reason| RegistryFetchError::AgentBuild {
        endpoint: request.endpoint.clone(),
        reason,
    })
}

pub(in crate::ic_registry::source) fn mainnet_registry_canister()
-> Result<Principal, RegistryFetchError> {
    principal_from_text(MAINNET_REGISTRY_CANISTER_ID, "registry_canister_id")
}

#[cfg(feature = "host")]
pub(in crate::ic_registry::source) fn mainnet_governance_canister()
-> Result<Principal, RegistryFetchError> {
    principal_from_text(MAINNET_GOVERNANCE_CANISTER_ID, "governance_canister_id")
}

fn principal_from_text(value: &str, field: &'static str) -> Result<Principal, RegistryFetchError> {
    Principal::from_text(value).map_err(|err| RegistryFetchError::InvalidPrincipal {
        field,
        reason: err.to_string(),
    })
}