aboutsummaryrefslogtreecommitdiff
path: root/src/util/chaintype.cpp
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-04-17 21:55:17 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-05-09 11:33:09 +0200
commitbfc21c31b2186f7d30fc9a9ca7d6887ab61c6fb9 (patch)
tree250239b4f93bc9882eb3051d238b0792357a2a01 /src/util/chaintype.cpp
parent322ec63b01499c1ec52d3912ee382ebd59f2366b (diff)
refactor: Create chaintype files
This is the first of a number of commits with the goal of moving the chain type definitions out of chainparamsbase to their own file and implementing them as enums instead of constant strings. The goal is to allow the kernel chainparams to no longer include chainparamsbase. The commit is part of an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager and other functionality that should not be part of the kernel library.
Diffstat (limited to 'src/util/chaintype.cpp')
-rw-r--r--src/util/chaintype.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/util/chaintype.cpp b/src/util/chaintype.cpp
new file mode 100644
index 0000000000..8a199e352a
--- /dev/null
+++ b/src/util/chaintype.cpp
@@ -0,0 +1,39 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <util/chaintype.h>
+
+#include <cassert>
+#include <optional>
+#include <string>
+
+std::string ChainTypeToString(ChainType chain)
+{
+ switch (chain) {
+ case ChainType::MAIN:
+ return "main";
+ case ChainType::TESTNET:
+ return "test";
+ case ChainType::SIGNET:
+ return "signet";
+ case ChainType::REGTEST:
+ return "regtest";
+ }
+ assert(false);
+}
+
+std::optional<ChainType> ChainTypeFromString(std::string_view chain)
+{
+ if (chain == "main") {
+ return ChainType::MAIN;
+ } else if (chain == "test") {
+ return ChainType::TESTNET;
+ } else if (chain == "signet") {
+ return ChainType::SIGNET;
+ } else if (chain == "regtest") {
+ return ChainType::REGTEST;
+ } else {
+ return std::nullopt;
+ }
+}