zcash_protocol/
lib.rs

1//! *A crate for Zcash protocol constants and value types.*
2//!
3//! `zcash_protocol` contains Rust structs, traits and functions that provide the network constants
4//! for the Zcash main and test networks, as well types for representing ZEC amounts and value
5//! balances.
6//!
7#![cfg_attr(feature = "std", doc = "## Feature flags")]
8#![cfg_attr(feature = "std", doc = document_features::document_features!())]
9//!
10
11#![no_std]
12#![cfg_attr(docsrs, feature(doc_cfg))]
13#![cfg_attr(docsrs, feature(doc_auto_cfg))]
14// Catch documentation errors caused by code changes.
15#![deny(rustdoc::broken_intra_doc_links)]
16// Temporary until we have addressed all Result<T, ()> cases.
17#![allow(clippy::result_unit_err)]
18
19#[cfg_attr(any(test, feature = "test-dependencies"), macro_use)]
20extern crate alloc;
21
22#[cfg(feature = "std")]
23extern crate std;
24
25use core::fmt;
26
27pub mod consensus;
28pub mod constants;
29#[cfg(feature = "local-consensus")]
30pub mod local_consensus;
31pub mod memo;
32pub mod value;
33
34mod txid;
35pub use txid::TxId;
36
37/// A Zcash shielded transfer protocol.
38#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
39pub enum ShieldedProtocol {
40    /// The Sapling protocol
41    Sapling,
42    /// The Orchard protocol
43    Orchard,
44}
45
46/// A value pool in the Zcash protocol.
47#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
48pub enum PoolType {
49    /// The transparent value pool
50    Transparent,
51    /// A shielded value pool.
52    Shielded(ShieldedProtocol),
53}
54
55impl PoolType {
56    pub const TRANSPARENT: PoolType = PoolType::Transparent;
57    pub const SAPLING: PoolType = PoolType::Shielded(ShieldedProtocol::Sapling);
58    pub const ORCHARD: PoolType = PoolType::Shielded(ShieldedProtocol::Orchard);
59}
60
61impl fmt::Display for PoolType {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        match self {
64            PoolType::Transparent => f.write_str("Transparent"),
65            PoolType::Shielded(ShieldedProtocol::Sapling) => f.write_str("Sapling"),
66            PoolType::Shielded(ShieldedProtocol::Orchard) => f.write_str("Orchard"),
67        }
68    }
69}