dfxmon-cli 0.1.4

CLI tool for interacting with dfxmon canister on the Internet Computer
/// dfxmon canister IDs for different networks
/// Local canister ID for development (dfx start)
pub const DFXMON_LOCAL_CANISTER_ID: &str = "uxrrr-q7777-77774-qaaaq-cai";
/// Mainnet canister ID for production use
pub const DFXMON_MAINNET_CANISTER_ID: &str = "yvfam-kiaaa-aaaag-aucfa-cai";

/// Network URL constants
pub const LOCAL_NETWORK_URL: &str = "http://localhost:4943";
pub const MAINNET_NETWORK_URL: &str = "https://ic0.app";

/// Resolves network shorthand to full URL
pub fn resolve_network_url(network: &str) -> String {
    match network {
        "local" => LOCAL_NETWORK_URL.to_string(),
        "mainnet" | "ic" => MAINNET_NETWORK_URL.to_string(),
        url if url.starts_with("http://") || url.starts_with("https://") => url.to_string(),
        _ => {
            // Assume it's a custom URL without protocol
            format!("http://{}", network)
        }
    }
}

/// Determines the appropriate dfxmon canister ID based on the network URL
pub fn get_default_canister_id(network_url: &str) -> &'static str {
    if network_url.contains("localhost") || network_url.contains("127.0.0.1") {
        DFXMON_LOCAL_CANISTER_ID
    } else if network_url.contains("icp0.io") || network_url.contains("ic0.app") || network_url == MAINNET_NETWORK_URL {
        DFXMON_MAINNET_CANISTER_ID
    } else {
        // Default to mainnet for unknown networks
        DFXMON_MAINNET_CANISTER_ID
    }
}