Prefer the `PoolType::{SAPLING, ORCHARD, TRANSPARENT}` constants to
`PoolType::{Shielded(_), Transparent}`. Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
c3e532f29b
commit
6c90219817
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ impl proposal::Proposal {
|
|||
.ok_or({
|
||||
ProposalDecodingError::InputNotFound(
|
||||
txid,
|
||||
PoolType::Transparent,
|
||||
PoolType::TRANSPARENT,
|
||||
out.index,
|
||||
)
|
||||
})?,
|
||||
|
|
|
@ -233,9 +233,7 @@ impl<C: Borrow<rusqlite::Connection>, 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<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(
|
||||
|
@ -1155,7 +1153,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(
|
||||
|
@ -1277,7 +1275,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,
|
||||
|
|
|
@ -389,7 +389,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))],
|
||||
|
@ -1670,10 +1670,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, _>(
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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(())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<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(),
|
||||
|
|
|
@ -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)
|
||||
]
|
||||
)?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue