-
Notifications
You must be signed in to change notification settings - Fork 0
/
chainparams.cpp
245 lines (212 loc) · 9.19 KB
/
chainparams.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The WolfTronCoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "assert.h"
#include "chainparams.h"
#include "core.h"
#include "protocol.h"
#include "util.h"
#include <boost/assign/list_of.hpp>
using namespace boost::assign;
//
// Main network
//
unsigned int pnSeed[] =
{
};
class CMainParams : public CChainParams {
public:
CMainParams() {
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
pchMessageStart[0] = 0xa0;
pchMessageStart[1] = 0xa2;
pchMessageStart[2] = 0xee;
pchMessageStart[3] = 0x6b;
vAlertPubKey = ParseHex("04c1cefc85550f2e95e8851b88368547f35e57d41a71b4b399b6e7b80464d8fa0bed119cf0a4bcb13bbd3c1187d0e22442e0c4889159ec9096686acc4cf85321ad");
nDefaultPort = 26853;
nRPCPort = 26854;
bnProofOfWorkLimit = CBigNum(~uint256(0) >> 32);
nSubsidyHalvingInterval = 840000;
// Build the genesis block. Note that the output of the genesis coinbase cannot
// be spent as it did not originally exist in the database.
//
// CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1510685233, nBits=1d00ffff, nNonce=0, vtx=1)
// CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
// CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
// CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
// vMerkleTree: 4a5e1e
const char* pszTimestamp = "14 NOV 2017";
CTransaction txNew;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.vout[0].nValue = 50 * COIN;
txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
genesis.vtx.push_back(txNew);
genesis.hashPrevBlock = 0;
genesis.hashMerkleRoot = genesis.BuildMerkleTree();
genesis.nVersion = 1;
genesis.nTime = 1510685233;
genesis.nBits = 0x1d00ffff;
genesis.nNonce = 3440633868;
hashGenesisBlock = genesis.GetHash();
if (false)
{
printf("Searching for genesis block...\n");
uint256 hashTarget = CBigNum().SetCompact(genesis.nBits).getuint256();
uint256 thash;
CBigNum bnTarget;
bnTarget.SetCompact(genesis.nBits);
while(1)
{
thash=genesis.GetHash();
if ((thash <= hashTarget) && (thash <= bnTarget.getuint256()) )
break;
if ((genesis.nNonce & 0xFFF) == 0)
{
printf("nonce %08X: hash = %s (target = %s)\n",genesis.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
}
++genesis.nNonce;
if (genesis.nNonce == 0)
{
printf("NONCE WRAPPED, incrementing time\n");
++genesis.nTime;
}
}
printf("genesis.nTime = %u \n",genesis.nTime);
printf("genesis.nNonce = %u \n",genesis.nNonce);
printf("min nBit: %08x\n", bnProofOfWorkLimit.GetCompact());
printf("genesis.hashMerkleRoot = %s\n",genesis.hashMerkleRoot.ToString().c_str());
printf("genesis.GetHash = %s\n",genesis.GetHash().ToString().c_str());
exit(1);
}
assert(hashGenesisBlock == uint256("0x00000000dc8b7e45939257aaf3681a57e52d21f839366944d93eb243c34313fb"));
assert(genesis.hashMerkleRoot == uint256("0x6acd6685e24623b1394b2c188015d9a0ee7fa0841168c5a4d2dd7bcffe12d418"));
vSeeds.push_back(CDNSSeedData("walletbuilders.com", "node.walletbuilders.com"));
vSeeds.push_back(CDNSSeedData("bitcoin.com", "wolftroncoin.bitcoin.com"));
base58Prefixes[PUBKEY_ADDRESS] = list_of(73);
base58Prefixes[SCRIPT_ADDRESS] = list_of(5);
base58Prefixes[SECRET_KEY] = list_of(201);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E);
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4);
// Convert the pnSeeds array into usable address objects.
for (unsigned int i = 0; i < ARRAYLEN(pnSeed); i++)
{
// It'll only connect to one or two seed nodes because once it connects,
// it'll get a pile of addresses with newer timestamps.
// Seed nodes are given a random 'last seen time' of between one and two
// weeks ago.
const int64 nOneWeek = 7*24*60*60;
struct in_addr ip;
memcpy(&ip, &pnSeed[i], sizeof(ip));
CAddress addr(CService(ip, GetDefaultPort()));
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
vFixedSeeds.push_back(addr);
}
}
virtual const CBlock& GenesisBlock() const { return genesis; }
virtual Network NetworkID() const { return CChainParams::MAIN; }
virtual const vector<CAddress>& FixedSeeds() const {
return vFixedSeeds;
}
protected:
CBlock genesis;
vector<CAddress> vFixedSeeds;
};
static CMainParams mainParams;
//
// Testnet (v3)
//
class CTestNetParams : public CMainParams {
public:
CTestNetParams() {
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
pchMessageStart[0] = 0xf5;
pchMessageStart[1] = 0xc3;
pchMessageStart[2] = 0xef;
pchMessageStart[3] = 0x5f;
vAlertPubKey = ParseHex("0454c273f2039a627a4c6d87b6510e718720bf513ee20b10a6d4535232b667773fd2e4a649548bf7db7803952df18ace59e62215cdd37828c9e8b0a2fc0df55238");
nDefaultPort = 36853;
nRPCPort = 36854;
strDataDir = "testnet3";
// Modify the testnet genesis block so the timestamp is valid for a later start.
genesis.nTime = 1510685233;
genesis.nNonce = 3440633868;
hashGenesisBlock = genesis.GetHash();
assert(hashGenesisBlock == uint256("0x00000000dc8b7e45939257aaf3681a57e52d21f839366944d93eb243c34313fb"));
vFixedSeeds.clear();
vSeeds.clear();
base58Prefixes[PUBKEY_ADDRESS] = list_of(111);
base58Prefixes[SCRIPT_ADDRESS] = list_of(196);
base58Prefixes[SECRET_KEY] = list_of(239);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF);
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94);
}
virtual Network NetworkID() const { return CChainParams::TESTNET; }
};
static CTestNetParams testNetParams;
//
// Regression test
//
class CRegTestParams : public CTestNetParams {
public:
CRegTestParams() {
pchMessageStart[0] = 0x86;
pchMessageStart[1] = 0xf3;
pchMessageStart[2] = 0x98;
pchMessageStart[3] = 0xf6;
nSubsidyHalvingInterval = 150;
bnProofOfWorkLimit = CBigNum(~uint256(0) >> 1);
genesis.nTime = 1510685233;
genesis.nBits = 0x207fffff;
genesis.nNonce = 2;
hashGenesisBlock = genesis.GetHash();
nDefaultPort = 18444;
strDataDir = "regtest";
//assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
}
virtual bool RequireRPCPassword() const { return false; }
virtual Network NetworkID() const { return CChainParams::REGTEST; }
};
static CRegTestParams regTestParams;
static CChainParams *pCurrentParams = &mainParams;
const CChainParams &Params() {
return *pCurrentParams;
}
void SelectParams(CChainParams::Network network) {
switch (network) {
case CChainParams::MAIN:
pCurrentParams = &mainParams;
break;
case CChainParams::TESTNET:
pCurrentParams = &testNetParams;
break;
case CChainParams::REGTEST:
pCurrentParams = ®TestParams;
break;
default:
assert(false && "Unimplemented network");
return;
}
}
bool SelectParamsFromCommandLine() {
bool fRegTest = GetBoolArg("-regtest", false);
bool fTestNet = GetBoolArg("-testnet", false);
if (fTestNet && fRegTest) {
return false;
}
if (fRegTest) {
SelectParams(CChainParams::REGTEST);
} else if (fTestNet) {
SelectParams(CChainParams::TESTNET);
} else {
SelectParams(CChainParams::MAIN);
}
return true;
}