mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-12 02:05:47 +00:00
Add taddr balances
This commit is contained in:
parent
ff51a50bfd
commit
3f75371500
@ -96,8 +96,14 @@ impl LightClient {
|
|||||||
|
|
||||||
// Collect t addresses
|
// Collect t addresses
|
||||||
let t_addresses = self.wallet.tkeys.iter().map( |pk| {
|
let t_addresses = self.wallet.tkeys.iter().map( |pk| {
|
||||||
|
let address = LightWallet::address_from_pk(&pk);
|
||||||
|
|
||||||
|
// Get the balance for this address
|
||||||
|
let balance = self.wallet.tbalance(Some(address.clone()));
|
||||||
|
|
||||||
object!{
|
object!{
|
||||||
"address" => LightWallet::address_from_pk(&pk),
|
"address" => address,
|
||||||
|
"balance" => balance,
|
||||||
}
|
}
|
||||||
}).collect::<Vec<JsonValue>>();
|
}).collect::<Vec<JsonValue>>();
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ use zcash_primitives::{
|
|||||||
serialize::{Vector, Optional},
|
serialize::{Vector, Optional},
|
||||||
transaction::{
|
transaction::{
|
||||||
builder::{Builder},
|
builder::{Builder},
|
||||||
components::Amount, components::amount::DEFAULT_FEE,
|
components::{Amount, OutPoint}, components::amount::DEFAULT_FEE,
|
||||||
TxId, Transaction
|
TxId, Transaction,
|
||||||
},
|
},
|
||||||
legacy::{TransparentAddress::PublicKey},
|
legacy::{TransparentAddress::PublicKey},
|
||||||
note_encryption::{Memo, try_sapling_note_decryption},
|
note_encryption::{Memo, try_sapling_note_decryption},
|
||||||
@ -338,6 +338,12 @@ pub struct Utxo {
|
|||||||
pub unconfirmed_spent: Option<TxId>, // If this utxo was spent in a send, but has not yet been confirmed.
|
pub unconfirmed_spent: Option<TxId>, // If this utxo was spent in a send, but has not yet been confirmed.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<OutPoint> for Utxo {
|
||||||
|
fn into(self) -> OutPoint {
|
||||||
|
OutPoint { hash: self.txid.0, n: self.output_index as u32 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct WalletTx {
|
pub struct WalletTx {
|
||||||
pub block: i32,
|
pub block: i32,
|
||||||
|
|
||||||
@ -654,13 +660,10 @@ impl LightWallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn balance(&self, addr: Option<String>) -> u64 {
|
pub fn balance(&self, addr: Option<String>) -> u64 {
|
||||||
self.txs
|
self.txs.read().unwrap()
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.values()
|
.values()
|
||||||
.map(|tx| {
|
.map(|tx| {
|
||||||
tx.notes
|
tx.notes.iter()
|
||||||
.iter()
|
|
||||||
.filter(|nd| { // TODO, this whole section is shared with verified_balance. Refactor it.
|
.filter(|nd| { // TODO, this whole section is shared with verified_balance. Refactor it.
|
||||||
match addr.clone() {
|
match addr.clone() {
|
||||||
Some(a) => a == encode_payment_address(
|
Some(a) => a == encode_payment_address(
|
||||||
@ -677,6 +680,23 @@ impl LightWallet {
|
|||||||
.sum::<u64>()
|
.sum::<u64>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tbalance(&self, addr: Option<String>) -> u64 {
|
||||||
|
self.txs.read().unwrap()
|
||||||
|
.values()
|
||||||
|
.map( |tx| {
|
||||||
|
tx.utxos.iter()
|
||||||
|
.filter( |utxo| {
|
||||||
|
match addr.clone() {
|
||||||
|
Some(a) => a == utxo.address,
|
||||||
|
None => true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map (|utxo| if utxo.spent.is_none() {utxo.value} else {0})
|
||||||
|
.sum::<u64>()
|
||||||
|
})
|
||||||
|
.sum::<u64>()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn verified_balance(&self, addr: Option<String>) -> u64 {
|
pub fn verified_balance(&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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user