set variable number of restore zaddr

This commit is contained in:
DenioD
2020-06-18 12:42:11 +02:00
parent 62d2a10cbd
commit e9c10d987a
3 changed files with 59 additions and 18 deletions

View File

@@ -204,7 +204,7 @@ impl LightWallet {
}
}
pub fn new(seed_phrase: Option<String>, config: &LightClientConfig, latest_block: u64) -> io::Result<Self> {
pub fn new(seed_phrase: Option<String>, config: &LightClientConfig, latest_block: u64, number: u64) -> io::Result<Self> {
// This is the source entropy that corresponds to the 24-word seed phrase
let mut seed_bytes = [0u8; 32];
@@ -213,7 +213,7 @@ impl LightWallet {
let mut system_rng = OsRng;
system_rng.fill(&mut seed_bytes);
} else {
let phrase = match Mnemonic::from_phrase(seed_phrase.unwrap(), Language::English) {
let phrase = match Mnemonic::from_phrase(seed_phrase.clone().unwrap(), Language::English) {
Ok(p) => p,
Err(e) => {
let e = format!("Error parsing phrase: {}", e);
@@ -238,7 +238,7 @@ impl LightWallet {
let (extsk, extfvk, address)
= LightWallet::get_zaddr_from_bip39seed(&config, &bip39_seed.as_bytes(), 0);
Ok(LightWallet {
let lw = LightWallet {
encrypted: false,
unlocked: true,
enc_seed: [0u8; 48],
@@ -254,7 +254,19 @@ impl LightWallet {
mempool_txs: Arc::new(RwLock::new(HashMap::new())),
config: config.clone(),
birthday: latest_block,
})
};
// If restoring from seed, make sure we are creating 50 addresses for users
if seed_phrase.is_some() {
for _i in 0..number {
lw.add_zaddr();
}
for _i in 0..5 {
lw.add_taddr();
}
}
Ok(lw)
}
pub fn read<R: Read>(mut inp: R, config: &LightClientConfig) -> io::Result<Self> {