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

fix(chain): Use network kind of TestnetKind in transparent addresses on Regtest #9175

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions zebra-chain/src/parameters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub enum NetworkKind {
/// A test network.
Testnet,

/// Regtest mode, not yet implemented
// TODO: Add `new_regtest()` and `is_regtest` methods on `Network`.
/// Regtest mode
Regtest,
}

Expand Down Expand Up @@ -186,6 +185,16 @@ impl Network {
}
}

/// Returns [`NetworkKind::Testnet`] on Testnet and Regtest, or [`NetworkKind::Mainnet`] on Mainnet.
///
/// This is used for transparent addresses, as the address prefix is the same on Regtest as it is on Testnet.
pub fn t_addr_kind(&self) -> NetworkKind {
match self {
Network::Mainnet => NetworkKind::Mainnet,
Network::Testnet(_) => NetworkKind::Testnet,
}
}

/// Returns an iterator over [`Network`] variants.
pub fn iter() -> impl Iterator<Item = Self> {
[Self::Mainnet, Self::new_default_testnet()].into_iter()
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/primitives/zcash_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ pub(crate) fn transparent_output_address(

match alt_addr {
Some(zcash_primitives::legacy::TransparentAddress::PublicKeyHash(pub_key_hash)) => Some(
transparent::Address::from_pub_key_hash(network.kind(), pub_key_hash),
transparent::Address::from_pub_key_hash(network.t_addr_kind(), pub_key_hash),
),
Some(zcash_primitives::legacy::TransparentAddress::ScriptHash(script_hash)) => Some(
transparent::Address::from_script_hash(network.kind(), script_hash),
transparent::Address::from_script_hash(network.t_addr_kind(), script_hash),
),
None => None,
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-consensus/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub enum TransactionError {
#[error("could not find a mempool transaction input UTXO in the best chain")]
TransparentInputNotFound,

#[error("could not validate nullifiers and anchors on best chain: {0}")]
#[error("could not contextually validate transaction on best chain: {0}")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
// This error variant is at least 128 bytes
ValidateContextError(Box<ValidateContextError>),
Expand Down
Loading