From b24f174b5e9d2adb7ed6db81441e1e943b6a0f5b Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Mon, 16 Sep 2019 13:57:37 -0700 Subject: [PATCH] Separate t / z balance --- rust-lightclient/src/lightclient.rs | 13 +++++++------ rust-lightclient/src/lightwallet.rs | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/rust-lightclient/src/lightclient.rs b/rust-lightclient/src/lightclient.rs index c32c719..c066935 100644 --- a/rust-lightclient/src/lightclient.rs +++ b/rust-lightclient/src/lightclient.rs @@ -95,8 +95,8 @@ impl LightClient { let address = encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad); object!{ "address" => address.clone(), - "balance" => self.wallet.balance(Some(address.clone())), - "verified_balance" => self.wallet.verified_balance(Some(address)), + "zbalance" => self.wallet.zbalance(Some(address.clone())), + "verified_zbalance" => self.wallet.verified_zbalance(Some(address)), } }).collect::>(); @@ -114,10 +114,11 @@ impl LightClient { }).collect::>(); object!{ - "balance" => self.wallet.balance(None), - "verified_balance" => self.wallet.verified_balance(None), - "z_addresses" => z_addresses, - "t_addresses" => t_addresses, + "zbalance" => self.wallet.zbalance(None), + "verified_zbalance" => self.wallet.verified_zbalance(None), + "tbalance" => self.wallet.tbalance(None), + "z_addresses" => z_addresses, + "t_addresses" => t_addresses, } } diff --git a/rust-lightclient/src/lightwallet.rs b/rust-lightclient/src/lightwallet.rs index 559b78d..62e09ed 100644 --- a/rust-lightclient/src/lightwallet.rs +++ b/rust-lightclient/src/lightwallet.rs @@ -580,8 +580,9 @@ impl LightWallet { Language::English).unwrap().entropy()); } - // TODO: Generate transparent addresses from the seed - let tpk = secp256k1::SecretKey::from_slice(&[1u8; 32]).unwrap(); + // TODO: HD-derive the address instead straight from the seed. + // TODO: This only reads one key for now + let tpk = secp256k1::SecretKey::from_slice(&seed_bytes).unwrap(); // Derive only the first address // TODO: We need to monitor addresses, and always keep 1 "free" address, so @@ -619,8 +620,9 @@ impl LightWallet { let addresses = extfvks.iter().map( |fvk| fvk.default_address().unwrap().1 ) .collect::>>(); - // TODO: Generate transparent addresses from the seed - let tpk = secp256k1::SecretKey::from_slice(&[1u8; 32]).unwrap(); + let mut tpk_bytes = [0u8; 32]; + reader.read_exact(&mut tpk_bytes)?; + let tpk = secp256k1::SecretKey::from_slice(&tpk_bytes).unwrap(); let utxos = Vector::read(&mut reader, |r| Utxo::read(r))?; @@ -658,6 +660,10 @@ impl LightWallet { |w, sk| sk.write(w) )?; + // Write the transparent private key + // TODO: This only writes the first key for now + writer.write_all(&self.tkeys[0][..])?; + Vector::write(&mut writer, &self.utxos.read().unwrap(), |w, u| u.write(w))?; Vector::write(&mut writer, &self.blocks.read().unwrap(), |w, b| b.write(w))?; @@ -780,7 +786,7 @@ impl LightWallet { ).unwrap().phrase().to_string() } - pub fn balance(&self, addr: Option) -> u64 { + pub fn zbalance(&self, addr: Option) -> u64 { self.txs.read().unwrap() .values() .map(|tx| { @@ -813,7 +819,7 @@ impl LightWallet { .sum::() } - pub fn verified_balance(&self, addr: Option) -> u64 { + pub fn verified_zbalance(&self, addr: Option) -> u64 { let anchor_height = match self.get_target_height_and_anchor_offset() { Some((height, anchor_offset)) => height - anchor_offset as u32, None => return 0,