Skip to content

Commit

Permalink
fix(chain): Use network kind of TestnetKind in transparent addresse…
Browse files Browse the repository at this point in the history
…s on Regtest (#9175)

* Use `TestnetKind` as transparent addr network kinds on Regtest

* Updates outdated error message

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
arya2 and mergify[bot] authored Feb 7, 2025
1 parent e0c3a55 commit 97460cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

0 comments on commit 97460cf

Please sign in to comment.