Enum Network
#[non_exhaustive]pub enum Network {
Bitcoin,
Testnet,
Testnet4,
Signet,
Regtest,
}
Expand description
The cryptocurrency network to act on.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Bitcoin
Mainnet Bitcoin.
Testnet
Bitcoin’s testnet network. (In future versions this will be combined into a single variant containing the version)
Testnet4
Bitcoin’s testnet4 network. (In future versions this will be combined into a single variant containing the version)
Signet
Bitcoin’s signet network.
Regtest
Bitcoin’s regtest network.
Implementations§
§impl Network
impl Network
pub fn from_magic(magic: Magic) -> Option<Network>
pub fn from_magic(magic: Magic) -> Option<Network>
Creates a Network
from the magic bytes.
§Examples
use bitcoin::p2p::Magic;
use bitcoin::Network;
assert_eq!(Ok(Network::Bitcoin), Network::try_from(Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9])));
assert_eq!(None, Network::from_magic(Magic::from_bytes([0xFF, 0xFF, 0xFF, 0xFF])));
pub fn magic(self) -> Magic
pub fn magic(self) -> Magic
Return the network magic bytes, which should be encoded little-endian at the start of every message
§Examples
use bitcoin::p2p::Magic;
use bitcoin::Network;
let network = Network::Bitcoin;
assert_eq!(network.magic(), Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9]));
pub fn to_core_arg(self) -> &'static str
pub fn to_core_arg(self) -> &'static str
Converts a Network
to its equivalent bitcoind -chain
argument name.
$ bitcoin-23.0/bin/bitcoind --help | grep -C 3 '\-chain=<chain>'
Chain selection options:
-chain=<chain>
Use the chain <chain> (default: main). Allowed values: main, test, signet, regtest
pub fn from_core_arg(core_arg: &str) -> Result<Network, ParseNetworkError>
pub fn from_core_arg(core_arg: &str) -> Result<Network, ParseNetworkError>
Converts a bitcoind -chain
argument name to its equivalent Network
.
$ bitcoin-23.0/bin/bitcoind --help | grep -C 3 '\-chain=<chain>'
Chain selection options:
-chain=<chain>
Use the chain <chain> (default: main). Allowed values: main, test, signet, regtest
pub fn chain_hash(self) -> ChainHash
pub fn chain_hash(self) -> ChainHash
Return the network’s chain hash (genesis block hash).
§Examples
use bitcoin::Network;
use bitcoin::blockdata::constants::ChainHash;
let network = Network::Bitcoin;
assert_eq!(network.chain_hash(), ChainHash::BITCOIN);
pub fn from_chain_hash(chain_hash: ChainHash) -> Option<Network>
pub fn from_chain_hash(chain_hash: ChainHash) -> Option<Network>
Creates a Network
from the chain hash (genesis block hash).
§Examples
use bitcoin::Network;
use bitcoin::blockdata::constants::ChainHash;
assert_eq!(Ok(Network::Bitcoin), Network::try_from(ChainHash::BITCOIN));
Trait Implementations§
§impl<'de> Deserialize<'de> for Network
impl<'de> Deserialize<'de> for Network
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Network, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Network, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl From<Network> for NetworkKind
impl From<Network> for NetworkKind
§fn from(n: Network) -> NetworkKind
fn from(n: Network) -> NetworkKind
Converts to this type from the input type.
§impl Ord for Network
impl Ord for Network
§impl PartialOrd for Network
impl PartialOrd for Network
§impl Serialize for Network
impl Serialize for Network
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Network
impl Eq for Network
impl StructuralPartialEq for Network
Auto Trait Implementations§
impl Freeze for Network
impl RefUnwindSafe for Network
impl Send for Network
impl Sync for Network
impl Unpin for Network
impl UnwindSafe for Network
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more