Browse Source

Autofix for bip39bug

checkpoints
Aditya Kulkarni 5 years ago
parent
commit
c3af5a1ca2
  1. 9
      lib/src/lightwallet.rs
  2. 33
      lib/src/lightwallet/bugs.rs

9
lib/src/lightwallet.rs

@ -202,7 +202,12 @@ impl LightWallet {
pub fn read<R: Read>(mut reader: R, config: &LightClientConfig) -> io::Result<Self> {
let version = reader.read_u64::<LittleEndian>()?;
assert!(version <= LightWallet::serialized_version());
if version > LightWallet::serialized_version() {
let e = format!("Don't know how to read wallet version {}. Do you have the latest version?", version);
error!("{}", e);
return Err(io::Error::new(ErrorKind::InvalidData, e));
}
info!("Reading wallet version {}", version);
let locked = if version >= 4 {
@ -1350,7 +1355,7 @@ impl LightWallet {
if selected_value < u64::from(target_value) {
let e = format!(
"Insufficient verified funds (have {}, need {:?}).\nNote: funds need {} confirmations before they can be spent",
"Insufficient verified funds (have {}, need {:?}). NOTE: funds need {} confirmations before they can be spent.",
selected_value, target_value, self.config.anchor_offset
);
error!("{}", e);

33
lib/src/lightwallet/bugs.rs

@ -43,6 +43,9 @@ impl BugBip39Derivation {
}
pub fn fix_bug(client: &LightClient) -> String {
use zcash_primitives::transaction::components::amount::DEFAULT_FEE;
use std::convert::TryInto;
if !BugBip39Derivation::has_bug(client) {
let r = object!{
"has_bug" => false
@ -51,7 +54,32 @@ impl BugBip39Derivation {
return r.pretty(2);
}
// TODO: Tranfer money
// Tranfer money
// 1. The desination is z address #0
let zaddr = client.do_address()["z_addresses"][0].as_str().unwrap().to_string();
let balance_json = client.do_balance();
let fee: u64 = DEFAULT_FEE.try_into().unwrap();
let amount: u64 = balance_json["zbalance"].as_u64().unwrap()
+ balance_json["tbalance"].as_u64().unwrap()
- fee;
let txid = if amount > 0 {
match client.do_send(vec![(&zaddr, amount, None)]) {
Ok(txid) => txid,
Err(e) => {
let r = object!{
"has_bug" => true,
"fixed" => false,
"error" => e,
};
return r.pretty(2);
}
}
} else {
"".to_string()
};
// regen addresses
let wallet = client.wallet.read().unwrap();
@ -75,7 +103,8 @@ impl BugBip39Derivation {
let r = object!{
"has_bug" => true,
"fixed" => true,
"fixed" => true,
"txid" => txid,
};
return r.pretty(2);

Loading…
Cancel
Save