merged conflicts manually
This commit is contained in:
@@ -231,6 +231,16 @@ impl Command for EncryptCommand {
|
||||
return self.help();
|
||||
}
|
||||
|
||||
// Refuse to encrypt if the bip39 bug has not been fixed
|
||||
use crate::lightwallet::bugs::BugBip39Derivation;
|
||||
if BugBip39Derivation::has_bug(lightclient) {
|
||||
let mut h = vec![];
|
||||
h.push("It looks like your wallet has the bip39bug. Please run 'fixbip39bug' to fix it");
|
||||
h.push("before encrypting your wallet.");
|
||||
h.push("ERROR: Cannot encrypt while wallet has the bip39bug.");
|
||||
return h.join("\n");
|
||||
}
|
||||
|
||||
let passwd = args[0].to_string();
|
||||
|
||||
match lightclient.wallet.write().unwrap().encrypt(passwd) {
|
||||
|
||||
@@ -244,8 +244,32 @@ impl LightClient {
|
||||
Ok(l)
|
||||
}
|
||||
|
||||
/// Create a brand new wallet with a new seed phrase. Will fail if a wallet file
|
||||
/// already exists on disk
|
||||
pub fn new(config: &LightClientConfig, latest_block: u64) -> io::Result<Self> {
|
||||
if config.wallet_exists() {
|
||||
return Err(Error::new(ErrorKind::AlreadyExists,
|
||||
"Cannot create a new wallet from seed, because a wallet already exists"));
|
||||
}
|
||||
|
||||
let mut l = LightClient {
|
||||
wallet : Arc::new(RwLock::new(LightWallet::new(None, config, latest_block)?)),
|
||||
config : config.clone(),
|
||||
sapling_output : vec![],
|
||||
sapling_spend : vec![]
|
||||
};
|
||||
|
||||
l.set_wallet_initial_state();
|
||||
l.read_sapling_params();
|
||||
|
||||
info!("Created new wallet with a new seed!");
|
||||
info!("Created LightClient to {}", &config.server);
|
||||
|
||||
Ok(l)
|
||||
}
|
||||
|
||||
pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, latest_block: u64) -> io::Result<Self> {
|
||||
if config.get_wallet_path().exists() {
|
||||
if config.wallet_exists() {
|
||||
return Err(Error::new(ErrorKind::AlreadyExists,
|
||||
"Cannot create a new wallet from seed, because a wallet already exists"));
|
||||
}
|
||||
@@ -267,7 +291,7 @@ impl LightClient {
|
||||
}
|
||||
|
||||
pub fn read_from_disk(config: &LightClientConfig) -> io::Result<Self> {
|
||||
if !config.get_wallet_path().exists() {
|
||||
if !config.wallet_exists() {
|
||||
return Err(Error::new(ErrorKind::AlreadyExists,
|
||||
format!("Cannot read wallet. No file at {}", config.get_wallet_path().display())));
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ use zcash_primitives::{
|
||||
primitives::{PaymentAddress},
|
||||
};
|
||||
|
||||
|
||||
use crate::lightclient::{LightClientConfig};
|
||||
|
||||
mod data;
|
||||
@@ -58,7 +57,6 @@ fn now() -> f64 {
|
||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as f64
|
||||
}
|
||||
|
||||
|
||||
/// Sha256(Sha256(value))
|
||||
pub fn double_sha256(payload: &[u8]) -> Vec<u8> {
|
||||
let h1 = Sha256::digest(&payload);
|
||||
|
||||
@@ -28,6 +28,10 @@ impl BugBip39Derivation {
|
||||
return false;
|
||||
}
|
||||
|
||||
if wallet.is_encrypted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The seed bytes is the raw entropy. To pass it to HD wallet generation,
|
||||
// we need to get the 64 byte bip39 entropy
|
||||
let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&wallet.seed, Language::English).unwrap(), "");
|
||||
@@ -73,13 +77,12 @@ impl BugBip39Derivation {
|
||||
println!("Sending funds to ourself.");
|
||||
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;
|
||||
+ balance_json["tbalance"].as_u64().unwrap();
|
||||
|
||||
let txid = if amount > 0 {
|
||||
match client.do_send(vec![(&zaddr, amount, None)]) {
|
||||
let fee: u64 = DEFAULT_FEE.try_into().unwrap();
|
||||
match client.do_send(vec![(&zaddr, amount-fee, None)]) {
|
||||
Ok(txid) => txid,
|
||||
Err(e) => {
|
||||
let r = object!{
|
||||
|
||||
Reference in New Issue
Block a user