Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/node-control/commands/src/commands/nodectl/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -136,7 +139,8 @@ pub fn get_wallet_config<'a>(
wallets: &'a HashMap<String, WalletConfig>,
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))
}

Expand Down