Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparatory refactoring for zcash/librustzcash#1673 #1675

Merged
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;
use zcash_protocol::{constants, PoolType};

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

Expand Down Expand Up @@ -136,17 +136,17 @@ impl super::private::SealedContainer for Address {
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const MAINNET: &'static str = "u";
const MAINNET: &'static str = constants::mainnet::HRP_UNIFIED_ADDRESS;

/// The HRP for a Bech32m-encoded testnet Unified Address.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const TESTNET: &'static str = "utest";
const TESTNET: &'static str = constants::testnet::HRP_UNIFIED_ADDRESS;

/// The HRP for a Bech32m-encoded regtest Unified Address.
const REGTEST: &'static str = "uregtest";
const REGTEST: &'static str = constants::regtest::HRP_UNIFIED_ADDRESS;

fn from_inner(receivers: Vec<Self::Item>) -> Self {
Self(receivers)
Expand Down
11 changes: 8 additions & 3 deletions components/zcash_address/src/kind/unified/fvk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::vec::Vec;
use core::convert::{TryFrom, TryInto};
use zcash_protocol::constants;

use super::{
private::{SealedContainer, SealedItem},
Expand Down Expand Up @@ -128,17 +129,21 @@ impl SealedContainer for Ufvk {
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const MAINNET: &'static str = "uview";
const MAINNET: &'static str = constants::mainnet::HRP_UNIFIED_FVK;

/// The HRP for a Bech32m-encoded testnet Unified FVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const TESTNET: &'static str = "uviewtest";
const TESTNET: &'static str = constants::testnet::HRP_UNIFIED_FVK;

/// The HRP for a Bech32m-encoded regtest Unified FVK.
const REGTEST: &'static str = "uviewregtest";
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const REGTEST: &'static str = constants::regtest::HRP_UNIFIED_FVK;

fn from_inner(fvks: Vec<Self::Item>) -> Self {
Self(fvks)
Expand Down
7 changes: 4 additions & 3 deletions components/zcash_address/src/kind/unified/ivk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::vec::Vec;
use core::convert::{TryFrom, TryInto};
use zcash_protocol::constants;

use super::{
private::{SealedContainer, SealedItem},
Expand Down Expand Up @@ -133,17 +134,17 @@ impl SealedContainer for Uivk {
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const MAINNET: &'static str = "uivk";
const MAINNET: &'static str = constants::mainnet::HRP_UNIFIED_IVK;

/// The HRP for a Bech32m-encoded testnet Unified IVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
const TESTNET: &'static str = "uivktest";
const TESTNET: &'static str = constants::testnet::HRP_UNIFIED_IVK;

/// The HRP for a Bech32m-encoded regtest Unified IVK.
const REGTEST: &'static str = "uivkregtest";
const REGTEST: &'static str = constants::regtest::HRP_UNIFIED_IVK;

fn from_inner(ivks: Vec<Self::Item>) -> Self {
Self(ivks)
Expand Down
6 changes: 6 additions & 0 deletions components/zcash_protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this library adheres to Rust's notion of

## [Unreleased]

### Changed
- `zcash_protocol::consensus::NetworkConstants` has added methods:
- `hrp_unified_address`
- `hrp_unified_fvk`
- `hrp_unified_ivk`

## [0.4.3] - 2024-12-16
### Added
- `zcash_protocol::TxId` (moved from `zcash_primitives::transaction`).
Expand Down
57 changes: 57 additions & 0 deletions components/zcash_protocol/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ pub trait NetworkConstants: Clone {
///
/// [ZIP 320]: https://zips.z.cash/zip-0320
fn hrp_tex_address(&self) -> &'static str;

/// The HRP for a Bech32m-encoded mainnet Unified Address.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
fn hrp_unified_address(&self) -> &'static str;

/// The HRP for a Bech32m-encoded mainnet Unified FVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
fn hrp_unified_fvk(&self) -> &'static str;

/// The HRP for a Bech32m-encoded mainnet Unified IVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
fn hrp_unified_ivk(&self) -> &'static str;
}

/// The enumeration of known Zcash network types.
Expand Down Expand Up @@ -272,6 +293,30 @@ impl NetworkConstants for NetworkType {
NetworkType::Regtest => regtest::HRP_TEX_ADDRESS,
}
}

fn hrp_unified_address(&self) -> &'static str {
match self {
NetworkType::Main => mainnet::HRP_UNIFIED_ADDRESS,
NetworkType::Test => testnet::HRP_UNIFIED_ADDRESS,
NetworkType::Regtest => regtest::HRP_UNIFIED_ADDRESS,
}
}

fn hrp_unified_fvk(&self) -> &'static str {
match self {
NetworkType::Main => mainnet::HRP_UNIFIED_FVK,
NetworkType::Test => testnet::HRP_UNIFIED_FVK,
NetworkType::Regtest => regtest::HRP_UNIFIED_FVK,
}
}

fn hrp_unified_ivk(&self) -> &'static str {
match self {
NetworkType::Main => mainnet::HRP_UNIFIED_IVK,
NetworkType::Test => testnet::HRP_UNIFIED_IVK,
NetworkType::Regtest => regtest::HRP_UNIFIED_IVK,
}
}
}

/// Zcash consensus parameters.
Expand Down Expand Up @@ -322,6 +367,18 @@ impl<P: Parameters> NetworkConstants for P {
fn hrp_tex_address(&self) -> &'static str {
self.network_type().hrp_tex_address()
}

fn hrp_unified_address(&self) -> &'static str {
self.network_type().hrp_unified_address()
}

fn hrp_unified_fvk(&self) -> &'static str {
self.network_type().hrp_unified_fvk()
}

fn hrp_unified_ivk(&self) -> &'static str {
self.network_type().hrp_unified_ivk()
}
}

/// Marker struct for the production network.
Expand Down
21 changes: 21 additions & 0 deletions components/zcash_protocol/src/constants/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ pub const B58_SCRIPT_ADDRESS_PREFIX: [u8; 2] = [0x1c, 0xbd];
///
/// [ZIP 320]: https://zips.z.cash/zip-0320
pub const HRP_TEX_ADDRESS: &str = "tex";

/// The HRP for a Bech32m-encoded mainnet Unified Address.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_ADDRESS: &str = "u";

/// The HRP for a Bech32m-encoded mainnet Unified FVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_FVK: &str = "uview";

/// The HRP for a Bech32m-encoded mainnet Unified IVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_IVK: &str = "uivk";
13 changes: 13 additions & 0 deletions components/zcash_protocol/src/constants/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ pub const B58_SCRIPT_ADDRESS_PREFIX: [u8; 2] = [0x1c, 0xba];
///
/// [ZIP 320]: https://zips.z.cash/zip-0320
pub const HRP_TEX_ADDRESS: &str = "texregtest";

/// The HRP for a Bech32m-encoded regtest Unified Address.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_ADDRESS: &str = "uregtest";

/// The HRP for a Bech32m-encoded regtest Unified FVK.
pub const HRP_UNIFIED_FVK: &str = "uviewregtest";

/// The HRP for a Bech32m-encoded regtest Unified IVK.
pub const HRP_UNIFIED_IVK: &str = "uivkregtest";
21 changes: 21 additions & 0 deletions components/zcash_protocol/src/constants/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ pub const B58_SCRIPT_ADDRESS_PREFIX: [u8; 2] = [0x1c, 0xba];
///
/// [ZIP 320]: https://zips.z.cash/zip-0320
pub const HRP_TEX_ADDRESS: &str = "textest";

/// The HRP for a Bech32m-encoded testnet Unified Address.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_ADDRESS: &str = "utest";

/// The HRP for a Bech32m-encoded testnet Unified FVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_FVK: &str = "uviewtest";

/// The HRP for a Bech32m-encoded testnet Unified IVK.
///
/// Defined in [ZIP 316][zip-0316].
///
/// [zip-0316]: https://zips.z.cash/zip-0316
pub const HRP_UNIFIED_IVK: &str = "uivktest";
12 changes: 12 additions & 0 deletions zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ and this library adheres to Rust's notion of

### Changed
- Migrated to `nonempty 0.11`
- `zcash_client_backend::wallet::Recipient` has changed:
- The `Recipient::External` variant is now a structured variant.
- The `Recipient::EphemeralTransparent` variant is now only available if
`zcash_client_backend` is built using the `transparent-inputs` feature flag.
- The `N` and `O` type pararameters to this type have been replaced by
concrete uses of `Box<Note>` and `Outpoint` instead. The
`map_internal_account_note` and `map_ephemeral_transparent_outpoint` and
`internal_account_note_transpose_option` methods have consequently been
removed.
- `zcash_client_backend::data_api::WalletRead::get_known_ephemeral_addresses`
now takes a `Range<zcash_transparent::keys::NonHardenedChildIndex>` as its
argument instead of a `Range<u32>`

### Deprecated
- `zcash_client_backend::address` (use `zcash_keys::address` instead)
Expand Down
1 change: 1 addition & 0 deletions zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ lightwalletd-tonic-transport = ["lightwalletd-tonic", "tonic?/transport"]
## Enables receiving transparent funds and shielding them.
transparent-inputs = [
"dep:bip32",
"transparent/transparent-inputs",
"zcash_keys/transparent-inputs",
"zcash_primitives/transparent-inputs",
]
Expand Down
19 changes: 8 additions & 11 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,18 @@ use std::{
use incrementalmerkletree::{frontier::Frontier, Retention};
use shardtree::{error::ShardTreeError, store::ShardStore, ShardTree};

use ::transparent::bundle::OutPoint;
use zcash_keys::{
address::UnifiedAddress,
keys::{
UnifiedAddressRequest, UnifiedFullViewingKey, UnifiedIncomingViewingKey, UnifiedSpendingKey,
},
};
use zcash_primitives::{
block::BlockHash,
transaction::{Transaction, TxId},
};
use zcash_primitives::{block::BlockHash, transaction::Transaction};
use zcash_protocol::{
consensus::BlockHeight,
memo::{Memo, MemoBytes},
value::{BalanceError, Zatoshis},
ShieldedProtocol,
ShieldedProtocol, TxId,
};
use zip32::fingerprint::SeedFingerprint;

Expand All @@ -99,8 +95,9 @@ use crate::{

#[cfg(feature = "transparent-inputs")]
use {
crate::wallet::TransparentAddressMetadata, ::transparent::address::TransparentAddress,
crate::wallet::TransparentAddressMetadata,
std::ops::Range,
transparent::{address::TransparentAddress, bundle::OutPoint, keys::NonHardenedChildIndex},
};

#[cfg(feature = "test-dependencies")]
Expand Down Expand Up @@ -1465,7 +1462,7 @@ pub trait WalletRead {
fn get_known_ephemeral_addresses(
&self,
_account: Self::AccountId,
_index_range: Option<Range<u32>>,
_index_range: Option<Range<NonHardenedChildIndex>>,
) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> {
Ok(vec![])
}
Expand Down Expand Up @@ -1966,7 +1963,7 @@ impl<'a, AccountId> SentTransaction<'a, AccountId> {
/// This type is capable of representing both shielded and transparent outputs.
pub struct SentTransactionOutput<AccountId> {
output_index: usize,
recipient: Recipient<AccountId, Note, OutPoint>,
recipient: Recipient<AccountId>,
value: Zatoshis,
memo: Option<MemoBytes>,
}
Expand All @@ -1983,7 +1980,7 @@ impl<AccountId> SentTransactionOutput<AccountId> {
/// * `memo` - the memo that was sent with this output
pub fn from_parts(
output_index: usize,
recipient: Recipient<AccountId, Note, OutPoint>,
recipient: Recipient<AccountId>,
value: Zatoshis,
memo: Option<MemoBytes>,
) -> Self {
Expand All @@ -2006,7 +2003,7 @@ impl<AccountId> SentTransactionOutput<AccountId> {
}
/// Returns the recipient address of the transaction, or the account id and
/// resulting note/outpoint for wallet-internal outputs.
pub fn recipient(&self) -> &Recipient<AccountId, Note, OutPoint> {
pub fn recipient(&self) -> &Recipient<AccountId> {
&self.recipient
}
/// Returns the value of the newly created output.
Expand Down
Loading
Loading