Skip to content

Commit

Permalink
Merge pull request #895 from fluidvanadium/deprecate_extra_balance_fu…
Browse files Browse the repository at this point in the history
…nctions

Deprecate extra balance functions
  • Loading branch information
AloeareV authored Apr 5, 2024
2 parents bf4953c + 914749e commit ccb1bcf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
6 changes: 5 additions & 1 deletion integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ mod fast {
}
}
mod slow {
use orchard::note_encryption::OrchardDomain;
use zcash_primitives::consensus::NetworkConstants;

use super::*;
Expand Down Expand Up @@ -1359,7 +1360,10 @@ mod slow {
Some(expected_funds)
);
assert_eq!(
recipient.wallet.verified_orchard_balance(None).await,
recipient
.wallet
.verified_balance::<OrchardDomain>(None)
.await,
Some(0)
);

Expand Down
22 changes: 16 additions & 6 deletions zingolib/src/lightclient/describe.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// These functions can be called by consumer to learn about the LightClient.
use json::{object, JsonValue};
use orchard::note_encryption::OrchardDomain;
use sapling_crypto::note_encryption::SaplingDomain;
use std::collections::HashMap;
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -50,14 +52,22 @@ impl LightClient {

pub async fn do_balance(&self) -> PoolBalances {
PoolBalances {
sapling_balance: self.wallet.maybe_verified_sapling_balance(None).await,
verified_sapling_balance: self.wallet.verified_sapling_balance(None).await,
sapling_balance: self
.wallet
.shielded_balance::<SaplingDomain>(None, &[])
.await,
verified_sapling_balance: self.wallet.verified_balance::<SaplingDomain>(None).await,
spendable_sapling_balance: self.wallet.spendable_sapling_balance(None).await,
unverified_sapling_balance: self.wallet.unverified_sapling_balance(None).await,
orchard_balance: self.wallet.maybe_verified_orchard_balance(None).await,
verified_orchard_balance: self.wallet.verified_orchard_balance(None).await,
unverified_sapling_balance: self.wallet.unverified_balance::<SaplingDomain>(None).await,

orchard_balance: self
.wallet
.shielded_balance::<OrchardDomain>(None, &[])
.await,
verified_orchard_balance: self.wallet.verified_balance::<OrchardDomain>(None).await,
spendable_orchard_balance: self.wallet.spendable_orchard_balance(None).await,
unverified_orchard_balance: self.wallet.unverified_orchard_balance(None).await,
unverified_orchard_balance: self.wallet.unverified_balance::<OrchardDomain>(None).await,

transparent_balance: self.wallet.tbalance(None).await,
}
}
Expand Down
27 changes: 6 additions & 21 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ impl LightWallet {
}

#[allow(clippy::type_complexity)]
async fn shielded_balance<D>(
pub async fn shielded_balance<D>(
&self,
target_addr: Option<String>,
filters: &[Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool + '_>],
Expand Down Expand Up @@ -936,7 +936,7 @@ impl LightWallet {
self.transaction_context.transaction_metadata_set.clone()
}

async fn unverified_balance<D: DomainWalletExt>(
pub async fn unverified_balance<D: DomainWalletExt>(
&self,
target_addr: Option<String>,
) -> Option<u64>
Expand All @@ -956,17 +956,10 @@ impl LightWallet {
self.shielded_balance::<D>(target_addr, filters).await
}

pub async fn unverified_orchard_balance(&self, target_addr: Option<String>) -> Option<u64> {
self.unverified_balance::<OrchardDomain>(target_addr).await
}

/// The following functions use a filter/map functional approach to
/// expressively unpack different kinds of transaction data.
pub async fn unverified_sapling_balance(&self, target_addr: Option<String>) -> Option<u64> {
self.unverified_balance::<SaplingDomain>(target_addr).await
}

async fn verified_balance<D: DomainWalletExt>(&self, target_addr: Option<String>) -> Option<u64>
pub async fn verified_balance<D: DomainWalletExt>(
&self,
target_addr: Option<String>,
) -> Option<u64>
where
<D as Domain>::Recipient: Recipient,
<D as Domain>::Note: PartialEq + Clone,
Expand All @@ -984,14 +977,6 @@ impl LightWallet {
self.shielded_balance::<D>(target_addr, filters).await
}

pub async fn verified_orchard_balance(&self, target_addr: Option<String>) -> Option<u64> {
self.verified_balance::<OrchardDomain>(target_addr).await
}

pub async fn verified_sapling_balance(&self, target_addr: Option<String>) -> Option<u64> {
self.verified_balance::<SaplingDomain>(target_addr).await
}

pub fn wallet_capability(&self) -> Arc<WalletCapability> {
self.transaction_context.key.clone()
}
Expand Down

0 comments on commit ccb1bcf

Please sign in to comment.