chaintype.cpp raw
1 // Copyright (c) 2023 The Limenka 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 <cassert>
8 #include <optional>
9 #include <string>
10
11 std::string ChainTypeToString(ChainType chain)
12 {
13 switch (chain) {
14 case ChainType::MAIN:
15 return "main";
16 case ChainType::TESTNET:
17 return "test";
18 case ChainType::TESTNET4:
19 return "testnet4";
20 case ChainType::SIGNET:
21 return "signet";
22 case ChainType::REGTEST:
23 return "regtest";
24 case ChainType::FORK:
25 return "limenka";
26 }
27 assert(false);
28 }
29
30 std::optional<ChainType> ChainTypeFromString(std::string_view chain)
31 {
32 if (chain == "main") {
33 return ChainType::MAIN;
34 } else if (chain == "test") {
35 return ChainType::TESTNET;
36 } else if (chain == "testnet4") {
37 return ChainType::TESTNET4;
38 } else if (chain == "signet") {
39 return ChainType::SIGNET;
40 } else if (chain == "regtest") {
41 return ChainType::REGTEST;
42 } else if (chain == "limenka") {
43 return ChainType::FORK;
44 } else {
45 return std::nullopt;
46 }
47 }
48