Skip to content

Commit 97460cf

Browse files
arya2mergify[bot]
andauthored
fix(chain): Use network kind of TestnetKind in transparent addresses 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>
1 parent e0c3a55 commit 97460cf

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

zebra-chain/src/parameters/network.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub enum NetworkKind {
2929
/// A test network.
3030
Testnet,
3131

32-
/// Regtest mode, not yet implemented
33-
// TODO: Add `new_regtest()` and `is_regtest` methods on `Network`.
32+
/// Regtest mode
3433
Regtest,
3534
}
3635

@@ -186,6 +185,16 @@ impl Network {
186185
}
187186
}
188187

188+
/// Returns [`NetworkKind::Testnet`] on Testnet and Regtest, or [`NetworkKind::Mainnet`] on Mainnet.
189+
///
190+
/// This is used for transparent addresses, as the address prefix is the same on Regtest as it is on Testnet.
191+
pub fn t_addr_kind(&self) -> NetworkKind {
192+
match self {
193+
Network::Mainnet => NetworkKind::Mainnet,
194+
Network::Testnet(_) => NetworkKind::Testnet,
195+
}
196+
}
197+
189198
/// Returns an iterator over [`Network`] variants.
190199
pub fn iter() -> impl Iterator<Item = Self> {
191200
[Self::Mainnet, Self::new_default_testnet()].into_iter()

zebra-chain/src/primitives/zcash_primitives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ pub(crate) fn transparent_output_address(
351351

352352
match alt_addr {
353353
Some(zcash_primitives::legacy::TransparentAddress::PublicKeyHash(pub_key_hash)) => Some(
354-
transparent::Address::from_pub_key_hash(network.kind(), pub_key_hash),
354+
transparent::Address::from_pub_key_hash(network.t_addr_kind(), pub_key_hash),
355355
),
356356
Some(zcash_primitives::legacy::TransparentAddress::ScriptHash(script_hash)) => Some(
357-
transparent::Address::from_script_hash(network.kind(), script_hash),
357+
transparent::Address::from_script_hash(network.t_addr_kind(), script_hash),
358358
),
359359
None => None,
360360
}

zebra-consensus/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub enum TransactionError {
204204
#[error("could not find a mempool transaction input UTXO in the best chain")]
205205
TransparentInputNotFound,
206206

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

0 commit comments

Comments
 (0)