Branch data Line data Source code
1 : : // Copyright (c) 2023-present The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <util/chaintype.h>
6 : :
7 : : #include <util/check.h>
8 : :
9 : : #include <optional>
10 : : #include <string>
11 : :
12 : 1261648 : std::string ChainTypeToString(ChainType chain)
13 : : {
14 [ + + + + : 1261648 : switch (chain) {
+ - ]
15 : 1209847 : case ChainType::MAIN:
16 : 1209847 : return "main";
17 : 8789 : case ChainType::TESTNET:
18 : 8789 : return "test";
19 : 9087 : case ChainType::TESTNET4:
20 : 9087 : return "testnet4";
21 : 8944 : case ChainType::SIGNET:
22 : 8944 : return "signet";
23 : 24981 : case ChainType::REGTEST:
24 : 24981 : return "regtest";
25 : : }
26 : 0 : assert(false);
27 : : }
28 : :
29 : 171 : std::optional<ChainType> ChainTypeFromString(std::string_view chain)
30 : : {
31 [ + + ]: 171 : if (chain == "main") {
32 : 36 : return ChainType::MAIN;
33 [ - + ]: 135 : } else if (chain == "test") {
34 : 0 : return ChainType::TESTNET;
35 [ + + ]: 135 : } else if (chain == "testnet4") {
36 : 36 : return ChainType::TESTNET4;
37 [ + + ]: 99 : } else if (chain == "signet") {
38 : 36 : return ChainType::SIGNET;
39 [ + - ]: 63 : } else if (chain == "regtest") {
40 : 63 : return ChainType::REGTEST;
41 : : } else {
42 : 0 : return std::nullopt;
43 : : }
44 : : }
|