From 41839cd4316fec827df2d4715ab31aeee4e51c54 Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Fri, 31 May 2024 01:35:35 +0100 Subject: [PATCH] Prefer the `PoolType::{SAPLING, ORCHARD, TRANSPARENT}` constants to `PoolType::{Shielded(_), Transparent}`. Signed-off-by: Daira-Emma Hopwood --- .../zcash_address/src/kind/unified/address.rs | 8 ++++---- components/zcash_address/src/lib.rs | 6 +++--- .../src/data_api/wallet/input_selection.rs | 10 +++++----- zcash_client_backend/src/fees.rs | 8 ++++---- zcash_client_backend/src/proposal.rs | 6 +++--- zcash_client_backend/src/proto.rs | 8 ++++---- zcash_client_sqlite/src/lib.rs | 6 +++--- zcash_client_sqlite/src/testing/pool.rs | 7 ++----- zcash_client_sqlite/src/wallet/init.rs | 2 +- .../init/migrations/orchard_received_notes.rs | 14 +++++++------- .../src/wallet/init/migrations/ufvk_support.rs | 8 +++----- .../wallet/init/migrations/v_transactions_net.rs | 4 ++-- 12 files changed, 41 insertions(+), 46 deletions(-) diff --git a/components/zcash_address/src/kind/unified/address.rs b/components/zcash_address/src/kind/unified/address.rs index 00d3c5c540..8942b49720 100644 --- a/components/zcash_address/src/kind/unified/address.rs +++ b/components/zcash_address/src/kind/unified/address.rs @@ -1,4 +1,4 @@ -use zcash_protocol::{PoolType, ShieldedProtocol}; +use zcash_protocol::PoolType; use super::{private::SealedItem, ParseError, Typecode}; @@ -107,9 +107,9 @@ impl Address { /// Returns whether this address has the ability to receive transfers of the given pool type. pub fn has_receiver_of_type(&self, pool_type: PoolType) -> bool { self.0.iter().any(|r| match r { - Receiver::Orchard(_) => pool_type == PoolType::Shielded(ShieldedProtocol::Orchard), - Receiver::Sapling(_) => pool_type == PoolType::Shielded(ShieldedProtocol::Sapling), - Receiver::P2pkh(_) | Receiver::P2sh(_) => pool_type == PoolType::Transparent, + Receiver::Orchard(_) => pool_type == PoolType::ORCHARD, + Receiver::Sapling(_) => pool_type == PoolType::SAPLING, + Receiver::P2pkh(_) | Receiver::P2sh(_) => pool_type == PoolType::TRANSPARENT, Receiver::Unknown { .. } => false, }) } diff --git a/components/zcash_address/src/lib.rs b/components/zcash_address/src/lib.rs index e5db457290..32a3c05f4d 100644 --- a/components/zcash_address/src/lib.rs +++ b/components/zcash_address/src/lib.rs @@ -143,7 +143,7 @@ pub use encoding::ParseError; pub use kind::unified; use kind::unified::Receiver; pub use zcash_protocol::consensus::NetworkType as Network; -use zcash_protocol::{PoolType, ShieldedProtocol}; +use zcash_protocol::PoolType; /// A Zcash address. #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -274,9 +274,9 @@ impl ZcashAddress { use AddressKind::*; match &self.kind { Sprout(_) => false, - Sapling(_) => pool_type == PoolType::Shielded(ShieldedProtocol::Sapling), + Sapling(_) => pool_type == PoolType::SAPLING, Unified(addr) => addr.has_receiver_of_type(pool_type), - P2pkh(_) | P2sh(_) | Tex(_) => pool_type == PoolType::Transparent, + P2pkh(_) | P2sh(_) | Tex(_) => pool_type == PoolType::TRANSPARENT, } } diff --git a/zcash_client_backend/src/data_api/wallet/input_selection.rs b/zcash_client_backend/src/data_api/wallet/input_selection.rs index ebbeef66a4..ddcba7304a 100644 --- a/zcash_client_backend/src/data_api/wallet/input_selection.rs +++ b/zcash_client_backend/src/data_api/wallet/input_selection.rs @@ -367,32 +367,32 @@ where match recipient_address { Address::Transparent(addr) => { - payment_pools.insert(*idx, PoolType::Transparent); + payment_pools.insert(*idx, PoolType::TRANSPARENT); transparent_outputs.push(TxOut { value: payment.amount(), script_pubkey: addr.script(), }); } Address::Sapling(_) => { - payment_pools.insert(*idx, PoolType::Shielded(ShieldedProtocol::Sapling)); + payment_pools.insert(*idx, PoolType::SAPLING); sapling_outputs.push(SaplingPayment(payment.amount())); } Address::Unified(addr) => { #[cfg(feature = "orchard")] if addr.orchard().is_some() { - payment_pools.insert(*idx, PoolType::Shielded(ShieldedProtocol::Orchard)); + payment_pools.insert(*idx, PoolType::ORCHARD); orchard_outputs.push(OrchardPayment(payment.amount())); continue; } if addr.sapling().is_some() { - payment_pools.insert(*idx, PoolType::Shielded(ShieldedProtocol::Sapling)); + payment_pools.insert(*idx, PoolType::SAPLING); sapling_outputs.push(SaplingPayment(payment.amount())); continue; } if let Some(addr) = addr.transparent() { - payment_pools.insert(*idx, PoolType::Transparent); + payment_pools.insert(*idx, PoolType::TRANSPARENT); transparent_outputs.push(TxOut { value: payment.amount(), script_pubkey: addr.script(), diff --git a/zcash_client_backend/src/fees.rs b/zcash_client_backend/src/fees.rs index b3dd99756d..7959881f27 100644 --- a/zcash_client_backend/src/fees.rs +++ b/zcash_client_backend/src/fees.rs @@ -11,7 +11,7 @@ use zcash_primitives::{ fees::{transparent, FeeRule}, }, }; -use zcash_protocol::{PoolType, ShieldedProtocol}; +use zcash_protocol::PoolType; pub(crate) mod common; pub mod fixed; @@ -42,7 +42,7 @@ impl ChangeValue { /// Constructs a new change value that will be created as a transparent output. pub fn transparent(value: NonNegativeAmount) -> Self { Self { - output_pool: PoolType::Transparent, + output_pool: PoolType::TRANSPARENT, value, memo: None, } @@ -51,7 +51,7 @@ impl ChangeValue { /// Constructs a new change value that will be created as a Sapling output. pub fn sapling(value: NonNegativeAmount, memo: Option) -> Self { Self { - output_pool: PoolType::Shielded(ShieldedProtocol::Sapling), + output_pool: PoolType::SAPLING, value, memo, } @@ -61,7 +61,7 @@ impl ChangeValue { #[cfg(feature = "orchard")] pub fn orchard(value: NonNegativeAmount, memo: Option) -> Self { Self { - output_pool: PoolType::Shielded(ShieldedProtocol::Orchard), + output_pool: PoolType::ORCHARD, value, memo, } diff --git a/zcash_client_backend/src/proposal.rs b/zcash_client_backend/src/proposal.rs index a2cf00143b..3c0c01215a 100644 --- a/zcash_client_backend/src/proposal.rs +++ b/zcash_client_backend/src/proposal.rs @@ -186,7 +186,7 @@ impl Proposal { for t_out in step.transparent_inputs() { let key = ( - PoolType::Transparent, + PoolType::TRANSPARENT, TxId::from_bytes(*t_out.outpoint().hash()), t_out.outpoint().n(), ); @@ -198,9 +198,9 @@ impl Proposal { for s_out in step.shielded_inputs().iter().flat_map(|i| i.notes().iter()) { let key = ( match &s_out.note() { - Note::Sapling(_) => PoolType::Shielded(ShieldedProtocol::Sapling), + Note::Sapling(_) => PoolType::SAPLING, #[cfg(feature = "orchard")] - Note::Orchard(_) => PoolType::Shielded(ShieldedProtocol::Orchard), + Note::Orchard(_) => PoolType::ORCHARD, }, *s_out.txid(), s_out.output_index().into(), diff --git a/zcash_client_backend/src/proto.rs b/zcash_client_backend/src/proto.rs index 65d4c483cb..ea0e25df56 100644 --- a/zcash_client_backend/src/proto.rs +++ b/zcash_client_backend/src/proto.rs @@ -441,9 +441,9 @@ impl std::error::Error for ProposalDecodingError fn pool_type(pool_id: i32) -> Result> { match proposal::ValuePool::try_from(pool_id) { - Ok(proposal::ValuePool::Transparent) => Ok(PoolType::Transparent), - Ok(proposal::ValuePool::Sapling) => Ok(PoolType::Shielded(ShieldedProtocol::Sapling)), - Ok(proposal::ValuePool::Orchard) => Ok(PoolType::Shielded(ShieldedProtocol::Orchard)), + Ok(proposal::ValuePool::Transparent) => Ok(PoolType::TRANSPARENT), + Ok(proposal::ValuePool::Sapling) => Ok(PoolType::SAPLING), + Ok(proposal::ValuePool::Orchard) => Ok(PoolType::ORCHARD), _ => Err(ProposalDecodingError::ValuePoolNotSupported(pool_id)), } } @@ -675,7 +675,7 @@ impl proposal::Proposal { .ok_or({ ProposalDecodingError::InputNotFound( txid, - PoolType::Transparent, + PoolType::TRANSPARENT, out.index, ) })?, diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 733c35973a..d7bbb13166 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -1074,7 +1074,7 @@ impl WalletWrite for WalletDb receiver.to_zcash_address(wdb.params.network_type()) ); - Recipient::External(wallet_address, PoolType::Shielded(ShieldedProtocol::Sapling)) + Recipient::External(wallet_address, PoolType::SAPLING) }; wallet::put_sent_output( @@ -1155,7 +1155,7 @@ impl WalletWrite for WalletDb receiver.to_zcash_address(wdb.params.network_type()) ); - Recipient::External(wallet_address, PoolType::Shielded(ShieldedProtocol::Orchard)) + Recipient::External(wallet_address, PoolType::ORCHARD) }; wallet::put_sent_output( @@ -1277,7 +1277,7 @@ impl WalletWrite for WalletDb #[cfg(not(feature = "transparent-inputs"))] let recipient_addr = receiver.to_zcash_address(wdb.params.network_type()); - let recipient = Recipient::External(recipient_addr, PoolType::Transparent); + let recipient = Recipient::External(recipient_addr, PoolType::TRANSPARENT); wallet::put_sent_output( wdb.conn.0, diff --git a/zcash_client_sqlite/src/testing/pool.rs b/zcash_client_sqlite/src/testing/pool.rs index c32ad74dab..83ba9d5e1e 100644 --- a/zcash_client_sqlite/src/testing/pool.rs +++ b/zcash_client_sqlite/src/testing/pool.rs @@ -386,7 +386,7 @@ pub(crate) fn send_multi_step_proposed_transfer() { let step1 = Step::from_parts( &[step0.clone()], request1, - [(0, PoolType::Transparent)].into_iter().collect(), + [(0, PoolType::TRANSPARENT)].into_iter().collect(), vec![], None, vec![StepOutput::new(0, StepOutputIndex::Payment(0))], @@ -1665,10 +1665,7 @@ pub(crate) fn fully_funded_send_to_t( diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index 9fff7e3a3f..ab69c69c29 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -1458,7 +1458,7 @@ mod tests { wdb.conn.execute( "INSERT INTO sent_notes (tx, output_pool, output_index, from_account, address, value) VALUES (0, ?, 0, ?, ?, 0)", - [pool_code(PoolType::Transparent).to_sql()?, u32::from(account).to_sql()?, taddr.to_sql()?])?; + [pool_code(PoolType::TRANSPARENT).to_sql()?, u32::from(account).to_sql()?, taddr.to_sql()?])?; } Ok(()) diff --git a/zcash_client_sqlite/src/wallet/init/migrations/orchard_received_notes.rs b/zcash_client_sqlite/src/wallet/init/migrations/orchard_received_notes.rs index 550dc14f43..beb3825971 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/orchard_received_notes.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/orchard_received_notes.rs @@ -5,7 +5,7 @@ use std::collections::HashSet; use schemer_rusqlite::RusqliteMigration; use uuid::Uuid; -use zcash_client_backend::{PoolType, ShieldedProtocol}; +use zcash_client_backend::PoolType; use super::full_account_ids; use crate::wallet::{init::WalletMigrationError, pool_code}; @@ -72,8 +72,8 @@ impl RusqliteMigration for Migration { )?; transaction.execute_batch({ - let sapling_pool_code = pool_code(PoolType::Shielded(ShieldedProtocol::Sapling)); - let orchard_pool_code = pool_code(PoolType::Shielded(ShieldedProtocol::Orchard)); + let sapling_pool_code = pool_code(PoolType::SAPLING); + let orchard_pool_code = pool_code(PoolType::ORCHARD); &format!( "CREATE VIEW v_received_notes AS SELECT @@ -109,8 +109,8 @@ impl RusqliteMigration for Migration { })?; transaction.execute_batch({ - let sapling_pool_code = pool_code(PoolType::Shielded(ShieldedProtocol::Sapling)); - let orchard_pool_code = pool_code(PoolType::Shielded(ShieldedProtocol::Orchard)); + let sapling_pool_code = pool_code(PoolType::SAPLING); + let orchard_pool_code = pool_code(PoolType::ORCHARD); &format!( "CREATE VIEW v_received_note_spends AS SELECT @@ -128,7 +128,7 @@ impl RusqliteMigration for Migration { })?; transaction.execute_batch({ - let transparent_pool_code = pool_code(PoolType::Transparent); + let transparent_pool_code = pool_code(PoolType::TRANSPARENT); &format!( "DROP VIEW v_transactions; CREATE VIEW v_transactions AS @@ -257,7 +257,7 @@ impl RusqliteMigration for Migration { })?; transaction.execute_batch({ - let transparent_pool_code = pool_code(PoolType::Transparent); + let transparent_pool_code = pool_code(PoolType::TRANSPARENT); &format!( "DROP VIEW v_tx_outputs; CREATE VIEW v_tx_outputs AS diff --git a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs index b4af042352..b014b8f9ab 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs @@ -8,7 +8,7 @@ use secrecy::{ExposeSecret, SecretVec}; use uuid::Uuid; use zcash_client_backend::{ - address::Address, keys::UnifiedSpendingKey, PoolType, ShieldedProtocol, + address::Address, keys::UnifiedSpendingKey, PoolType, }; use zcash_keys::keys::UnifiedAddressRequest; use zcash_primitives::{consensus, zip32::AccountId}; @@ -262,10 +262,8 @@ impl RusqliteMigration for Migration

{ )) })?; let output_pool = match decoded_address { - Address::Sapling(_) => { - Ok(pool_code(PoolType::Shielded(ShieldedProtocol::Sapling))) - } - Address::Transparent(_) => Ok(pool_code(PoolType::Transparent)), + Address::Sapling(_) => Ok(pool_code(PoolType::SAPLING)), + Address::Transparent(_) => Ok(pool_code(PoolType::TRANSPARENT)), Address::Unified(_) => Err(WalletMigrationError::CorruptedData( "Unified addresses should not yet appear in the sent_notes table." .to_string(), diff --git a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs index c94d08a677..8b4aa6d198 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs @@ -6,7 +6,7 @@ use rusqlite::{self, named_params}; use schemer; use schemer_rusqlite::RusqliteMigration; use uuid::Uuid; -use zcash_client_backend::{PoolType, ShieldedProtocol}; +use zcash_client_backend::PoolType; use super::add_transaction_views; use crate::wallet::{init::WalletMigrationError, pool_code}; @@ -44,7 +44,7 @@ impl RusqliteMigration for Migration { SELECT tx, :output_pool, output_index, from_account, from_account, value FROM sent_notes", named_params![ - ":output_pool": &pool_code(PoolType::Shielded(ShieldedProtocol::Sapling)) + ":output_pool": &pool_code(PoolType::SAPLING) ] )?;