Separate t / z balance

This commit is contained in:
Aditya Kulkarni 2019-09-16 13:57:37 -07:00
parent 7fe784289f
commit b24f174b5e
2 changed files with 19 additions and 12 deletions

View File

@ -95,8 +95,8 @@ impl LightClient {
let address = encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad); let address = encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad);
object!{ object!{
"address" => address.clone(), "address" => address.clone(),
"balance" => self.wallet.balance(Some(address.clone())), "zbalance" => self.wallet.zbalance(Some(address.clone())),
"verified_balance" => self.wallet.verified_balance(Some(address)), "verified_zbalance" => self.wallet.verified_zbalance(Some(address)),
} }
}).collect::<Vec<JsonValue>>(); }).collect::<Vec<JsonValue>>();
@ -114,10 +114,11 @@ impl LightClient {
}).collect::<Vec<JsonValue>>(); }).collect::<Vec<JsonValue>>();
object!{ object!{
"balance" => self.wallet.balance(None), "zbalance" => self.wallet.zbalance(None),
"verified_balance" => self.wallet.verified_balance(None), "verified_zbalance" => self.wallet.verified_zbalance(None),
"z_addresses" => z_addresses, "tbalance" => self.wallet.tbalance(None),
"t_addresses" => t_addresses, "z_addresses" => z_addresses,
"t_addresses" => t_addresses,
} }
} }

View File

@ -580,8 +580,9 @@ impl LightWallet {
Language::English).unwrap().entropy()); Language::English).unwrap().entropy());
} }
// TODO: Generate transparent addresses from the seed // TODO: HD-derive the address instead straight from the seed.
let tpk = secp256k1::SecretKey::from_slice(&[1u8; 32]).unwrap(); // TODO: This only reads one key for now
let tpk = secp256k1::SecretKey::from_slice(&seed_bytes).unwrap();
// Derive only the first address // Derive only the first address
// TODO: We need to monitor addresses, and always keep 1 "free" address, so // 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 ) let addresses = extfvks.iter().map( |fvk| fvk.default_address().unwrap().1 )
.collect::<Vec<PaymentAddress<Bls12>>>(); .collect::<Vec<PaymentAddress<Bls12>>>();
// TODO: Generate transparent addresses from the seed let mut tpk_bytes = [0u8; 32];
let tpk = secp256k1::SecretKey::from_slice(&[1u8; 32]).unwrap(); 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))?; let utxos = Vector::read(&mut reader, |r| Utxo::read(r))?;
@ -658,6 +660,10 @@ impl LightWallet {
|w, sk| sk.write(w) |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.utxos.read().unwrap(), |w, u| u.write(w))?;
Vector::write(&mut writer, &self.blocks.read().unwrap(), |w, b| b.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() ).unwrap().phrase().to_string()
} }
pub fn balance(&self, addr: Option<String>) -> u64 { pub fn zbalance(&self, addr: Option<String>) -> u64 {
self.txs.read().unwrap() self.txs.read().unwrap()
.values() .values()
.map(|tx| { .map(|tx| {
@ -813,7 +819,7 @@ impl LightWallet {
.sum::<u64>() .sum::<u64>()
} }
pub fn verified_balance(&self, addr: Option<String>) -> u64 { pub fn verified_zbalance(&self, addr: Option<String>) -> u64 {
let anchor_height = match self.get_target_height_and_anchor_offset() { let anchor_height = match self.get_target_height_and_anchor_offset() {
Some((height, anchor_offset)) => height - anchor_offset as u32, Some((height, anchor_offset)) => height - anchor_offset as u32,
None => return 0, None => return 0,