如何生成创世块
What I did so far:
Change pszTimestamp to a sentence fromnewspaper
change block.nTime to current time
compile
run compiled source with -testnet -noirc
now u see some lines and a crash Code: b115383690ee67ebeef9a7e754342638cd7bbf488561998e6d1bc1ed367484f6// Block derived from pszTimestamp
b8fa883689f099d3942ff73439d9f55d60a5e257b0d69a8f0f6ab4572ecff415 //Genesisblock (invalid cuz its already coded wrong)
bd58bf217abb76059de07dc519f6c3dcdf5b1a7bb9219a66d24205e08f3716f9 // MerkleRoot(Valid because its newly calculated
corresponding to code:
Code: //// debug print
printf("%s\n",block.GetHash().ToString().c_str());
printf("%s\n",hashGenesisBlock.ToString().c_str());
printf("%s\n",block.hashMerkleRoot.ToString().c_str());
assert(block.hashMerkleRoot ==uint256("0xbd58bf217abb76059de07dc519f6c3dcdf5b1a7bb9219a66d24205e08f3716f9"));
update main.cpp with the mentioned merkleroot(it crashed because of the last assert) and run again
you should have already changed the false totrue in
Code: // If genesisblock hash does not match, then generate new genesis hash.
if (true && block.GetHash() !=hashGenesisBlock)
so it will find a genesis block for yourstring
after a long time you get:
Code: nonce 003C1000: hash =e8525d8ae8a74a33dbc4b06a64c97ced84dfd29628b3e9e4197c7030cc4a09d3 (target =00000ffff0000000000000000000000000000000000000000000000000000000)
block.nTime = 1367704866
block.nNonce = 3939341
block.GetHash =fafdbfc957ea6867a0743ff80c4ae126c7dd9fa82057255228a4d58f6ccfdf33
CBlock(hash=fafdbfc957ea6867a074, PoW=000000b1398554a520b5, ver=1,hashPrevBlock=00000000000000000000, hashMerkleRoot=bd58bf217a,nTime=1367704866, nBits=1e0ffff0, nNonce=3939341, vtx=1)
CTransaction(hash=bd58bf217a, ver=1, vin.size=1, vout.size=1,nLockTime=0)
CTxIn(COutPoint(0000000000, -1), coinbase04ffff001d01043741442e6e6c20342f352042657672696a64696e6773646167207a6f6e6e69672c20646161726e61206f6f6b207a6f6d657273207761726d)
CTxOut(error)
vMerkleTree: bd58bf217a
xx: main.cpp:2070: bool LoadBlockIndex(bool): Assertion `block.GetHash() ==hashGenesisBlock' failed.
Aborted (core dumped)
Now you have the valid Genesisblock andnNonce:
block.nNonce = 3939341
block.GetHash =fafdbfc957ea6867a0743ff80c4ae126c7dd9fa82057255228a4d58f6ccfdf33
Update your code with these values and yourready to go!
|