use crate::{cli::CurrentNetwork, console::account::PrivateKey};
use anyhow::{anyhow, Result};
fn env_template() -> String {
r#"
NETWORK=testnet3
PRIVATE_KEY={{PASTE_YOUR_PRIVATE_KEY_HERE}}
"#
.to_string()
}
fn dotenv_load() -> Result<()> {
dotenvy::dotenv().map_err(|_| {
anyhow!(
"Missing a '.env' file. Create the '.env' file in your package's root directory with the following:\n\n{}\n",
env_template()
)
})?;
Ok(())
}
pub fn dotenv_private_key() -> Result<PrivateKey<CurrentNetwork>> {
if cfg!(test) {
let rng = &mut crate::utilities::TestRng::fixed(123456789);
PrivateKey::<CurrentNetwork>::new(rng)
} else {
use std::str::FromStr;
dotenv_load()?;
let private_key = dotenvy::var("PRIVATE_KEY").map_err(|e| anyhow!("Missing PRIVATE_KEY - {e}"))?;
PrivateKey::<CurrentNetwork>::from_str(&private_key)
}
}