From 1bd9369db5419a0f791508b96cbcc27d1816ca7c Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Sun, 13 Oct 2024 21:20:17 -0300 Subject: [PATCH] cargo clippy + cargo fmt --- zcash_client_backend/src/data_api.rs | 15 +++++++------ zcash_client_sqlite/src/wallet.rs | 7 ++++++- zcash_client_sqlite/src/wallet/transparent.rs | 21 +++++++------------ 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index 53376a198..b7b7da26b 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -244,8 +244,10 @@ impl AccountBalance { }; fn check_total(&self) -> Result { - (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. @@ -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." @@ -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 diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index db8fee685..fbb992f36 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1530,7 +1530,12 @@ pub(crate) fn get_wallet_summary( 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. diff --git a/zcash_client_sqlite/src/wallet/transparent.rs b/zcash_client_sqlite/src/wallet/transparent.rs index 589321097..a7f310c9d 100644 --- a/zcash_client_sqlite/src/wallet/transparent.rs +++ b/zcash_client_sqlite/src/wallet/transparent.rs @@ -386,7 +386,6 @@ pub(crate) fn add_transparent_account_balances( min_confirmations: u32, account_balances: &mut HashMap, ) -> Result<(), SqliteClientError> { - let mut stmt_account_spendable_balances = conn.prepare( "SELECT u.account_id, SUM(u.value_zat) FROM transparent_received_outputs u @@ -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)?); @@ -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) @@ -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)?); @@ -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)