Skip to content

Instantly share code, notes, and snippets.

@progmax
Created March 20, 2018 11:16
Show Gist options
  • Save progmax/1f67d18117d11ceed16efd2e53c758cc to your computer and use it in GitHub Desktop.
Save progmax/1f67d18117d11ceed16efd2e53c758cc to your computer and use it in GitHub Desktop.
// calculate Genesis Block
// Reset genesis
consensus.hashGenesisBlock = uint256S("0x");
std::cout << std::string("Begin calculating Mainnet Genesis Block:\n");
if (true && (genesis.GetHash() != consensus.hashGenesisBlock)) {
LogPrintf("Calculating Mainnet Genesis Block:\n");
arith_uint256 hashTarget = arith_uint256().SetCompact(genesis.nBits);
uint256 hash;
genesis.nNonce = 0;
// This will figure out a valid hash and Nonce if you're
// creating a different genesis block:
//uint256 hashTarget = CBigNum().SetCompact(genesis.nBits).getuint256();
// hashTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow).getuint256();
// while (genesis.GetHash() > hashTarget)
while (UintToArith256(genesis.GetHash()) > hashTarget)
{
++genesis.nNonce;
if (genesis.nNonce == 0)
{
LogPrintf("NONCE WRAPPED, incrementing time");
std::cout << std::string("NONCE WRAPPED, incrementing time:\n");
++genesis.nTime;
}
if (genesis.nNonce % 10000 == 0)
{
LogPrintf("Mainnet: nonce %08u: hash = %s \n", genesis.nNonce, genesis.GetHash().ToString().c_str());
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");
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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment