Adds Sapling HRPs as fields on testnet params. (#8398)

This commit is contained in:
Arya 2024-04-17 18:39:16 -04:00 committed by GitHub
parent 868535b54c
commit 0b835f1f05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 22 deletions

View File

@ -308,43 +308,29 @@ impl zp_consensus::Parameters for Network {
fn address_network(&self) -> Option<zcash_address::Network> {
match self {
Network::Mainnet => Some(zcash_address::Network::Main),
Network::Testnet(params) if params.is_default_testnet() => {
Some(zcash_address::Network::Test)
}
_other => None,
// TODO: Check if network is `Regtest` first, and if it is, return `zcash_address::Network::Regtest`
Network::Testnet(_params) => Some(zcash_address::Network::Test),
}
}
fn hrp_sapling_extended_spending_key(&self) -> &str {
match self {
Network::Mainnet => zp_constants::mainnet::HRP_SAPLING_EXTENDED_SPENDING_KEY,
Network::Testnet(params) if params.is_default_testnet() => {
zp_constants::testnet::HRP_SAPLING_EXTENDED_SPENDING_KEY
}
// TODO: Add this as a field to testnet params
_other => "secret-extended-key-unknown-test",
Network::Testnet(params) => params.hrp_sapling_extended_spending_key(),
}
}
fn hrp_sapling_extended_full_viewing_key(&self) -> &str {
match self {
Network::Mainnet => zp_constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
Network::Testnet(params) if params.is_default_testnet() => {
zp_constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY
}
// TODO: Add this as a field to testnet params
_other => "zxviewunknowntestsapling",
Network::Testnet(params) => params.hrp_sapling_extended_full_viewing_key(),
}
}
fn hrp_sapling_payment_address(&self) -> &str {
match self {
Network::Mainnet => zp_constants::mainnet::HRP_SAPLING_PAYMENT_ADDRESS,
Network::Testnet(params) if params.is_default_testnet() => {
zp_constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS
}
// TODO: Add this as a field to testnet params
_other => "zunknowntestsapling",
Network::Testnet(params) => params.hrp_sapling_payment_address(),
}
}

View File

@ -1,6 +1,8 @@
//! Types and implementation for Testnet consensus parameters
use std::collections::BTreeMap;
use zcash_primitives::constants as zp_constants;
use crate::{
block::Height,
parameters::{
@ -35,6 +37,12 @@ pub struct ConfiguredActivationHeights {
pub struct ParametersBuilder {
/// The network upgrade activation heights for this network, see [`Parameters::activation_heights`] for more details.
activation_heights: BTreeMap<Height, NetworkUpgrade>,
/// Sapling extended spending key human-readable prefix for this network
hrp_sapling_extended_spending_key: String,
/// Sapling extended full viewing key human-readable prefix for this network
hrp_sapling_extended_full_viewing_key: String,
/// Sapling payment address human-readable prefix for this network
hrp_sapling_payment_address: String,
}
impl Default for ParametersBuilder {
@ -50,6 +58,12 @@ impl Default for ParametersBuilder {
]
.into_iter()
.collect(),
hrp_sapling_extended_spending_key:
zp_constants::testnet::HRP_SAPLING_EXTENDED_SPENDING_KEY.to_string(),
hrp_sapling_extended_full_viewing_key:
zp_constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY.to_string(),
hrp_sapling_payment_address: zp_constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS
.to_string(),
}
}
}
@ -120,8 +134,18 @@ impl ParametersBuilder {
/// Converts the builder to a [`Parameters`] struct
pub fn finish(self) -> Parameters {
let Self { activation_heights } = self;
Parameters { activation_heights }
let Self {
activation_heights,
hrp_sapling_extended_spending_key,
hrp_sapling_extended_full_viewing_key,
hrp_sapling_payment_address,
} = self;
Parameters {
activation_heights,
hrp_sapling_extended_spending_key,
hrp_sapling_extended_full_viewing_key,
hrp_sapling_payment_address,
}
}
/// Converts the builder to a configured [`Network::Testnet`]
@ -139,6 +163,12 @@ pub struct Parameters {
/// compiled with the `zebra-test` feature flag AND the `TEST_FAKE_ACTIVATION_HEIGHTS`
/// environment variable is set.
activation_heights: BTreeMap<Height, NetworkUpgrade>,
/// Sapling extended spending key human-readable prefix for this network
hrp_sapling_extended_spending_key: String,
/// Sapling extended full viewing key human-readable prefix for this network
hrp_sapling_extended_full_viewing_key: String,
/// Sapling payment address human-readable prefix for this network
hrp_sapling_payment_address: String,
}
impl Default for Parameters {
@ -146,6 +176,12 @@ impl Default for Parameters {
fn default() -> Self {
Self {
activation_heights: TESTNET_ACTIVATION_HEIGHTS.iter().cloned().collect(),
hrp_sapling_extended_spending_key:
zp_constants::testnet::HRP_SAPLING_EXTENDED_SPENDING_KEY.to_string(),
hrp_sapling_extended_full_viewing_key:
zp_constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY.to_string(),
hrp_sapling_payment_address: zp_constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS
.to_string(),
}
}
}
@ -161,8 +197,23 @@ impl Parameters {
self == &Self::default()
}
/// Returns a reference to the network upgrade activation heights
/// Returns the network upgrade activation heights
pub fn activation_heights(&self) -> &BTreeMap<Height, NetworkUpgrade> {
&self.activation_heights
}
/// Returns the `hrp_sapling_extended_spending_key` field
pub fn hrp_sapling_extended_spending_key(&self) -> &str {
&self.hrp_sapling_extended_spending_key
}
/// Returns the `hrp_sapling_extended_full_viewing_key` field
pub fn hrp_sapling_extended_full_viewing_key(&self) -> &str {
&self.hrp_sapling_extended_full_viewing_key
}
/// Returns the `hrp_sapling_payment_address` field
pub fn hrp_sapling_payment_address(&self) -> &str {
&self.hrp_sapling_payment_address
}
}