1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_CHAINPARAMS_H
7 #define BITCOIN_CHAINPARAMS_H
9 #include "chainparamsbase.h"
10 #include "checkpoints.h"
11 #include "core/block.h"
17 typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
20 std::string name, host;
21 CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
25 * CChainParams defines various tweakable parameters of a given instance of the
26 * Bitcoin system. There are three: the main network on which people trade goods
27 * and services, the public test network which gets reset from time to time and
28 * a regression test mode which is intended for private networks only. It has
29 * minimal difficulty to ensure that blocks can be found instantly.
44 const uint256& HashGenesisBlock() const { return hashGenesisBlock; }
45 const MessageStartChars& MessageStart() const { return pchMessageStart; }
46 const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
47 int GetDefaultPort() const { return nDefaultPort; }
48 const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
49 int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
50 /** Used to check majorities for block version upgrade */
51 int EnforceBlockUpgradeMajority() const { return nEnforceBlockUpgradeMajority; }
52 int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; }
53 int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; }
55 /** Used if GenerateBitcoins is called with a negative number of threads */
56 int DefaultMinerThreads() const { return nMinerThreads; }
57 const CBlock& GenesisBlock() const { return genesis; }
58 bool RequireRPCPassword() const { return fRequireRPCPassword; }
59 /** Make miner wait to have peers to avoid wasting work */
60 bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
61 /** Default value for -checkmempool argument */
62 bool DefaultCheckMemPool() const { return fDefaultCheckMemPool; }
63 /** Allow mining of a min-difficulty block */
64 bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
65 /** Skip proof-of-work check: allow mining of any difficulty block */
66 bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; }
67 /** Make standard checks */
68 bool RequireStandard() const { return fRequireStandard; }
69 int64_t TargetTimespan() const { return nTargetTimespan; }
70 int64_t TargetSpacing() const { return nTargetSpacing; }
71 int64_t Interval() const { return nTargetTimespan / nTargetSpacing; }
72 /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
73 bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
74 /** In the future use NetworkIDString() for RPC fields */
75 bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
76 /** Return the BIP70 network string (main, test or regtest) */
77 std::string NetworkIDString() const { return strNetworkID; }
78 const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
79 const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
80 const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
81 virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
85 uint256 hashGenesisBlock;
86 MessageStartChars pchMessageStart;
87 //! Raw pub key bytes for the broadcast alert signing key.
88 std::vector<unsigned char> vAlertPubKey;
90 uint256 bnProofOfWorkLimit;
91 int nSubsidyHalvingInterval;
92 int nEnforceBlockUpgradeMajority;
93 int nRejectBlockOutdatedMajority;
94 int nToCheckBlockUpgradeMajority;
95 int64_t nTargetTimespan;
96 int64_t nTargetSpacing;
98 std::vector<CDNSSeedData> vSeeds;
99 std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
100 CBaseChainParams::Network networkID;
101 std::string strNetworkID;
103 std::vector<CAddress> vFixedSeeds;
104 bool fRequireRPCPassword;
105 bool fMiningRequiresPeers;
106 bool fDefaultCheckMemPool;
107 bool fAllowMinDifficultyBlocks;
108 bool fRequireStandard;
109 bool fMineBlocksOnDemand;
110 bool fSkipProofOfWorkCheck;
111 bool fTestnetToBeDeprecatedFieldRPC;
115 * Modifiable parameters interface is used by test cases to adapt the parameters in order
116 * to test specific features more easily. Test cases should always restore the previous
117 * values after finalization.
120 class CModifiableParams {
122 //! Published setters to allow changing values in unit test cases
123 virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) =0;
124 virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority)=0;
125 virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority)=0;
126 virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority)=0;
127 virtual void setDefaultCheckMemPool(bool aDefaultCheckMemPool)=0;
128 virtual void setAllowMinDifficultyBlocks(bool aAllowMinDifficultyBlocks)=0;
129 virtual void setSkipProofOfWorkCheck(bool aSkipProofOfWorkCheck)=0;
134 * Return the currently selected parameters. This won't change after app startup
135 * outside of the unit tests.
137 const CChainParams &Params();
139 /** Return parameters for the given network. */
140 CChainParams &Params(CBaseChainParams::Network network);
142 /** Get modifiable network parameters (UNITTEST only) */
143 CModifiableParams *ModifiableParams();
145 /** Sets the params returned by Params() to those for the given network. */
146 void SelectParams(CBaseChainParams::Network network);
149 * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
150 * Returns false if an invalid combination is given.
152 bool SelectParamsFromCommandLine();
154 #endif // BITCOIN_CHAINPARAMS_H