Skip to content

Instantly share code, notes, and snippets.

@bellflower2015
Last active August 25, 2023 05:55
Show Gist options
  • Save bellflower2015/6f37c3722615be755efdf0f1d465e146 to your computer and use it in GitHub Desktop.
Save bellflower2015/6f37c3722615be755efdf0f1d465e146 to your computer and use it in GitHub Desktop.
Calculating Genesis Block
// ... snip ...
#include <arith_uint256.h>
// ... snip ...
class CMainParams : public CChainParams {
public:
CMainParams() {
// ... snip ...
genesis = CreateGenesisBlock(1534567890, 0, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = uint256S("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
if (true && (genesis.GetHash() != consensus.hashGenesisBlock)) {
std::cout << std::string("Begin calculating Mainnet Genesis Block:\n");
arith_uint256 hashTarget = arith_uint256().SetCompact(genesis.nBits);
uint256 hash;
genesis.nNonce = 0;
while (UintToArith256(genesis.GetHash()) > hashTarget) {
++genesis.nNonce;
if (genesis.nNonce == 0) {
std::cout << std::string("NONCE WRAPPED, incrementing time:\n");
++genesis.nTime;
}
if (genesis.nNonce % 1000 == 0) {
std::cout << strNetworkID << " nonce: " << genesis.nNonce << " time: " << genesis.nTime << " hash: " << genesis.GetHash().ToString().c_str() << "\n";
}
}
std::cout << "Mainnet ---\n";
std::cout << " nonce: " << genesis.nNonce << "\n";
std::cout << " time: " << genesis.nTime << "\n";
std::cout << " hash: " << genesis.GetHash().ToString().c_str() << "\n";
std::cout << " merklehash: " << genesis.hashMerkleRoot.ToString().c_str() << "\n";
std::cout << std::string("Finished calculating Mainnet Genesis Block:\n");
}
consensus.hashGenesisBlock = genesis.GetHash();
// ... snip ...
}
// ... snip ...
@Jolly-Pirate
Copy link

Exactly what I needed. Couldn't find a python tool for a custom new hash, and this snippet did the job. Thanks.

@bartgevers013
Copy link

you are my hero ;-))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment