pub enum Network {
Bitcoin,
Testnet,
Testnet4,
Signet,
Regtest,
}
Expand description
The cryptocurrency network to act on.
This is an exhaustive enum, meaning that we cannot add any future networks without defining a new, incompatible version of this type. If you are using this type directly and wish to support the new network, this will be a breaking change to your APIs and likely require changes in your code.
If you are concerned about forward compatibility, consider using T: Into<Params>
instead of
this type as a parameter to functions in your public API, or directly using the Params
type.
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§
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;
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<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
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);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Network
impl<'de> Deserialize<'de> for Network
Source§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>,
Source§impl Ord for Network
impl Ord for Network
Source§impl PartialOrd for Network
impl PartialOrd for Network
Source§impl Serialize for Network
impl Serialize for Network
Source§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,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.