forked from NicolasChoukroun/altcoin-genesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creategenesis.cpp
51 lines (44 loc) · 2.17 KB
/
creategenesis.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
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2014-2017 The Dash Core developers
// Copyright (c) 2017-2017 The Pura Core developers
// Copyright (c) 2018 Nicolas Choukroun
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//Mining algorithm
const arith_uint256 maxUint = UintToArith256(
uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
static void MineGenesis(CBlockHeader &genesisBlock, const uint256 &powLimit, bool noProduction) {
if (noProduction) genesisBlock.nTime = std::time(0);
genesisBlock.nNonce = 0;
printf("NOTE: Genesis nTime = %u \n", genesisBlock.nTime);
printf("WARN: Genesis nNonce (BLANK!) = %u \n", genesisBlock.nNonce);
arith_uint256 besthash;
memset(&besthash, 0xFF, 32);
arith_uint256 hashTarget = UintToArith256(powLimit);
printf("Target: %s\n", hashTarget.GetHex().c_str());
arith_uint256 newhash = UintToArith256(genesisBlock.GetHash());
while (newhash > hashTarget) {
genesisBlock.nNonce++;
if (genesisBlock.nNonce == 0) {
printf("NONCE WRAPPED, incrementing time\n");
++genesisBlock.nTime;
}
// If nothing found after trying for a while, print status
if ((genesisBlock.nNonce & 0xffff) == 0)
printf("nonce %08X: hash = %s \r",
genesisBlock.nNonce, newhash.ToString().c_str(),
hashTarget.ToString().c_str());
if (newhash < besthash) {
besthash = newhash;
printf("New best: %s\n", newhash.GetHex().c_str());
}
newhash = UintToArith256(genesisBlock.GetHash());
}
printf("\nGenesis nTime = %u \n", genesisBlock.nTime);
printf("Genesis nNonce = %u \n", genesisBlock.nNonce);
printf("Genesis nBits: %08x\n", genesisBlock.nBits);
printf("Genesis Hash = %s\n", newhash.ToString().c_str());
printf("Genesis Hash Merkle Root = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str());
printf("Genesis Hash Merkle Root = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str());
}