Adds Network::to_core_arg
This allows users to create `Network` instances from `bitcoind -chain` values
This commit is contained in:
parent
cde120bb0f
commit
bd1eb29f61
|
@ -119,6 +119,28 @@ impl Network {
|
|||
Network::Regtest => "regtest",
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a `bitcoind -chain` argument name to its equivalent `Network`.
|
||||
///
|
||||
/// ```bash
|
||||
/// $ 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<Self, ParseNetworkError> {
|
||||
use Network::*;
|
||||
|
||||
let network = match core_arg {
|
||||
"main" => Bitcoin,
|
||||
"test" => Testnet,
|
||||
"signet" => Signet,
|
||||
"regtest" => Regtest,
|
||||
_ => return Err(ParseNetworkError(core_arg.to_owned())),
|
||||
};
|
||||
Ok(network)
|
||||
}
|
||||
}
|
||||
|
||||
/// An error in parsing network string.
|
||||
|
|
Loading…
Reference in New Issue