Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use secret key from env if no wallets are present #2509

Merged
merged 2 commits into from
Dec 10, 2024
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
4 changes: 2 additions & 2 deletions ant-cli/src/wallet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
7 changes: 6 additions & 1 deletion ant-cli/src/wallet/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -133,7 +134,11 @@ pub(crate) fn select_wallet_address() -> Result<String, Error> {
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),
}?;
Expand Down
Loading