You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chainparams.cpp 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // Copyright (c) 2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2014 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. #include "chainparams.h"
  6. #include "random.h"
  7. #include "util.h"
  8. #include <assert.h>
  9. #include <boost/assign/list_of.hpp>
  10. using namespace std;
  11. using namespace boost::assign;
  12. struct SeedSpec6 {
  13. uint8_t addr[16];
  14. uint16_t port;
  15. };
  16. #include "chainparamsseeds.h"
  17. //
  18. // Main network
  19. //
  20. // Convert the pnSeeds6 array into usable address objects.
  21. static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count)
  22. {
  23. // It'll only connect to one or two seed nodes because once it connects,
  24. // it'll get a pile of addresses with newer timestamps.
  25. // Seed nodes are given a random 'last seen time' of between one and two
  26. // weeks ago.
  27. const int64_t nOneWeek = 7*24*60*60;
  28. for (unsigned int i = 0; i < count; i++)
  29. {
  30. struct in6_addr ip;
  31. memcpy(&ip, data[i].addr, sizeof(ip));
  32. CAddress addr(CService(ip, data[i].port));
  33. addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
  34. vSeedsOut.push_back(addr);
  35. }
  36. }
  37. class CMainParams : public CChainParams {
  38. public:
  39. CMainParams() {
  40. networkID = CBaseChainParams::MAIN;
  41. strNetworkID = "main";
  42. // The message start string is designed to be unlikely to occur in normal data.
  43. // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
  44. // a large 4-byte int at any alignment.
  45. pchMessageStart[0] = 0xf9;
  46. pchMessageStart[1] = 0xbe;
  47. pchMessageStart[2] = 0xb4;
  48. pchMessageStart[3] = 0xd9;
  49. vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
  50. nDefaultPort = 8333;
  51. bnProofOfWorkLimit = ~uint256(0) >> 32;
  52. nSubsidyHalvingInterval = 210000;
  53. nEnforceBlockUpgradeMajority = 750;
  54. nRejectBlockOutdatedMajority = 950;
  55. nToCheckBlockUpgradeMajority = 1000;
  56. nMinerThreads = 0;
  57. nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  58. nTargetSpacing = 10 * 60;
  59. // Build the genesis block. Note that the output of the genesis coinbase cannot
  60. // be spent as it did not originally exist in the database.
  61. //
  62. // CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
  63. // CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
  64. // CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
  65. // CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
  66. // vMerkleTree: 4a5e1e
  67. const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
  68. CMutableTransaction txNew;
  69. txNew.vin.resize(1);
  70. txNew.vout.resize(1);
  71. txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
  72. txNew.vout[0].nValue = 50 * COIN;
  73. txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
  74. genesis.vtx.push_back(txNew);
  75. genesis.hashPrevBlock = 0;
  76. genesis.hashMerkleRoot = genesis.BuildMerkleTree();
  77. genesis.nVersion = 1;
  78. genesis.nTime = 1231006505;
  79. genesis.nBits = 0x1d00ffff;
  80. genesis.nNonce = 2083236893;
  81. hashGenesisBlock = genesis.GetHash();
  82. assert(hashGenesisBlock == uint256("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
  83. assert(genesis.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
  84. vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be"));
  85. vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me"));
  86. vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.bitcoin.dashjr.org"));
  87. vSeeds.push_back(CDNSSeedData("bitcoinstats.com", "seed.bitcoinstats.com"));
  88. vSeeds.push_back(CDNSSeedData("bitnodes.io", "seed.bitnodes.io"));
  89. vSeeds.push_back(CDNSSeedData("xf2.org", "bitseed.xf2.org"));
  90. base58Prefixes[PUBKEY_ADDRESS] = list_of(0);
  91. base58Prefixes[SCRIPT_ADDRESS] = list_of(5);
  92. base58Prefixes[SECRET_KEY] = list_of(128);
  93. base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E);
  94. base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4);
  95. convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main));
  96. fRequireRPCPassword = true;
  97. fMiningRequiresPeers = true;
  98. fDefaultCheckMemPool = false;
  99. fAllowMinDifficultyBlocks = false;
  100. fRequireStandard = true;
  101. fMineBlocksOnDemand = false;
  102. }
  103. };
  104. static CMainParams mainParams;
  105. //
  106. // Testnet (v3)
  107. //
  108. class CTestNetParams : public CMainParams {
  109. public:
  110. CTestNetParams() {
  111. networkID = CBaseChainParams::TESTNET;
  112. strNetworkID = "test";
  113. // The message start string is designed to be unlikely to occur in normal data.
  114. // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
  115. // a large 4-byte int at any alignment.
  116. pchMessageStart[0] = 0x0b;
  117. pchMessageStart[1] = 0x11;
  118. pchMessageStart[2] = 0x09;
  119. pchMessageStart[3] = 0x07;
  120. vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
  121. nDefaultPort = 18333;
  122. nEnforceBlockUpgradeMajority = 51;
  123. nRejectBlockOutdatedMajority = 75;
  124. nToCheckBlockUpgradeMajority = 100;
  125. nMinerThreads = 0;
  126. nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  127. nTargetSpacing = 10 * 60;
  128. // Modify the testnet genesis block so the timestamp is valid for a later start.
  129. genesis.nTime = 1296688602;
  130. genesis.nNonce = 414098458;
  131. hashGenesisBlock = genesis.GetHash();
  132. assert(hashGenesisBlock == uint256("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
  133. vFixedSeeds.clear();
  134. vSeeds.clear();
  135. vSeeds.push_back(CDNSSeedData("alexykot.me", "testnet-seed.alexykot.me"));
  136. vSeeds.push_back(CDNSSeedData("bitcoin.petertodd.org", "testnet-seed.bitcoin.petertodd.org"));
  137. vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me"));
  138. vSeeds.push_back(CDNSSeedData("bitcoin.schildbach.de", "testnet-seed.bitcoin.schildbach.de"));
  139. base58Prefixes[PUBKEY_ADDRESS] = list_of(111);
  140. base58Prefixes[SCRIPT_ADDRESS] = list_of(196);
  141. base58Prefixes[SECRET_KEY] = list_of(239);
  142. base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF);
  143. base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94);
  144. convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test));
  145. fRequireRPCPassword = true;
  146. fMiningRequiresPeers = true;
  147. fDefaultCheckMemPool = false;
  148. fAllowMinDifficultyBlocks = true;
  149. fRequireStandard = false;
  150. fMineBlocksOnDemand = false;
  151. }
  152. };
  153. static CTestNetParams testNetParams;
  154. //
  155. // Regression test
  156. //
  157. class CRegTestParams : public CTestNetParams {
  158. public:
  159. CRegTestParams() {
  160. networkID = CBaseChainParams::REGTEST;
  161. strNetworkID = "regtest";
  162. pchMessageStart[0] = 0xfa;
  163. pchMessageStart[1] = 0xbf;
  164. pchMessageStart[2] = 0xb5;
  165. pchMessageStart[3] = 0xda;
  166. nSubsidyHalvingInterval = 150;
  167. nEnforceBlockUpgradeMajority = 750;
  168. nRejectBlockOutdatedMajority = 950;
  169. nToCheckBlockUpgradeMajority = 1000;
  170. nMinerThreads = 1;
  171. nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  172. nTargetSpacing = 10 * 60;
  173. bnProofOfWorkLimit = ~uint256(0) >> 1;
  174. genesis.nTime = 1296688602;
  175. genesis.nBits = 0x207fffff;
  176. genesis.nNonce = 2;
  177. hashGenesisBlock = genesis.GetHash();
  178. nDefaultPort = 18444;
  179. assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
  180. vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
  181. fRequireRPCPassword = false;
  182. fMiningRequiresPeers = false;
  183. fDefaultCheckMemPool = true;
  184. fAllowMinDifficultyBlocks = true;
  185. fRequireStandard = false;
  186. fMineBlocksOnDemand = true;
  187. }
  188. };
  189. static CRegTestParams regTestParams;
  190. static CChainParams *pCurrentParams = 0;
  191. const CChainParams &Params() {
  192. assert(pCurrentParams);
  193. return *pCurrentParams;
  194. }
  195. void SelectParams(CBaseChainParams::Network network) {
  196. SelectBaseParams(network);
  197. switch (network) {
  198. case CBaseChainParams::MAIN:
  199. pCurrentParams = &mainParams;
  200. break;
  201. case CBaseChainParams::TESTNET:
  202. pCurrentParams = &testNetParams;
  203. break;
  204. case CBaseChainParams::REGTEST:
  205. pCurrentParams = &regTestParams;
  206. break;
  207. default:
  208. assert(false && "Unimplemented network");
  209. return;
  210. }
  211. }
  212. bool SelectParamsFromCommandLine() {
  213. if (!SelectBaseParamsFromCommandLine())
  214. return false;
  215. SelectParams(BaseParams().NetworkID());
  216. return true;
  217. }