Files
altcoin-genesis/creategenesis.cpp
2018-12-17 21:58:44 +07:00

51 lines
2.1 KiB
C++

// 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
// 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("Genesis 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());
}