Skip to content

Commit

Permalink
zcash_client_backend: Move the ShieldedProtocol and PoolType type…
Browse files Browse the repository at this point in the history
…s to `zcash_protocol`
  • Loading branch information
nuttycom committed Feb 2, 2024
1 parent 7350f45 commit 3abc70e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions components/zcash_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,38 @@
// Temporary until we have addressed all Result<T, ()> 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"),

Check warning on line 49 in components/zcash_protocol/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_protocol/src/lib.rs#L46-L49

Added lines #L46 - L49 were not covered by tests
}
}
}
1 change: 1 addition & 0 deletions zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ where
Some(memo),
))
}
#[cfg(zcash_unstable = "orchard")]
ShieldedProtocol::Orchard => {
#[cfg(not(feature = "orchard"))]
return Err(Error::UnsupportedPoolType(PoolType::Shielded(
Expand Down
33 changes: 1 addition & 32 deletions zcash_client_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"),
}
}
}
2 changes: 0 additions & 2 deletions zcash_client_backend/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ 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)),
#[cfg(zcash_unstable = "orchard")]
Ok(proposal::ValuePool::Orchard) => Ok(PoolType::Shielded(ShieldedProtocol::Orchard)),
_ => Err(ProposalDecodingError::ValuePoolNotSupported(pool_id)),
}
Expand All @@ -338,7 +337,6 @@ impl From<ShieldedProtocol> for proposal::ValuePool {
fn from(value: ShieldedProtocol) -> Self {
match value {
ShieldedProtocol::Sapling => proposal::ValuePool::Sapling,
#[cfg(zcash_unstable = "orchard")]
ShieldedProtocol::Orchard => proposal::ValuePool::Orchard,
}
}
Expand Down
2 changes: 0 additions & 2 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 3abc70e

Please sign in to comment.