#[non_exhaustive]pub enum Network {
Bitcoin,
Testnet,
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.
Signet
Bitcoin’s signet network.
Regtest
Bitcoin’s regtest network.
Implementations§
source§impl Network
impl Network
sourcepub 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;
use std::convert::TryFrom;
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])));
sourcepub 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]));
sourcepub 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
sourcepub fn from_core_arg(core_arg: &str) -> Result<Self, ParseNetworkError>
pub fn from_core_arg(core_arg: &str) -> Result<Self, 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
sourcepub 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);
sourcepub 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;
use std::convert::TryFrom;
assert_eq!(Ok(Network::Bitcoin), Network::try_from(ChainHash::BITCOIN));
Trait Implementations§
source§impl<'de> Deserialize<'de> for Network
impl<'de> Deserialize<'de> for Network
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Network
impl Ord for Network
source§impl PartialEq<Network> for Network
impl PartialEq<Network> for Network
source§impl PartialOrd<Network> for Network
impl PartialOrd<Network> for Network
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Network
impl Eq for Network
impl StructuralEq for Network
impl StructuralPartialEq for Network
Auto Trait Implementations§
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