Skip to content

Commit c8c52de

Browse files
committed
Replace virtual methods with static attributes, chainparams.h depends on
protocol.h instead of the other way around
1 parent a3d946e commit c8c52de

File tree

5 files changed

+53
-41
lines changed

5 files changed

+53
-41
lines changed

src/alert.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "alert.h"
77

8+
#include "chainparams.h"
89
#include "key.h"
910
#include "net.h"
1011
#include "ui_interface.h"

src/chainparams.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include "chainparams.h"
77

88
#include "assert.h"
9-
#include "core.h"
10-
#include "protocol.h"
119
#include "util.h"
1210

1311
#include <boost/assign/list_of.hpp>
@@ -100,6 +98,7 @@ unsigned int pnSeed[] =
10098
class CMainParams : public CChainParams {
10199
public:
102100
CMainParams() {
101+
networkID = CChainParams::MAIN;
103102
// The message start string is designed to be unlikely to occur in normal data.
104103
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
105104
// a large 4-byte int at any alignment.
@@ -171,27 +170,25 @@ class CMainParams : public CChainParams {
171170
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
172171
vFixedSeeds.push_back(addr);
173172
}
174-
}
175-
176-
virtual const CBlock& GenesisBlock() const { return genesis; }
177-
virtual Network NetworkID() const { return CChainParams::MAIN; }
178173

179-
virtual const vector<CAddress>& FixedSeeds() const {
180-
return vFixedSeeds;
174+
fRequireRPCPassword = true;
175+
fMiningRequiresPeers = true;
176+
fDefaultCheckMemPool = false;
177+
fAllowMinDifficultyBlocks = false;
178+
fRequireStandard = true;
179+
fRPCisTestNet = false;
180+
fMineBlocksOnDemand = false;
181181
}
182-
protected:
183-
CBlock genesis;
184-
vector<CAddress> vFixedSeeds;
185182
};
186183
static CMainParams mainParams;
187184

188-
189185
//
190186
// Testnet (v3)
191187
//
192188
class CTestNetParams : public CMainParams {
193189
public:
194190
CTestNetParams() {
191+
networkID = CChainParams::TESTNET;
195192
// The message start string is designed to be unlikely to occur in normal data.
196193
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
197194
// a large 4-byte int at any alignment.
@@ -223,22 +220,25 @@ class CTestNetParams : public CMainParams {
223220
base58Prefixes[SECRET_KEY] = list_of(239);
224221
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF);
225222
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94);
226-
}
227223

228-
virtual bool AllowMinDifficultyBlocks() const { return true; }
229-
virtual bool RequireStandard() const { return false; }
230-
virtual bool RPCisTestNet() const { return true; }
231-
virtual Network NetworkID() const { return CChainParams::TESTNET; }
224+
fRequireRPCPassword = true;
225+
fMiningRequiresPeers = true;
226+
fDefaultCheckMemPool = false;
227+
fAllowMinDifficultyBlocks = true;
228+
fRequireStandard = false;
229+
fRPCisTestNet = true;
230+
fMineBlocksOnDemand = false;
231+
}
232232
};
233233
static CTestNetParams testNetParams;
234234

235-
236235
//
237236
// Regression test
238237
//
239238
class CRegTestParams : public CTestNetParams {
240239
public:
241240
CRegTestParams() {
241+
networkID = CChainParams::REGTEST;
242242
pchMessageStart[0] = 0xfa;
243243
pchMessageStart[1] = 0xbf;
244244
pchMessageStart[2] = 0xb5;
@@ -258,14 +258,15 @@ class CRegTestParams : public CTestNetParams {
258258
assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
259259

260260
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
261-
}
262261

263-
virtual bool RequireRPCPassword() const { return false; }
264-
virtual bool MiningRequiresPeers() const { return false; }
265-
virtual bool MineBlocksOnDemand() const { return true; }
266-
virtual bool DefaultCheckMemPool() const { return true; }
267-
virtual bool RequireStandard() const { return false; }
268-
virtual Network NetworkID() const { return CChainParams::REGTEST; }
262+
fRequireRPCPassword = false;
263+
fMiningRequiresPeers = false;
264+
fDefaultCheckMemPool = true;
265+
fAllowMinDifficultyBlocks = true;
266+
fRequireStandard = false;
267+
fRPCisTestNet = true;
268+
fMineBlocksOnDemand = true;
269+
}
269270
};
270271
static CRegTestParams regTestParams;
271272

src/chainparams.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
#define BITCOIN_CHAIN_PARAMS_H
88

99
#include "uint256.h"
10+
#include "core.h"
11+
#include "protocol.h"
1012

1113
#include <vector>
1214

1315
using namespace std;
1416

15-
#define MESSAGE_START_SIZE 4
1617
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
1718

18-
class CAddress;
19-
class CBlock;
20-
2119
struct CDNSSeedData {
2220
string name, host;
2321
CDNSSeedData(const string &strName, const string &strHost) : name(strName), host(strHost) {}
@@ -64,26 +62,26 @@ class CChainParams
6462

6563
/* Used if GenerateBitcoins is called with a negative number of threads */
6664
int DefaultMinerThreads() const { return nMinerThreads; }
67-
virtual const CBlock& GenesisBlock() const = 0;
68-
virtual bool RequireRPCPassword() const { return true; }
65+
const CBlock& GenesisBlock() const { return genesis; };
66+
bool RequireRPCPassword() const { return fRequireRPCPassword; }
6967
/* Make miner wait to have peers to avoid wasting work */
70-
virtual bool MiningRequiresPeers() const { return true; }
68+
bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
7169
/* Default value for -checkmempool argument */
72-
virtual bool DefaultCheckMemPool() const { return false; }
70+
bool DefaultCheckMemPool() const { return fDefaultCheckMemPool; }
7371
/* Allow mining of a min-difficulty block */
74-
virtual bool AllowMinDifficultyBlocks() const { return false; }
72+
bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
7573
/* Make standard checks */
76-
virtual bool RequireStandard() const { return true; }
74+
bool RequireStandard() const { return fRequireStandard; }
7775
/* Make standard checks */
78-
virtual bool RPCisTestNet() const { return false; }
76+
bool RPCisTestNet() const { return fRPCisTestNet; }
7977
const string& DataDir() const { return strDataDir; }
8078
/* Make miner stop after a block is found. In RPC, don't return
8179
* until nGenProcLimit blocks are generated */
82-
virtual bool MineBlocksOnDemand() const { return false; }
83-
virtual Network NetworkID() const = 0;
80+
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
81+
Network NetworkID() const { return networkID; }
8482
const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
85-
const std::vector<unsigned char> &Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
86-
virtual const vector<CAddress>& FixedSeeds() const = 0;
83+
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
84+
const vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
8785
int RPCPort() const { return nRPCPort; }
8886
protected:
8987
CChainParams() {}
@@ -103,6 +101,16 @@ class CChainParams
103101
int nMinerThreads;
104102
vector<CDNSSeedData> vSeeds;
105103
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
104+
Network networkID;
105+
CBlock genesis;
106+
vector<CAddress> vFixedSeeds;
107+
bool fRequireRPCPassword;
108+
bool fMiningRequiresPeers;
109+
bool fDefaultCheckMemPool;
110+
bool fAllowMinDifficultyBlocks;
111+
bool fRequireStandard;
112+
bool fRPCisTestNet;
113+
bool fMineBlocksOnDemand;
106114
};
107115

108116
/**

src/protocol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "protocol.h"
77

8+
#include "chainparams.h"
89
#include "util.h"
910

1011
#ifndef WIN32

src/protocol.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#ifndef __INCLUDED_PROTOCOL_H__
1111
#define __INCLUDED_PROTOCOL_H__
1212

13-
#include "chainparams.h"
1413
#include "netbase.h"
1514
#include "serialize.h"
1615
#include "uint256.h"
@@ -19,6 +18,8 @@
1918
#include <stdint.h>
2019
#include <string>
2120

21+
#define MESSAGE_START_SIZE 4
22+
2223
/** Message header.
2324
* (4) message start.
2425
* (12) command.

0 commit comments

Comments
 (0)