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: create wallet file from env sk #2526

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions ant-cli/src/wallet/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use autonomi::{get_evm_network_from_env, RewardsAddress, Wallet};
use const_hex::traits::FromHex;
use prettytable::{Cell, Row, Table};
use std::ffi::OsString;
use std::io::Read;
use std::io::{Read, Write};
use std::path::PathBuf;
use std::sync::OnceLock;

Expand Down Expand Up @@ -137,7 +137,15 @@ pub(crate) fn select_wallet_address() -> Result<String, Error> {
0 => {
ermineJose marked this conversation as resolved.
Show resolved Hide resolved
let secret_key =
get_secret_key_from_env().map_err(|_| Error::NoWalletsFoundAndNoSecretKeysInEnv)?;
Ok(secret_key)
let network = get_evm_network_from_env().expect("Could not load EVM network from environment");
let wallet = Wallet::new_from_private_key(network, &secret_key).expect("Could not initialize wallet");
let public_key = wallet.address().to_string();
let wallet_directory = get_client_wallet_dir_path()?;
let file_path = std::path::Path::new(&wallet_directory).join(&public_key);
let mut file = std::fs::File::create(&file_path).expect("Could not create file on disk");
file.write_all(secret_key.as_bytes()).expect("Could not write secret key to file");

Ok(public_key)
}
1 => Ok(filter_wallet_file_extension(&wallet_files[0])),
_ => get_wallet_selection(wallet_files),
Expand Down
Loading