kaspa_cli_lib/modules/
network.rs

1use crate::imports::*;
2
3#[derive(Default, Handler)]
4#[help("Select network type (mainnet|testnet)")]
5pub struct Network;
6
7impl Network {
8    async fn main(self: Arc<Self>, ctx: &Arc<dyn Context>, argv: Vec<String>, _cmd: &str) -> Result<()> {
9        let ctx = ctx.clone().downcast_arc::<KaspaCli>()?;
10
11        if let Some(network_id) = argv.first() {
12            let network_id: NetworkId = network_id.trim().parse::<NetworkId>()?;
13            tprintln!(ctx, "Setting network id to: {network_id}");
14            ctx.wallet().set_network_id(&network_id)?;
15            ctx.wallet().settings().set(WalletSettings::Network, network_id).await?;
16        } else {
17            let network_id = ctx.wallet().network_id()?;
18            tprintln!(ctx, "Current network id is: {network_id}");
19        }
20
21        Ok(())
22    }
23}