1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_CHAINPARAMS_H
7 #define BITCOIN_CHAINPARAMS_H
8 
9 #include "chainparamsbase.h"
10 #include "consensus/params.h"
11 #include "primitives/block.h"
12 #include "protocol.h"
13 
14 #include <vector>
15 
16 struct CDNSSeedData {
17     std::string name, host;
18     bool supportsServiceBitsFiltering;
nameCDNSSeedData19     CDNSSeedData(const std::string &strName, const std::string &strHost, bool supportsServiceBitsFilteringIn = false) : name(strName), host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
20 };
21 
22 struct SeedSpec6 {
23     uint8_t addr[16];
24     uint16_t port;
25 };
26 
27 typedef std::map<int, uint256> MapCheckpoints;
28 
29 struct CCheckpointData {
30     MapCheckpoints mapCheckpoints;
31     int64_t nTimeLastCheckpoint;
32     int64_t nTransactionsLastCheckpoint;
33     double fTransactionsPerDay;
34 };
35 
36 /**
37  * CChainParams defines various tweakable parameters of a given instance of the
38  * Bitcoin system. There are three: the main network on which people trade goods
39  * and services, the public test network which gets reset from time to time and
40  * a regression test mode which is intended for private networks only. It has
41  * minimal difficulty to ensure that blocks can be found instantly.
42  */
43 class CChainParams
44 {
45 public:
46     enum Base58Type {
47         PUBKEY_ADDRESS,
48         SCRIPT_ADDRESS,
49         SECRET_KEY,
50         EXT_PUBLIC_KEY,
51         EXT_SECRET_KEY,
52 
53         MAX_BASE58_TYPES
54     };
55 
GetConsensus()56     const Consensus::Params& GetConsensus() const { return consensus; }
MessageStart()57     const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
GetDefaultPort()58     int GetDefaultPort() const { return nDefaultPort; }
59 
GenesisBlock()60     const CBlock& GenesisBlock() const { return genesis; }
61     /** Make miner wait to have peers to avoid wasting work */
MiningRequiresPeers()62     bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
63     /** Default value for -checkmempool and -checkblockindex argument */
DefaultConsistencyChecks()64     bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
65     /** Policy: Filter transactions that do not match well-defined patterns */
RequireStandard()66     bool RequireStandard() const { return fRequireStandard; }
PruneAfterHeight()67     uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
68     /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
MineBlocksOnDemand()69     bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
70     /** In the future use NetworkIDString() for RPC fields */
TestnetToBeDeprecatedFieldRPC()71     bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
72     /** Return the BIP70 network string (main, test or regtest) */
NetworkIDString()73     std::string NetworkIDString() const { return strNetworkID; }
DNSSeeds()74     const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
Base58Prefix(Base58Type type)75     const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
FixedSeeds()76     const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
Checkpoints()77     const CCheckpointData& Checkpoints() const { return checkpointData; }
78 protected:
CChainParams()79     CChainParams() {}
80 
81     Consensus::Params consensus;
82     CMessageHeader::MessageStartChars pchMessageStart;
83     int nDefaultPort;
84     uint64_t nPruneAfterHeight;
85     std::vector<CDNSSeedData> vSeeds;
86     std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
87     std::string strNetworkID;
88     CBlock genesis;
89     std::vector<SeedSpec6> vFixedSeeds;
90     bool fMiningRequiresPeers;
91     bool fDefaultConsistencyChecks;
92     bool fRequireStandard;
93     bool fMineBlocksOnDemand;
94     bool fTestnetToBeDeprecatedFieldRPC;
95     CCheckpointData checkpointData;
96 };
97 
98 /**
99  * Return the currently selected parameters. This won't change after app
100  * startup, except for unit tests.
101  */
102 const CChainParams &Params();
103 
104 /**
105  * @returns CChainParams for the given BIP70 chain name.
106  */
107 CChainParams& Params(const std::string& chain);
108 
109 /**
110  * Sets the params returned by Params() to those for the given BIP70 chain name.
111  * @throws std::runtime_error when the chain is not supported.
112  */
113 void SelectParams(const std::string& chain);
114 
115 /**
116  * Allows modifying the BIP9 regtest parameters.
117  */
118 void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout);
119 
120 #endif // BITCOIN_CHAINPARAMS_H
121