Skip to content

Commit 5fb5c9b

Browse files
committed
Clean up chainparams some more.
Clean up the code in chainparams a bit more after the recent refactorings. In particular, make sure the structure of the "RegTest" params matches the structure of the other classes. This makes the code clearer to read. Also remove redundant values of the genesis block in always-specified optional arguments and mark variable/argument as "const".
1 parent 675d2fe commit 5fb5c9b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/chainparams.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using namespace std;
1616

1717
#include "chainparamsseeds.h"
1818

19-
static CBlock CreateGenesisBlock(const char* pszTimestamp, CScript genesisOutputScript, uint32_t nTime=1231006505, uint32_t nNonce=2083236893, uint32_t nBits=0x1d00ffff, int32_t nVersion=1, const CAmount& genesisReward=50 * COIN)
19+
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
2020
{
2121
CMutableTransaction txNew;
2222
txNew.nVersion = 1;
@@ -48,10 +48,10 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, CScript genesisOutput
4848
* CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
4949
* vMerkleTree: 4a5e1e
5050
*/
51-
static CBlock CreateGenesisBlock(uint32_t nTime=1231006505, uint32_t nNonce=2083236893, uint32_t nBits=0x1d00ffff, int32_t nVersion=1, const CAmount& genesisReward=50 * COIN)
51+
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
5252
{
5353
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
54-
CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
54+
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
5555
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
5656
}
5757

@@ -91,7 +91,7 @@ class CMainParams : public CChainParams {
9191
nDefaultPort = 8333;
9292
nPruneAfterHeight = 100000;
9393

94-
genesis = CreateGenesisBlock();
94+
genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
9595
consensus.hashGenesisBlock = genesis.GetHash();
9696
assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
9797
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
@@ -164,9 +164,10 @@ class CTestNetParams : public CChainParams {
164164
nDefaultPort = 18333;
165165
nPruneAfterHeight = 1000;
166166

167-
genesis = CreateGenesisBlock(1296688602, 414098458);
167+
genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
168168
consensus.hashGenesisBlock = genesis.GetHash();
169169
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
170+
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
170171

171172
vFixedSeeds.clear();
172173
vSeeds.clear();
@@ -216,16 +217,19 @@ class CRegTestParams : public CChainParams {
216217
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
217218
consensus.nPowTargetSpacing = 10 * 60;
218219
consensus.fPowAllowMinDifficultyBlocks = true;
220+
219221
pchMessageStart[0] = 0xfa;
220222
pchMessageStart[1] = 0xbf;
221223
pchMessageStart[2] = 0xb5;
222224
pchMessageStart[3] = 0xda;
223-
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff);
224-
consensus.hashGenesisBlock = genesis.GetHash();
225225
nDefaultPort = 18444;
226-
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
227226
nPruneAfterHeight = 1000;
228227

228+
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
229+
consensus.hashGenesisBlock = genesis.GetHash();
230+
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
231+
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
232+
229233
vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds.
230234
vSeeds.clear(); //! Regtest mode doesn't have any DNS seeds.
231235

0 commit comments

Comments
 (0)