uint256 Tx::createHash() const { CHash256 ctx; ctx.Write((const unsigned char*) m_data.begin(), m_data.size()); uint256 result; ctx.Finalize((unsigned char*)&result); return result; }
// SYSCOIN generate block // This will figure out a valid hash and Nonce if you're // creating a different genesis block: static bool GenerateGenesisBlock(CBlockHeader &genesisBlock, uint256 *phash) { // Write the first 76 bytes of the block header to a double-SHA256 state. genesisBlock.nTime = time(NULL); CHash256 hasher; CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss << genesisBlock; assert(ss.size() == 80); hasher.Write((unsigned char*)&ss[0], 76); arith_uint256 hashTarget = arith_uint256().SetCompact(genesisBlock.nBits); while (true) { // Write the last 4 bytes of the block header (the nonce) to a copy of // the double-SHA256 state, and compute the result. CHash256(hasher).Write((unsigned char*)&genesisBlock.nNonce, 4).Finalize((unsigned char*)phash); // Return the nonce if the hash has at least some zero bits, // check if it has enough to reach the target if (((uint16_t*)phash)[15] == 0 && UintToArith256(*phash) <= hashTarget) break; genesisBlock.nNonce++; if (genesisBlock.nNonce == 0) { printf("NONCE WRAPPED, incrementing time\n"); ++genesisBlock.nTime; } // If nothing found after trying for a while, return -1 if ((genesisBlock.nNonce & 0xfff) == 0) printf("nonce %08X: hash = %s (target = %s)\n", genesisBlock.nNonce, (*phash).ToString().c_str(), hashTarget.ToString().c_str()); } printf("genesis.nTime = %u \n", genesisBlock.nTime); printf("genesis.nNonce = %u \n", genesisBlock.nNonce); printf("Generate hash = %s\n", (*phash).ToString().c_str()); printf("genesis.hashMerkleRoot = %s\n", genesisBlock.hashMerkleRoot.ToString().c_str()); }