Skip to content

Commit

Permalink
Merge #12128: Refactor: One CBaseChainParams should be enough
Browse files Browse the repository at this point in the history
Summary:
1687cb4 Refactor: One CBaseChainParams should be enough (Jorge Timón)

Pull request description:

  There's no need for class hierarchy with CBaseChainParams, it is just a struct with 2 fields.
  This starts as a +10-43 diff

Tree-SHA512: 0a7dd64ab785416550b541787c6083540e4962d76b6cffa806bb3593aec2daf1752dfe65ac5cd51b34ad5c31dd8292c422b483fdd2d37d0b7e68725498ed4c2d

Backport of Core PR12128
bitcoin/bitcoin#12128

Test Plan:
  make check

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3804
  • Loading branch information
laanwj authored and proteanx committed Sep 10, 2019
1 parent 781a504 commit 2a41c08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
36 changes: 3 additions & 33 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,6 @@ void SetupChainParamsBaseOptions() {
OptionsCategory::CHAINPARAMS);
}

/**
* Main network
*/
class CBaseMainParams : public CBaseChainParams {
public:
CBaseMainParams() { nRPCPort = 3339; }
};

/**
* Testnet (v3)
*/
class CBaseTestNetParams : public CBaseChainParams {
public:
CBaseTestNetParams() {
nRPCPort = 13339;
strDataDir = "testnet1";
}
};

/*
* Regression test
*/
class CBaseRegTestParams : public CBaseChainParams {
public:
CBaseRegTestParams() {
nRPCPort = 18332;
strDataDir = "regtest";
}
};

static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

const CBaseChainParams &BaseParams() {
Expand All @@ -64,11 +34,11 @@ const CBaseChainParams &BaseParams() {
std::unique_ptr<CBaseChainParams>
CreateBaseChainParams(const std::string &chain) {
if (chain == CBaseChainParams::MAIN)
return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
return std::make_unique<CBaseChainParams>("", 3339);
else if (chain == CBaseChainParams::TESTNET)
return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
return std::make_unique<CBaseChainParams>("testnet1", 13339);
else if (chain == CBaseChainParams::REGTEST)
return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
return std::make_unique<CBaseChainParams>("regtest", 18332);
else
throw std::runtime_error(
strprintf("%s: Unknown chain %s.", __func__, chain));
Expand Down
6 changes: 4 additions & 2 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class CBaseChainParams {
const std::string &DataDir() const { return strDataDir; }
int RPCPort() const { return nRPCPort; }

protected:
CBaseChainParams() = default;
CBaseChainParams() = delete;
CBaseChainParams(const std::string &data_dir, int rpc_port)
: nRPCPort(rpc_port), strDataDir(data_dir) {}

private:
int nRPCPort;
std::string strDataDir;
};
Expand Down

0 comments on commit 2a41c08

Please sign in to comment.