Bitcoin ABC  0.29.4
P2P Digital Currency
chainparams.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2020 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include <chainparams.h>
8 
9 #include <common/args.h>
10 #include <consensus/merkle.h>
11 #include <currencyunit.h>
12 #include <logging.h>
13 #include <tinyformat.h>
14 
15 #include <cassert>
16 
17 static std::unique_ptr<const CChainParams> globalChainParams;
18 
19 const CChainParams &Params() {
21  return *globalChainParams;
22 }
23 
24 void ReadChainArgs(const ArgsManager &args,
25  CChainParams::ChainOptions &options) {
26  options.ecash = args.GetBoolArg("-ecash", DEFAULT_ECASH);
27  // Only relevant for REGTEST
28  options.fastprune = args.GetBoolArg("-fastprune", false);
29 }
30 
31 std::unique_ptr<const CChainParams>
32 CreateChainParams(const ArgsManager &args, const std::string &chain) {
33  auto opts = CChainParams::ChainOptions{};
34  ReadChainArgs(args, opts);
35  if (chain == CBaseChainParams::MAIN) {
36  return CChainParams::Main(opts);
37  }
38 
39  if (chain == CBaseChainParams::TESTNET) {
40  return CChainParams::TestNet(opts);
41  }
42 
43  if (chain == CBaseChainParams::REGTEST) {
44  return CChainParams::RegTest(opts);
45  }
46 
47  throw std::runtime_error(
48  strprintf("%s: Unknown chain %s.", __func__, chain));
49 }
50 
51 void SelectParams(const std::string &network) {
52  SelectBaseParams(network);
54 }
ArgsManager gArgs
Definition: args.cpp:38
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
Definition: chainparams.cpp:32
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
Definition: chainparams.cpp:51
void ReadChainArgs(const ArgsManager &args, CChainParams::ChainOptions &options)
Definition: chainparams.cpp:24
static std::unique_ptr< const CChainParams > globalChainParams
Definition: chainparams.cpp:17
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:556
static const std::string REGTEST
static const std::string TESTNET
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:80
static std::unique_ptr< const CChainParams > TestNet(const ChainOptions &options)
static std::unique_ptr< const CChainParams > RegTest(const ChainOptions &options)
static std::unique_ptr< const CChainParams > Main(const ChainOptions &options)
constexpr bool DEFAULT_ECASH
Definition: currencyunit.h:10
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
assert(!tx.IsCoinBase())