diff --git a/Cargo.lock b/Cargo.lock index f4f7020de2..03d631410b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3046,6 +3046,7 @@ dependencies = [ "zcash_note_encryption", "zcash_primitives", "zcash_proofs", + "zcash_protocol", "zip32", ] diff --git a/components/zcash_protocol/src/lib.rs b/components/zcash_protocol/src/lib.rs index c597be43a0..b672a5ef3e 100644 --- a/components/zcash_protocol/src/lib.rs +++ b/components/zcash_protocol/src/lib.rs @@ -15,8 +15,38 @@ // Temporary until we have addressed all Result cases. #![allow(clippy::result_unit_err)] +use core::fmt; + pub mod consensus; pub mod constants; #[cfg(feature = "local-consensus")] pub mod local_consensus; pub mod value; + +/// A Zcash shielded transfer protocol. +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub enum ShieldedProtocol { + /// The Sapling protocol + Sapling, + /// The Orchard protocol + Orchard, +} + +/// A value pool in the Zcash protocol. +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum PoolType { + /// The transparent value pool + Transparent, + /// A shielded value pool. + Shielded(ShieldedProtocol), +} + +impl fmt::Display for PoolType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + PoolType::Transparent => f.write_str("Transparent"), + PoolType::Shielded(ShieldedProtocol::Sapling) => f.write_str("Sapling"), + PoolType::Shielded(ShieldedProtocol::Orchard) => f.write_str("Orchard"), + } + } +} diff --git a/zcash_client_backend/Cargo.toml b/zcash_client_backend/Cargo.toml index 61b2785c2e..405d9b76db 100644 --- a/zcash_client_backend/Cargo.toml +++ b/zcash_client_backend/Cargo.toml @@ -30,6 +30,7 @@ zcash_encoding.workspace = true zcash_keys.workspace = true zcash_note_encryption.workspace = true zcash_primitives.workspace = true +zcash_protocol.workspace = true zip32.workspace = true # Dependencies exposed in a public API: diff --git a/zcash_client_backend/src/data_api/wallet.rs b/zcash_client_backend/src/data_api/wallet.rs index c37cfd1548..78f1e6706e 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -741,7 +741,6 @@ where Some(memo), )) } - #[cfg(zcash_unstable = "orchard")] ShieldedProtocol::Orchard => { #[cfg(not(feature = "orchard"))] return Err(Error::UnsupportedPoolType(PoolType::Shielded( diff --git a/zcash_client_backend/src/lib.rs b/zcash_client_backend/src/lib.rs index 94f2c4eaef..0b5f44c7ee 100644 --- a/zcash_client_backend/src/lib.rs +++ b/zcash_client_backend/src/lib.rs @@ -76,9 +76,8 @@ pub mod zip321; #[cfg(feature = "unstable-serialization")] pub mod serialization; -use std::fmt; - pub use decrypt::{decrypt_transaction, DecryptedOutput, TransferType}; +pub use zcash_protocol::{ShieldedProtocol, PoolType}; #[cfg(test)] #[macro_use] @@ -88,33 +87,3 @@ extern crate assert_matches; core::compile_error!( "The `orchard` feature flag requires the `zcash_unstable=\"orchard\"` RUSTFLAG." ); - -/// A shielded transfer protocol known to the wallet. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub enum ShieldedProtocol { - /// The Sapling protocol - Sapling, - /// The Orchard protocol - #[cfg(zcash_unstable = "orchard")] - Orchard, -} - -/// A value pool to which the wallet supports sending transaction outputs. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum PoolType { - /// The transparent value pool - Transparent, - /// A shielded value pool. - Shielded(ShieldedProtocol), -} - -impl fmt::Display for PoolType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - PoolType::Transparent => f.write_str("Transparent"), - PoolType::Shielded(ShieldedProtocol::Sapling) => f.write_str("Sapling"), - #[cfg(zcash_unstable = "orchard")] - PoolType::Shielded(ShieldedProtocol::Orchard) => f.write_str("Orchard"), - } - } -} diff --git a/zcash_client_backend/src/proto.rs b/zcash_client_backend/src/proto.rs index 027f0ee90e..623095dc60 100644 --- a/zcash_client_backend/src/proto.rs +++ b/zcash_client_backend/src/proto.rs @@ -312,7 +312,6 @@ 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)), - #[cfg(zcash_unstable = "orchard")] Ok(proposal::ValuePool::Orchard) => Ok(PoolType::Shielded(ShieldedProtocol::Orchard)), _ => Err(ProposalDecodingError::ValuePoolNotSupported(pool_id)), } @@ -338,7 +337,6 @@ impl From for proposal::ValuePool { fn from(value: ShieldedProtocol) -> Self { match value { ShieldedProtocol::Sapling => proposal::ValuePool::Sapling, - #[cfg(zcash_unstable = "orchard")] ShieldedProtocol::Orchard => proposal::ValuePool::Orchard, } } diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 86fdb51d9d..0d6ced6ea6 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -133,7 +133,6 @@ pub(crate) fn pool_code(pool_type: PoolType) -> i64 { match pool_type { PoolType::Transparent => 0i64, PoolType::Shielded(ShieldedProtocol::Sapling) => 2i64, - #[cfg(zcash_unstable = "orchard")] PoolType::Shielded(ShieldedProtocol::Orchard) => 3i64, } } @@ -796,7 +795,6 @@ pub(crate) fn get_received_memo( ) .optional()? .flatten(), - #[cfg(zcash_unstable = "orchard")] _ => { return Err(SqliteClientError::UnsupportedPoolType(PoolType::Shielded( note_id.protocol(),