Skip to content

Commit

Permalink
Merge pull request zingolabs#984 from fluidvanadium/wallet_read
Browse files Browse the repository at this point in the history
Wallet read for TxMapAndMaybeTrees Complete
  • Loading branch information
zancas authored Apr 25, 2024
2 parents 98d8a98 + fd16136 commit 8cf1d49
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions zingolib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ zingo-netutils = { path = "../zingo-netutils" }

http-body = { workspace = true }
hyper = { workspace = true }
hyper-rustls = { workspace = true }
prost = { workspace = true }
tonic = { workspace = true }
tower = { workspace = true }
prost = { workspace = true }

orchard = { workspace = true }
shardtree = { workspace = true, features = ["legacy-api"] }
incrementalmerkletree = { workspace = true, features = ["test-dependencies", "legacy-api"] }
zcash_address = { workspace = true }
zcash_client_backend = { workspace = true, features = ["unstable", "transparent-inputs", "unstable-serialization", "unstable-spanning-tree"] }
zcash_encoding = { workspace = true }
zcash_keys = { workspace = true }
zcash_note_encryption = { workspace = true }
zcash_primitives = { workspace = true }
zcash_proofs = { workspace = true }
hyper-rustls = { workspace = true }
zip32.workspace = true

append-only-vec = { git = "https://github.com/zancas/append-only-vec.git", branch = "add_debug_impl" }
Expand Down Expand Up @@ -80,8 +82,10 @@ derive_more = "0.99.17"
either = "1.8.1"
serde = { version = "1.0.188", features = ["derive"] }
sapling-crypto.workspace = true
secrecy = "0.8.0"
getset = "0.1.2"
test-case = "3.3.1"
proptest = "1.4.0"

[dev-dependencies]
portpicker = "0.1.0"
Expand Down
41 changes: 21 additions & 20 deletions zingolib/src/wallet/transaction_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ impl TransactionRecord {
sum
}

/// Sums all the received notes in the transaction.
pub fn total_value_received(&self) -> u64 {
self.query_sum_value(OutputQuery::stipulations(
true, true, true, true, true, true,
))
}

/// TODO: Add Doc Comment Here!
pub fn pool_value_received<D: DomainWalletExt>(&self) -> u64
where
<D as zcash_note_encryption::Domain>::Note: PartialEq + Clone,
<D as zcash_note_encryption::Domain>::Recipient: super::traits::Recipient,
{
D::to_notes_vec(self)
.iter()
.map(|note_and_metadata| note_and_metadata.value())
.sum()
}

/// TODO: Add Doc Comment Here!
pub fn get_transparent_value_spent(&self) -> u64 {
self.total_transparent_value_spent
Expand Down Expand Up @@ -237,31 +256,12 @@ impl TransactionRecord {
D::sum_pool_change(self)
}

/// TODO: Add Doc Comment Here!
pub fn pool_value_received<D: DomainWalletExt>(&self) -> u64
where
<D as zcash_note_encryption::Domain>::Note: PartialEq + Clone,
<D as zcash_note_encryption::Domain>::Recipient: super::traits::Recipient,
{
D::to_notes_vec(self)
.iter()
.map(|note_and_metadata| note_and_metadata.value())
.sum()
}

/// TODO: Add Doc Comment Here!
pub fn total_change_returned(&self) -> u64 {
self.pool_change_returned::<sapling_crypto::note_encryption::SaplingDomain>()
+ self.pool_change_returned::<orchard::note_encryption::OrchardDomain>()
}

/// Sums all the received notes in the transaction.
pub fn total_value_received(&self) -> u64 {
self.query_sum_value(OutputQuery::stipulations(
true, true, true, true, true, true,
))
}

/// TODO: Add Doc Comment Here!
pub fn total_value_spent(&self) -> u64 {
self.value_spent_by_pool().iter().sum()
Expand Down Expand Up @@ -334,7 +334,9 @@ impl TransactionRecord {
} else {
vec![]
};

let utxos = zcash_encoding::Vector::read(&mut reader, |r| TransparentOutput::read(r))?;

let total_sapling_value_spent = reader.read_u64::<LittleEndian>()?;
let total_transparent_value_spent = reader.read_u64::<LittleEndian>()?;
let total_orchard_value_spent = if version >= 22 {
Expand Down Expand Up @@ -573,7 +575,6 @@ mod tests {
use test_case::test_matrix;

use crate::wallet::notes::query::OutputQuery;

use crate::wallet::notes::transparent::mocks::TransparentOutputBuilder;
use crate::wallet::transaction_record::mocks::{
nine_note_transaction_record, TransactionRecordBuilder,
Expand Down
2 changes: 2 additions & 0 deletions zingolib/src/wallet/tx_map_and_maybe_trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ impl TxMapAndMaybeTrees {
self.witness_trees.as_mut().map(WitnessTrees::clear);
}
}

pub mod trait_walletread;
Loading

0 comments on commit 8cf1d49

Please sign in to comment.