diff --git a/src/node-control/commands/src/commands/nodectl/config_wallet_cmd.rs b/src/node-control/commands/src/commands/nodectl/config_wallet_cmd.rs index 2d57bc2..5a07cf5 100644 --- a/src/node-control/commands/src/commands/nodectl/config_wallet_cmd.rs +++ b/src/node-control/commands/src/commands/nodectl/config_wallet_cmd.rs @@ -9,9 +9,10 @@ use crate::commands::nodectl::{ output_format::OutputFormat, utils::{ - SEND_TIMEOUT, check_ton_api_connection, get_wallet_config, load_config_vault, - load_config_vault_rpc_client, make_wallet, save_config, wait_for_seqno_change, - wallet_address, wallet_info, warn_missing_secret, warn_ton_api_unavailable, + MASTER_WALLET_RESERVED_NAME, SEND_TIMEOUT, check_ton_api_connection, get_wallet_config, + load_config_vault, load_config_vault_rpc_client, make_wallet, save_config, + wait_for_seqno_change, wallet_address, wallet_info, warn_missing_secret, + warn_ton_api_unavailable, }, }; use anyhow::Context; @@ -138,7 +139,7 @@ impl WalletCmd { impl WalletAddCmd { pub async fn run(&self, path: &Path) -> anyhow::Result<()> { - if self.name == "master_wallet" { + if self.name == MASTER_WALLET_RESERVED_NAME { anyhow::bail!("'master_wallet' is a reserved name"); } @@ -196,7 +197,7 @@ impl WalletLsCmd { let mut all_wallets: Vec<(&str, &WalletConfig)> = config.wallets.iter().map(|(k, v)| (k.as_str(), v)).collect(); if let Some(mw) = config.master_wallet.as_ref() { - all_wallets.push(("master_wallet", mw)); + all_wallets.push((MASTER_WALLET_RESERVED_NAME, mw)); } if all_wallets.is_empty() { @@ -326,6 +327,10 @@ async fn print_wallets_table( impl WalletRmCmd { pub async fn run(&self, path: &Path) -> anyhow::Result<()> { + if self.name == MASTER_WALLET_RESERVED_NAME { + anyhow::bail!("The master wallet cannot be removed"); + } + let mut config = AppConfig::load(path)?; if !config.wallets.contains_key(&self.name) { diff --git a/src/node-control/commands/src/commands/nodectl/utils.rs b/src/node-control/commands/src/commands/nodectl/utils.rs index 6601a5b..df78305 100644 --- a/src/node-control/commands/src/commands/nodectl/utils.rs +++ b/src/node-control/commands/src/commands/nodectl/utils.rs @@ -29,6 +29,9 @@ const POLL_INTERVAL: tokio::time::Duration = tokio::time::Duration::from_secs(2) pub const SEND_TIMEOUT: tokio::time::Duration = tokio::time::Duration::from_secs(15); pub const DEPLOY_TIMEOUT: tokio::time::Duration = tokio::time::Duration::from_secs(60); +/// Logical name for the master wallet in CLI, `get_wallet_config`, and `config wallet ls`. +pub const MASTER_WALLET_RESERVED_NAME: &str = "master_wallet"; + pub fn warn_missing_secret(secret_name: &str) { println!("\n{} {}", "[WARNING]".yellow().bold(), "Vault secret is missing".yellow(),); println!( @@ -136,7 +139,8 @@ pub fn get_wallet_config<'a>( wallets: &'a HashMap, master_wallet: Option<&'a WalletConfig>, ) -> anyhow::Result<&'a WalletConfig> { - let config = if name == "master_wallet" { master_wallet } else { wallets.get(name) }; + let config = + if name == MASTER_WALLET_RESERVED_NAME { master_wallet } else { wallets.get(name) }; config.ok_or_else(|| anyhow::anyhow!("Wallet not found '{}'", name)) }