use super::prelude::*;
use {bitcoin, cryptonote, ethereum};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Wallet {
pub coin: Coin,
pub address: String,
pub public_key: String,
pub private_key: String,
pub other: Option<HashMap<String, String>>,
}
impl Wallet {
pub fn generate(coin: Coin) -> Result<Self> {
use self::Coin::*;
match coin {
Ethereum | EthereumClassic => ethereum::new_wallet(coin),
Monero | Aeon => cryptonote::new_wallet(coin),
coin if bitcoin::wif_data(coin).is_some() => bitcoin::new_wallet(coin),
_ => Err(Error::CoinNotSupported(coin)),
}
}
}
#[test]
fn gen_all_wallets() {
use coin::COINS;
println!("Generating wallets for all coins...");
for coin in COINS.iter() {
let wallet = match Wallet::generate(*coin) {
Ok(wallet) => wallet,
Err(Error::CoinNotSupported(_)) => continue,
Err(e) => {
panic!(
"Error generating wallet for {:?} ({}): {}",
coin,
coin.symbol(),
e,
)
},
};
println!("Coin: {:?} ({})", coin, coin.symbol());
println!("Address: {}", &wallet.address);
println!("Public key: {}", &wallet.public_key);
println!("Private key: {}", &wallet.private_key);
if let Some(ref other) = wallet.other {
println!("Other: {:#?}", other);
}
println!();
}
}