mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-01-30 18:42:15 +00:00
Add bugfix address derivation
This commit is contained in:
parent
3ebc46185c
commit
611974c5fa
@ -463,19 +463,7 @@ impl Command for FixBip39BugCommand {
|
||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||
use crate::lightwallet::bugs::BugBip39Derivation;
|
||||
|
||||
let r = if BugBip39Derivation::has_bug(&lightclient.wallet.read().unwrap()) {
|
||||
object!{
|
||||
"has_bug" => true,
|
||||
"fixed" => false,
|
||||
}
|
||||
} else {
|
||||
object!{
|
||||
"has_bug" => false,
|
||||
"fixed" => false,
|
||||
}
|
||||
};
|
||||
|
||||
r.pretty(2)
|
||||
BugBip39Derivation::fix_bug(lightclient)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
use super::LightWallet;
|
||||
use crate::lightclient::LightClient;
|
||||
|
||||
use json::object;
|
||||
use bip39::{Mnemonic, Language};
|
||||
|
||||
pub struct BugBip39Derivation {}
|
||||
|
||||
impl BugBip39Derivation {
|
||||
|
||||
pub fn has_bug(wallet: &LightWallet) -> bool {
|
||||
pub fn has_bug(client: &LightClient) -> bool {
|
||||
let wallet = client.wallet.read().unwrap();
|
||||
|
||||
if wallet.zaddress.read().unwrap().len() <= 1 {
|
||||
return false;
|
||||
}
|
||||
@ -37,4 +41,43 @@ impl BugBip39Derivation {
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn fix_bug(client: &LightClient) -> String {
|
||||
if !BugBip39Derivation::has_bug(client) {
|
||||
let r = object!{
|
||||
"has_bug" => false
|
||||
};
|
||||
|
||||
return r.pretty(2);
|
||||
}
|
||||
|
||||
// TODO: Tranfer money
|
||||
|
||||
// regen addresses
|
||||
let wallet = client.wallet.read().unwrap();
|
||||
let num_zaddrs = wallet.zaddress.read().unwrap().len();
|
||||
let num_taddrs = wallet.taddresses.read().unwrap().len();
|
||||
|
||||
wallet.extsks.write().unwrap().truncate(1);
|
||||
wallet.extfvks.write().unwrap().truncate(1);
|
||||
wallet.zaddress.write().unwrap().truncate(1);
|
||||
|
||||
wallet.tkeys.write().unwrap().truncate(1);
|
||||
wallet.taddresses.write().unwrap().truncate(1);
|
||||
|
||||
for _ in 1..num_zaddrs {
|
||||
wallet.add_zaddr();
|
||||
}
|
||||
|
||||
for _ in 1..num_taddrs {
|
||||
wallet.add_taddr();
|
||||
}
|
||||
|
||||
let r = object!{
|
||||
"has_bug" => true,
|
||||
"fixed" => true,
|
||||
};
|
||||
|
||||
return r.pretty(2);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user