]>
Commit | Line | Data |
---|---|---|
0e4b3175 MH |
1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | // Copyright (c) 2009-2013 The Bitcoin developers | |
3 | // Distributed under the MIT/X11 software license, see the accompanying | |
4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
5 | ||
6 | #ifndef BITCOIN_CHAIN_PARAMS_H | |
7 | #define BITCOIN_CHAIN_PARAMS_H | |
8 | ||
0e4b3175 | 9 | #include "uint256.h" |
0e4b3175 MH |
10 | |
11 | #include <vector> | |
12 | ||
13 | using namespace std; | |
14 | ||
15 | #define MESSAGE_START_SIZE 4 | |
16 | typedef unsigned char MessageStartChars[MESSAGE_START_SIZE]; | |
17 | ||
18 | class CAddress; | |
19 | class CBlock; | |
20 | ||
21 | struct CDNSSeedData { | |
22 | string name, host; | |
23 | CDNSSeedData(const string &strName, const string &strHost) : name(strName), host(strHost) {} | |
24 | }; | |
25 | ||
26 | /** | |
27 | * CChainParams defines various tweakable parameters of a given instance of the | |
28 | * Bitcoin system. There are three: the main network on which people trade goods | |
29 | * and services, the public test network which gets reset from time to time and | |
30 | * a regression test mode which is intended for private networks only. It has | |
31 | * minimal difficulty to ensure that blocks can be found instantly. | |
32 | */ | |
33 | class CChainParams | |
34 | { | |
35 | public: | |
36 | enum Network { | |
37 | MAIN, | |
38 | TESTNET, | |
39 | REGTEST, | |
b94595bb GA |
40 | |
41 | MAX_NETWORK_TYPES | |
0e4b3175 MH |
42 | }; |
43 | ||
44 | enum Base58Type { | |
45 | PUBKEY_ADDRESS, | |
46 | SCRIPT_ADDRESS, | |
47 | SECRET_KEY, | |
eb2c9990 PW |
48 | EXT_PUBLIC_KEY, |
49 | EXT_SECRET_KEY, | |
0e4b3175 MH |
50 | |
51 | MAX_BASE58_TYPES | |
52 | }; | |
53 | ||
54 | const uint256& HashGenesisBlock() const { return hashGenesisBlock; } | |
55 | const MessageStartChars& MessageStart() const { return pchMessageStart; } | |
56 | const vector<unsigned char>& AlertKey() const { return vAlertPubKey; } | |
57 | int GetDefaultPort() const { return nDefaultPort; } | |
df9eb5e1 | 58 | const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; } |
0e4b3175 MH |
59 | int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; } |
60 | virtual const CBlock& GenesisBlock() const = 0; | |
61 | virtual bool RequireRPCPassword() const { return true; } | |
1712adbe | 62 | /* Make miner wait to have peers to avoid wasting work */ |
63 | virtual bool MiningRequiresPeers() const { return true; } | |
0e4b3175 MH |
64 | const string& DataDir() const { return strDataDir; } |
65 | virtual Network NetworkID() const = 0; | |
66 | const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; } | |
8388289e | 67 | const std::vector<unsigned char> &Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } |
0e4b3175 MH |
68 | virtual const vector<CAddress>& FixedSeeds() const = 0; |
69 | int RPCPort() const { return nRPCPort; } | |
70 | protected: | |
96b9603c | 71 | CChainParams() {} |
0e4b3175 MH |
72 | |
73 | uint256 hashGenesisBlock; | |
74 | MessageStartChars pchMessageStart; | |
75 | // Raw pub key bytes for the broadcast alert signing key. | |
76 | vector<unsigned char> vAlertPubKey; | |
77 | int nDefaultPort; | |
78 | int nRPCPort; | |
df9eb5e1 | 79 | uint256 bnProofOfWorkLimit; |
0e4b3175 MH |
80 | int nSubsidyHalvingInterval; |
81 | string strDataDir; | |
82 | vector<CDNSSeedData> vSeeds; | |
8388289e | 83 | std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES]; |
0e4b3175 MH |
84 | }; |
85 | ||
86 | /** | |
87 | * Return the currently selected parameters. This won't change after app startup | |
88 | * outside of the unit tests. | |
89 | */ | |
90 | const CChainParams &Params(); | |
91 | ||
92 | /** Sets the params returned by Params() to those for the given network. */ | |
93 | void SelectParams(CChainParams::Network network); | |
94 | ||
95 | /** | |
96 | * Looks for -regtest or -testnet and then calls SelectParams as appropriate. | |
97 | * Returns false if an invalid combination is given. | |
98 | */ | |
99 | bool SelectParamsFromCommandLine(); | |
100 | ||
101 | inline bool TestNet() { | |
102 | // Note: it's deliberate that this returns "false" for regression test mode. | |
103 | return Params().NetworkID() == CChainParams::TESTNET; | |
104 | } | |
105 | ||
2461aba1 PW |
106 | inline bool RegTest() { |
107 | return Params().NetworkID() == CChainParams::REGTEST; | |
108 | } | |
109 | ||
0e4b3175 | 110 | #endif |