Adds `is_regtest()` methods

This commit is contained in:
Arya 2024-04-18 21:05:32 -04:00
parent 9b41cba5a3
commit b38dbfd252
2 changed files with 25 additions and 0 deletions

View File

@ -180,6 +180,15 @@ impl Network {
}
}
/// Returns true if the network is Regtest, or false otherwise.
pub fn is_regtest(&self) -> bool {
if let Self::Testnet(params) = self {
params.is_regtest()
} else {
false
}
}
/// Returns the [`NetworkKind`] for this network.
pub fn kind(&self) -> NetworkKind {
match self {

View File

@ -291,6 +291,22 @@ impl Parameters {
self == &Self::default()
}
/// Returns true if the instance of [`Parameters`] represents Regtest.
pub fn is_regtest(&self) -> bool {
let Self {
network_name,
hrp_sapling_extended_spending_key,
hrp_sapling_extended_full_viewing_key,
hrp_sapling_payment_address,
..
} = Self::new_regtest(ConfiguredActivationHeights::default());
self.network_name == network_name
&& self.hrp_sapling_extended_spending_key == hrp_sapling_extended_spending_key
&& self.hrp_sapling_extended_full_viewing_key == hrp_sapling_extended_full_viewing_key
&& self.hrp_sapling_payment_address == hrp_sapling_payment_address
}
/// Returns the network name
pub fn network_name(&self) -> &str {
&self.network_name