Created
January 25, 2017 18:01
-
-
Save brianonn/ba028186e2bbcfb5193be4d93efa2cf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main.cpp b/src/main.cpp | |
index 37ad1db..905a14d 100644 | |
--- a/src/main.cpp | |
+++ b/src/main.cpp | |
@@ -2951,6 +2951,42 @@ bool InitBlockIndex() { | |
printf("Got: block.GetHash() = %s\n", hash.ToString().c_str()); | |
printf("Got: block.hashMerkleRoot = %s\n", block.hashMerkleRoot.ToString().c_str()); | |
+ // BEGIN MINING THE GENESISBLOCK | |
+ // If genesis block hash does not match, then generate new genesis hash. | |
+ if (GetBoolArg("-genesis", false) && block.GetHash() != hashGenesisBlock) | |
+ { | |
+ printf("Searching for genesis block...\n"); | |
+ // This will figure out a valid hash and Nonce if you're | |
+ // creating a different genesis block: | |
+ uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256(); | |
+ uint256 thisHash; | |
+ block.nNonce = GetRandInt(0xffff0000); | |
+ while(true) | |
+ { | |
+ thisHash = block.GetHash(); | |
+ if (thisHash <= hashTarget) | |
+ // FOUND ONE! | |
+ break; | |
+ if ((block.nNonce & 0xFFF) == 0) | |
+ printf("nonce %08X: hash = %s\n" | |
+ " target = %s\n", | |
+ block.nNonce, | |
+ thisHash.ToString().c_str(), | |
+ hashTarget.ToString().c_str()); | |
+ ++block.nNonce; | |
+ if (block.nNonce == 0) | |
+ { | |
+ printf("NONCE WRAPPED, incrementing time\n"); | |
+ ++block.nTime; | |
+ } | |
+ } | |
+ printf("block.nTime = %u \n", block.nTime); | |
+ printf("block.nNonce = %u \n", block.nNonce); | |
+ printf("block.GetHash = %s\n", block.GetHash().ToString().c_str()); | |
+ } | |
+ // END MINING THE GENESISBLOCK | |
+ | |
+ | |
block.print(); | |
assert(block.hashMerkleRoot == genesisMerkleRoot); | |
assert(hash == hashGenesisBlock); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment