From 6c90219817b9d14093d932a6f2c40555b607eb45 Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Sun, 16 Jun 2024 19:00:01 +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 +++--- zcash_client_backend/src/data_api/wallet.rs | 14 ++++---------- .../src/data_api/wallet/input_selection.rs | 10 +++++----- zcash_client_backend/src/fees.rs | 2 +- zcash_client_backend/src/proposal.rs | 6 +++--- zcash_client_backend/src/proto.rs | 8 ++++---- zcash_client_sqlite/src/lib.rs | 10 ++++------ zcash_client_sqlite/src/testing/pool.rs | 7 ++----- zcash_client_sqlite/src/wallet.rs | 4 +--- zcash_client_sqlite/src/wallet/init.rs | 2 +- .../init/migrations/orchard_received_notes.rs | 14 +++++++------- .../src/wallet/init/migrations/ufvk_support.rs | 10 +++------- .../wallet/init/migrations/v_transactions_net.rs | 4 ++-- 14 files changed, 44 insertions(+), 61 deletions(-) diff --git a/components/zcash_address/src/kind/unified/address.rs b/components/zcash_address/src/kind/unified/address.rs index 00d3c5c54..8942b4972 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 e5db45729..32a3c05f4 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.rs b/zcash_client_backend/src/data_api/wallet.rs index e0e6918f0..3921b6a6e 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -980,10 +980,7 @@ where memo.clone(), )?; orchard_output_meta.push(( - Recipient::External( - payment.recipient_address().clone(), - PoolType::Shielded(ShieldedProtocol::Orchard), - ), + Recipient::External(payment.recipient_address().clone(), *output_pool), payment.amount(), Some(memo), )); @@ -997,10 +994,7 @@ where memo.clone(), )?; sapling_output_meta.push(( - Recipient::External( - payment.recipient_address().clone(), - PoolType::Shielded(ShieldedProtocol::Sapling), - ), + Recipient::External(payment.recipient_address().clone(), *output_pool), payment.amount(), Some(memo), )); @@ -1117,7 +1111,7 @@ where let recipient = recipient .map_internal_account_note(|pool| { - assert!(pool == PoolType::Shielded(ShieldedProtocol::Orchard)); + assert!(pool == PoolType::ORCHARD); build_result .transaction() .orchard_bundle() @@ -1147,7 +1141,7 @@ where let recipient = recipient .map_internal_account_note(|pool| { - assert!(pool == PoolType::Shielded(ShieldedProtocol::Sapling)); + assert!(pool == PoolType::SAPLING); build_result .transaction() .sapling_bundle() 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 ebbeef66a..ddcba7304 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 26bfbc745..85b596a10 100644 --- a/zcash_client_backend/src/fees.rs +++ b/zcash_client_backend/src/fees.rs @@ -46,7 +46,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, } diff --git a/zcash_client_backend/src/proposal.rs b/zcash_client_backend/src/proposal.rs index a2cf00143..3c0c01215 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 65d4c483c..ea0e25df5 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 b171bf457..092d060d8 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -233,9 +233,7 @@ impl, P: consensus::Parameters> InputSource for .map(|opt| opt.map(|n| n.map_note(Note::Orchard))); #[cfg(not(feature = "orchard"))] - return Err(SqliteClientError::UnsupportedPoolType(PoolType::Shielded( - ShieldedProtocol::Orchard, - ))); + return Err(SqliteClientError::UnsupportedPoolType(PoolType::ORCHARD)); } } } @@ -1074,7 +1072,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 +1153,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 +1275,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 aa7b4c7c1..0ad9072e2 100644 --- a/zcash_client_sqlite/src/testing/pool.rs +++ b/zcash_client_sqlite/src/testing/pool.rs @@ -389,7 +389,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))], @@ -1670,10 +1670,7 @@ pub(crate) fn fully_funded_send_to_t( diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index b51b52948..e8ed54159 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1418,9 +1418,7 @@ pub(crate) fn get_received_memo( ShieldedProtocol::Orchard => fetch_memo(ORCHARD_TABLES_PREFIX, "action_index")?.flatten(), #[cfg(not(feature = "orchard"))] ShieldedProtocol::Orchard => { - return Err(SqliteClientError::UnsupportedPoolType(PoolType::Shielded( - ShieldedProtocol::Orchard, - ))) + return Err(SqliteClientError::UnsupportedPoolType(PoolType::ORCHARD)) } }; diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index dfe62470b..665c253a5 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -905,7 +905,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 550dc14f4..beb382597 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 b4af04235..5a97b24ea 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs @@ -7,9 +7,7 @@ use schemer_rusqlite::RusqliteMigration; use secrecy::{ExposeSecret, SecretVec}; use uuid::Uuid; -use zcash_client_backend::{ - address::Address, keys::UnifiedSpendingKey, PoolType, ShieldedProtocol, -}; +use zcash_client_backend::{address::Address, keys::UnifiedSpendingKey, PoolType}; use zcash_keys::keys::UnifiedAddressRequest; use zcash_primitives::{consensus, zip32::AccountId}; @@ -262,10 +260,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 c94d08a67..8b4aa6d19 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) ] )?;