Skip to content

Commit 1687cb4

Browse files
committed
Refactor: One CBaseChainParams should be enough
1 parent d405bee commit 1687cb4

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

src/chainparamsbase.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,6 @@ void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
2424
strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
2525
}
2626

27-
/**
28-
* Main network
29-
*/
30-
class CBaseMainParams : public CBaseChainParams
31-
{
32-
public:
33-
CBaseMainParams()
34-
{
35-
nRPCPort = 8332;
36-
}
37-
};
38-
39-
/**
40-
* Testnet (v3)
41-
*/
42-
class CBaseTestNetParams : public CBaseChainParams
43-
{
44-
public:
45-
CBaseTestNetParams()
46-
{
47-
nRPCPort = 18332;
48-
strDataDir = "testnet3";
49-
}
50-
};
51-
52-
/*
53-
* Regression test
54-
*/
55-
class CBaseRegTestParams : public CBaseChainParams
56-
{
57-
public:
58-
CBaseRegTestParams()
59-
{
60-
nRPCPort = 18443;
61-
strDataDir = "regtest";
62-
}
63-
};
64-
6527
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
6628

6729
const CBaseChainParams& BaseParams()
@@ -73,11 +35,11 @@ const CBaseChainParams& BaseParams()
7335
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
7436
{
7537
if (chain == CBaseChainParams::MAIN)
76-
return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
38+
return MakeUnique<CBaseChainParams>("", 8332);
7739
else if (chain == CBaseChainParams::TESTNET)
78-
return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
40+
return MakeUnique<CBaseChainParams>("testnet3", 18332);
7941
else if (chain == CBaseChainParams::REGTEST)
80-
return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
42+
return MakeUnique<CBaseChainParams>("regtest", 18443);
8143
else
8244
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
8345
}

src/chainparamsbase.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class CBaseChainParams
2424
const std::string& DataDir() const { return strDataDir; }
2525
int RPCPort() const { return nRPCPort; }
2626

27-
protected:
28-
CBaseChainParams() {}
27+
CBaseChainParams() = delete;
28+
CBaseChainParams(const std::string& data_dir, int rpc_port) : nRPCPort(rpc_port), strDataDir(data_dir) {}
2929

30+
private:
3031
int nRPCPort;
3132
std::string strDataDir;
3233
};

0 commit comments

Comments
 (0)