Skip to content

Commit

Permalink
Prefer the PoolType::{SAPLING, ORCHARD, TRANSPARENT} constants to
Browse files Browse the repository at this point in the history
`PoolType::{Shielded(_), Transparent}`.

Signed-off-by: Daira-Emma Hopwood <[email protected]>
  • Loading branch information
daira committed Jun 3, 2024
1 parent fd5b031 commit 41839cd
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 46 deletions.
8 changes: 4 additions & 4 deletions components/zcash_address/src/kind/unified/address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use zcash_protocol::{PoolType, ShieldedProtocol};
use zcash_protocol::PoolType;

use super::{private::SealedItem, ParseError, Typecode};

Expand Down Expand Up @@ -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,
})
}
Expand Down
6 changes: 3 additions & 3 deletions components/zcash_address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}
}

Expand Down
10 changes: 5 additions & 5 deletions zcash_client_backend/src/data_api/wallet/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions zcash_client_backend/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
Expand All @@ -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<MemoBytes>) -> Self {
Self {
output_pool: PoolType::Shielded(ShieldedProtocol::Sapling),
output_pool: PoolType::SAPLING,
value,
memo,
}
Expand All @@ -61,7 +61,7 @@ impl ChangeValue {
#[cfg(feature = "orchard")]
pub fn orchard(value: NonNegativeAmount, memo: Option<MemoBytes>) -> Self {
Self {
output_pool: PoolType::Shielded(ShieldedProtocol::Orchard),
output_pool: PoolType::ORCHARD,
value,
memo,
}
Expand Down
6 changes: 3 additions & 3 deletions zcash_client_backend/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<FeeRuleT, NoteRef> Proposal<FeeRuleT, NoteRef> {

for t_out in step.transparent_inputs() {
let key = (
PoolType::Transparent,
PoolType::TRANSPARENT,
TxId::from_bytes(*t_out.outpoint().hash()),
t_out.outpoint().n(),
);
Expand All @@ -198,9 +198,9 @@ impl<FeeRuleT, NoteRef> Proposal<FeeRuleT, NoteRef> {
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(),
Expand Down
8 changes: 4 additions & 4 deletions zcash_client_backend/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ impl<E: std::error::Error + 'static> std::error::Error for ProposalDecodingError

fn pool_type<T>(pool_id: i32) -> Result<PoolType, ProposalDecodingError<T>> {
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)),
}
}
Expand Down Expand Up @@ -675,7 +675,7 @@ impl proposal::Proposal {
.ok_or({
ProposalDecodingError::InputNotFound(
txid,
PoolType::Transparent,
PoolType::TRANSPARENT,
out.index,
)
})?,
Expand Down
6 changes: 3 additions & 3 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
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(
Expand Down Expand Up @@ -1155,7 +1155,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
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(
Expand Down Expand Up @@ -1277,7 +1277,7 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
#[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,
Expand Down
7 changes: 2 additions & 5 deletions zcash_client_sqlite/src/testing/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub(crate) fn send_multi_step_proposed_transfer<T: ShieldedPoolTester>() {
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))],
Expand Down Expand Up @@ -1665,10 +1665,7 @@ pub(crate) fn fully_funded_send_to_t<P0: ShieldedPoolTester, P1: ShieldedPoolTes
// Since there are sufficient funds in either pool, change is kept in the same pool as
// the source note (the target pool), and does not necessarily follow preference order.
// The source note will always be sapling, as we spend Sapling funds preferentially.
assert_eq!(
change_output.output_pool(),
PoolType::Shielded(ShieldedProtocol::Sapling)
);
assert_eq!(change_output.output_pool(), PoolType::SAPLING);
assert_eq!(change_output.value(), expected_change);

let create_proposed_result = st.create_proposed_transactions::<Infallible, _>(
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_sqlite/src/wallet/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -262,10 +262,8 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
))
})?;
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
]
)?;

Expand Down

0 comments on commit 41839cd

Please sign in to comment.