From 464e20b92fdbcd57206868939faac8aa618d9eaa Mon Sep 17 00:00:00 2001 From: Nikko <40539492+Nikkoid@users.noreply.github.com> Date: Sun, 9 Dec 2018 00:01:10 +0700 Subject: [PATCH] Initial commit This function generate the genesis for any coin. --- creategenesis.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 creategenesis.cpp diff --git a/creategenesis.cpp b/creategenesis.cpp new file mode 100644 index 0000000..aaf6555 --- /dev/null +++ b/creategenesis.cpp @@ -0,0 +1,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 +// 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 \n(target = %s)\n", + 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()); +} +