/ src / util / chaintype.cpp
chaintype.cpp
 1  // Copyright (c) 2023 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 <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::SIGNET:
19          return "signet";
20      case ChainType::REGTEST:
21          return "regtest";
22      }
23      assert(false);
24  }
25  
26  std::optional<ChainType> ChainTypeFromString(std::string_view chain)
27  {
28      if (chain == "main") {
29          return ChainType::MAIN;
30      } else if (chain == "test") {
31          return ChainType::TESTNET;
32      } else if (chain == "signet") {
33          return ChainType::SIGNET;
34      } else if (chain == "regtest") {
35          return ChainType::REGTEST;
36      } else {
37          return std::nullopt;
38      }
39  }