From 519db4d9515d11f3f7243d1ea10c0fefc700ece4 Mon Sep 17 00:00:00 2001 From: connormullett Date: Thu, 17 Nov 2022 17:25:00 -0500 Subject: [PATCH] add Network::to_core_arg() method --- bitcoin/src/network/constants.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bitcoin/src/network/constants.rs b/bitcoin/src/network/constants.rs index a8025ee3..595f3db2 100644 --- a/bitcoin/src/network/constants.rs +++ b/bitcoin/src/network/constants.rs @@ -101,6 +101,24 @@ impl Network { /// assert_eq!(network.magic(), Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9])); /// ``` pub fn magic(self) -> Magic { Magic::from(self) } + + /// Converts a `Network` to its equivalent `bitcoind -chain` argument name. + /// + /// ```bash,no_run + /// $ bitcoin-23.0/bin/bitcoind --help | grep -C 3 '\-chain=' + /// Chain selection options: + /// + /// -chain= + /// Use the chain (default: main). Allowed values: main, test, signet, regtest + /// ``` + pub fn to_core_arg(self) -> &'static str { + match self { + Network::Bitcoin => "main", + Network::Testnet => "test", + Network::Signet => "signet", + Network::Regtest => "regtest", + } + } } /// An error in parsing network string.