From 408cea7d29ef37308cac4d662d8e6f210d14ebe1 Mon Sep 17 00:00:00 2001 From: Ermine Jose Date: Mon, 9 Dec 2024 21:36:05 +0530 Subject: [PATCH] feat: use secret key from env if no wallets are present --- ant-cli/src/wallet/error.rs | 4 ++-- ant-cli/src/wallet/fs.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ant-cli/src/wallet/error.rs b/ant-cli/src/wallet/error.rs index b32455566d..1dd8fa6c91 100644 --- a/ant-cli/src/wallet/error.rs +++ b/ant-cli/src/wallet/error.rs @@ -24,8 +24,8 @@ pub enum Error { FailedToCreateWalletsFolder, #[error("Could not find private key file")] PrivateKeyFileNotFound, - #[error("No wallets found. Create one using `wallet create`")] - NoWalletsFound, + #[error("No wallets found and No secret Keys found in ENV, create one using `wallet create`")] + NoWalletsFoundAndNoSecretKeysInEnv, #[error("Invalid wallet selection input")] InvalidSelection, } diff --git a/ant-cli/src/wallet/fs.rs b/ant-cli/src/wallet/fs.rs index 39426bf5a1..136ddf5c4f 100644 --- a/ant-cli/src/wallet/fs.rs +++ b/ant-cli/src/wallet/fs.rs @@ -6,6 +6,7 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. +use crate::keys::get_secret_key_from_env; use crate::wallet::encryption::{decrypt_private_key, encrypt_private_key}; use crate::wallet::error::Error; use crate::wallet::input::{get_password_input, get_wallet_selection_input}; @@ -133,7 +134,11 @@ pub(crate) fn select_wallet_address() -> Result { let wallet_files = get_wallet_files(&wallets_folder)?; let wallet_address = match wallet_files.len() { - 0 => Err(Error::NoWalletsFound), + 0 => { + let secret_key = + get_secret_key_from_env().map_err(|_| Error::NoWalletsFoundAndNoSecretKeysInEnv)?; + Ok(secret_key) + } 1 => Ok(filter_wallet_file_extension(&wallet_files[0])), _ => get_wallet_selection(wallet_files), }?;