|
@ -11,7 +11,7 @@ use log::{info, warn, error}; |
|
|
|
|
|
|
|
|
use protobuf::parse_from_bytes; |
|
|
use protobuf::parse_from_bytes; |
|
|
|
|
|
|
|
|
use libflate::{gzip::{Decoder, Encoder}, finish::AutoFinishUnchecked}; |
|
|
use libflate::gzip::{Decoder}; |
|
|
use secp256k1::SecretKey; |
|
|
use secp256k1::SecretKey; |
|
|
use bip39::{Mnemonic, Language}; |
|
|
use bip39::{Mnemonic, Language}; |
|
|
|
|
|
|
|
@ -135,7 +135,7 @@ pub struct LightWallet { |
|
|
|
|
|
|
|
|
impl LightWallet { |
|
|
impl LightWallet { |
|
|
pub fn serialized_version() -> u64 { |
|
|
pub fn serialized_version() -> u64 { |
|
|
return 5; |
|
|
return 6; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fn get_taddr_from_bip39seed(config: &LightClientConfig, bip39_seed: &[u8], pos: u32) -> SecretKey { |
|
|
fn get_taddr_from_bip39seed(config: &LightClientConfig, bip39_seed: &[u8], pos: u32) -> SecretKey { |
|
@ -243,8 +243,8 @@ impl LightWallet { |
|
|
println!("Reading wallet version {}", version); |
|
|
println!("Reading wallet version {}", version); |
|
|
info!("Reading wallet version {}", version); |
|
|
info!("Reading wallet version {}", version); |
|
|
|
|
|
|
|
|
// After version 5, we're writing the rest of the file as a compressed stream (gzip)
|
|
|
// At version 5, we're writing the rest of the file as a compressed stream (gzip)
|
|
|
let mut reader: Box<dyn Read> = if version <= 4 { |
|
|
let mut reader: Box<dyn Read> = if version !=5 { |
|
|
info!("Reading direct"); |
|
|
info!("Reading direct"); |
|
|
Box::new(inp) |
|
|
Box::new(inp) |
|
|
} else { |
|
|
} else { |
|
@ -342,17 +342,14 @@ impl LightWallet { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn write<W: Write>(&self, mut out: W) -> io::Result<()> { |
|
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> { |
|
|
if self.encrypted && self.unlocked { |
|
|
if self.encrypted && self.unlocked { |
|
|
return Err(Error::new(ErrorKind::InvalidInput,
|
|
|
return Err(Error::new(ErrorKind::InvalidInput,
|
|
|
format!("Cannot write while wallet is unlocked while encrypted."))); |
|
|
format!("Cannot write while wallet is unlocked while encrypted."))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Write the version
|
|
|
// Write the version
|
|
|
out.write_u64::<LittleEndian>(LightWallet::serialized_version())?; |
|
|
writer.write_u64::<LittleEndian>(LightWallet::serialized_version())?; |
|
|
|
|
|
|
|
|
// Gzip encoder
|
|
|
|
|
|
let mut writer = AutoFinishUnchecked::new(Encoder::new(out).unwrap()); |
|
|
|
|
|
|
|
|
|
|
|
// Write if it is locked
|
|
|
// Write if it is locked
|
|
|
writer.write_u8(if self.encrypted {1} else {0})?; |
|
|
writer.write_u8(if self.encrypted {1} else {0})?; |
|
|