Skip to content

Commit

Permalink
Merge pull request #2526 from ermineJose/sk_wallet_file-create
Browse files Browse the repository at this point in the history
feat: create wallet file from env sk
  • Loading branch information
jacderida authored Dec 16, 2024
2 parents 756aa11 + 5a6f3e6 commit 3345299
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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 and No secret Keys found in ENV, create one using `wallet create`")]
NoWalletsFoundAndNoSecretKeysInEnv,
#[error("No wallets found. Create one using `wallet create` or supply a private key using the `SECRET_KEY` environment variable")]
NoWalletsFound,
#[error("Invalid wallet selection input")]
InvalidSelection,
}
13 changes: 7 additions & 6 deletions ant-cli/src/wallet/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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::keys::load_evm_wallet_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 @@ -118,6 +118,11 @@ pub(crate) fn load_wallet_from_address(wallet_address: &str) -> Result<Wallet, E
}

pub(crate) fn select_wallet() -> Result<Wallet, Error> {
// try if there is a wallet set in the ENV first
if let Ok(env_wallet) = load_evm_wallet_from_env() {
return Ok(env_wallet);
}

let wallet_address = select_wallet_address()?;
load_wallet_from_address(&wallet_address)
}
Expand All @@ -137,11 +142,7 @@ 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 => {
let secret_key =
get_secret_key_from_env().map_err(|_| Error::NoWalletsFoundAndNoSecretKeysInEnv)?;
Ok(secret_key)
}
0 => Err(Error::NoWalletsFound),
1 => Ok(filter_wallet_file_extension(&wallet_files[0])),
_ => get_wallet_selection(wallet_files),
}?;
Expand Down

0 comments on commit 3345299

Please sign in to comment.