1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::imports::*;

#[derive(Default, Handler)]
#[help("Select network type (mainnet|testnet)")]
pub struct Network;

impl Network {
    async fn main(self: Arc<Self>, ctx: &Arc<dyn Context>, argv: Vec<String>, _cmd: &str) -> Result<()> {
        let ctx = ctx.clone().downcast_arc::<KaspaCli>()?;

        if let Some(network_id) = argv.first() {
            let network_id: NetworkId = network_id.trim().parse::<NetworkId>()?;
            tprintln!(ctx, "Setting network id to: {network_id}");
            ctx.wallet().set_network_id(network_id)?;
            ctx.wallet().settings().set(WalletSettings::Network, network_id).await?;
        } else {
            let network_id = ctx.wallet().network_id()?;
            tprintln!(ctx, "Current network id is: {network_id}");
        }

        Ok(())
    }
}