Add NetworkKind
Add a new type `NetworkKind` the describes the kind of network we are on, ether mainnet or one of the test nets (testnet, regtest, signet). Do not use the type yet.
This commit is contained in:
parent
3d6151b9e1
commit
6d5ef23e61
|
@ -129,7 +129,7 @@ pub use crate::{
|
|||
crypto::key::{self, PrivateKey, PubkeyHash, PublicKey, CompressedPublicKey, WPubkeyHash, XOnlyPublicKey},
|
||||
crypto::sighash::{self, LegacySighash, SegwitV0Sighash, TapSighash, TapSighashTag},
|
||||
merkle_tree::MerkleBlock,
|
||||
network::Network,
|
||||
network::{Network, NetworkKind},
|
||||
pow::{CompactTarget, Target, Work},
|
||||
psbt::Psbt,
|
||||
sighash::{EcdsaSighashType, TapSighashType},
|
||||
|
|
|
@ -31,6 +31,33 @@ use crate::constants::ChainHash;
|
|||
use crate::p2p::Magic;
|
||||
use crate::prelude::{String, ToOwned};
|
||||
|
||||
/// What kind of network we are on.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum NetworkKind {
|
||||
/// The Bitcoin mainnet network.
|
||||
Main,
|
||||
/// Some kind of testnet network.
|
||||
Test,
|
||||
}
|
||||
|
||||
// We explicitly do not provide `is_testnet`, using `!network.is_mainnet()` is less
|
||||
// ambiguous due to confusion caused by signet/testnet/regtest.
|
||||
impl NetworkKind {
|
||||
/// Returns true if this is real mainnet bitcoin.
|
||||
pub fn is_mainnet(&self) -> bool { *self == NetworkKind::Main }
|
||||
}
|
||||
|
||||
impl From<Network> for NetworkKind {
|
||||
fn from(n: Network) -> Self {
|
||||
use Network::*;
|
||||
|
||||
match n {
|
||||
Bitcoin => NetworkKind::Main,
|
||||
Testnet | Signet | Regtest => NetworkKind::Test,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The cryptocurrency network to act on.
|
||||
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
|
Loading…
Reference in New Issue