Skip to content

Commit

Permalink
cargo clippy + cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
pacu committed Oct 22, 2024
1 parent 295be99 commit 1bd9369
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
15 changes: 9 additions & 6 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ impl AccountBalance {
};

fn check_total(&self) -> Result<NonNegativeAmount, BalanceError> {
(self.sapling_balance.total() + self.orchard_balance.total() + self.unshielded_balance.total())
.ok_or(BalanceError::Overflow)
(self.sapling_balance.total()
+ self.orchard_balance.total()
+ self.unshielded_balance.total())
.ok_or(BalanceError::Overflow)
}

/// Returns the [`Balance`] of Sapling funds in the account.
Expand Down Expand Up @@ -282,7 +284,6 @@ impl AccountBalance {
Ok(result)
}


/// Returns the total value of unspent transparent transaction outputs belonging to the wallet.
#[deprecated(
note = "this function is deprecated. Please use AccountBalance::unshielded_balance instead."
Expand Down Expand Up @@ -313,15 +314,17 @@ impl AccountBalance {
#[deprecated(
note = "this function is deprecated. Please use the `Balance::add_spendable_value` on the unshielded field instead instead."
)]
pub fn add_unshielded_value(&mut self, value: NonNegativeAmount) -> Result<(), BalanceError> {
pub fn add_unshielded_value(&mut self, value: NonNegativeAmount) -> Result<(), BalanceError> {
self.unshielded_balance.add_pending_spendable_value(value)?;
Ok(())
}

/// Returns the total value of funds belonging to the account.
pub fn total(&self) -> NonNegativeAmount {
(self.sapling_balance.total() + self.orchard_balance.total() + self.unshielded_balance.total())
.expect("Account balance cannot overflow MAX_MONEY")
(self.sapling_balance.total()
+ self.orchard_balance.total()
+ self.unshielded_balance.total())
.expect("Account balance cannot overflow MAX_MONEY")
}

/// Returns the total value of shielded (Sapling and Orchard) funds that may immediately be
Expand Down
7 changes: 6 additions & 1 deletion zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,12 @@ pub(crate) fn get_wallet_summary<P: consensus::Parameters>(
drop(sapling_trace);

#[cfg(feature = "transparent-inputs")]
transparent::add_transparent_account_balances(tx, chain_tip_height + 1, min_confirmations, &mut account_balances)?;
transparent::add_transparent_account_balances(
tx,
chain_tip_height + 1,
min_confirmations,
&mut account_balances,
)?;

// The approach used here for Sapling and Orchard subtree indexing was a quick hack
// that has not yet been replaced. TODO: Make less hacky.
Expand Down
21 changes: 8 additions & 13 deletions zcash_client_sqlite/src/wallet/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ pub(crate) fn add_transparent_account_balances(
min_confirmations: u32,
account_balances: &mut HashMap<AccountId, AccountBalance>,
) -> Result<(), SqliteClientError> {

let mut stmt_account_spendable_balances = conn.prepare(
"SELECT u.account_id, SUM(u.value_zat)
FROM transparent_received_outputs u
Expand All @@ -409,11 +408,10 @@ pub(crate) fn add_transparent_account_balances(
)
GROUP BY u.account_id",
)?;
let mut rows = stmt_account_spendable_balances
.query(named_params![
":mempool_height": u32::from(mempool_height),
":min_confirmations": min_confirmations,
])?;
let mut rows = stmt_account_spendable_balances.query(named_params![
":mempool_height": u32::from(mempool_height),
":min_confirmations": min_confirmations,
])?;

while let Some(row) = rows.next()? {
let account = AccountId(row.get(0)?);
Expand All @@ -422,7 +420,6 @@ pub(crate) fn add_transparent_account_balances(
SqliteClientError::CorruptedData(format!("Negative UTXO value {:?}", raw_value))
})?;


account_balances
.entry(account)
.or_insert(AccountBalance::ZERO)
Expand Down Expand Up @@ -457,11 +454,10 @@ pub(crate) fn add_transparent_account_balances(
GROUP BY u.account_id",
)?;

let mut rows = stmt_account_unconfirmed_balances
.query(named_params![
":mempool_height": u32::from(mempool_height),
":min_confirmations": min_confirmations,
])?;
let mut rows = stmt_account_unconfirmed_balances.query(named_params![
":mempool_height": u32::from(mempool_height),
":min_confirmations": min_confirmations,
])?;

while let Some(row) = rows.next()? {
let account = AccountId(row.get(0)?);
Expand All @@ -470,7 +466,6 @@ pub(crate) fn add_transparent_account_balances(
SqliteClientError::CorruptedData(format!("Negative UTXO value {:?}", raw_value))
})?;


account_balances
.entry(account)
.or_insert(AccountBalance::ZERO)
Expand Down

0 comments on commit 1bd9369

Please sign in to comment.