mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-01 03:12:15 +00:00
Autofix for bip39bug
This commit is contained in:
parent
53713f5f2d
commit
c3af5a1ca2
@ -202,7 +202,12 @@ impl LightWallet {
|
|||||||
|
|
||||||
pub fn read<R: Read>(mut reader: R, config: &LightClientConfig) -> io::Result<Self> {
|
pub fn read<R: Read>(mut reader: R, config: &LightClientConfig) -> io::Result<Self> {
|
||||||
let version = reader.read_u64::<LittleEndian>()?;
|
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);
|
info!("Reading wallet version {}", version);
|
||||||
|
|
||||||
let locked = if version >= 4 {
|
let locked = if version >= 4 {
|
||||||
@ -1350,7 +1355,7 @@ impl LightWallet {
|
|||||||
|
|
||||||
if selected_value < u64::from(target_value) {
|
if selected_value < u64::from(target_value) {
|
||||||
let e = format!(
|
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
|
selected_value, target_value, self.config.anchor_offset
|
||||||
);
|
);
|
||||||
error!("{}", e);
|
error!("{}", e);
|
||||||
|
@ -43,6 +43,9 @@ impl BugBip39Derivation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fix_bug(client: &LightClient) -> String {
|
pub fn fix_bug(client: &LightClient) -> String {
|
||||||
|
use zcash_primitives::transaction::components::amount::DEFAULT_FEE;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
if !BugBip39Derivation::has_bug(client) {
|
if !BugBip39Derivation::has_bug(client) {
|
||||||
let r = object!{
|
let r = object!{
|
||||||
"has_bug" => false
|
"has_bug" => false
|
||||||
@ -51,7 +54,32 @@ impl BugBip39Derivation {
|
|||||||
return r.pretty(2);
|
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
|
// regen addresses
|
||||||
let wallet = client.wallet.read().unwrap();
|
let wallet = client.wallet.read().unwrap();
|
||||||
@ -76,6 +104,7 @@ impl BugBip39Derivation {
|
|||||||
let r = object!{
|
let r = object!{
|
||||||
"has_bug" => true,
|
"has_bug" => true,
|
||||||
"fixed" => true,
|
"fixed" => true,
|
||||||
|
"txid" => txid,
|
||||||
};
|
};
|
||||||
|
|
||||||
return r.pretty(2);
|
return r.pretty(2);
|
||||||
|
Loading…
Reference in New Issue
Block a user