int nBits, unsigned int nTimeBlockFrom, - unsigned int& nTimeTx, uint256& hashProofOfStake) bool stakeTargetHit(uint256 hashProofOfStake, int64_t nValueIn, uint256 bnTargetPerCoinDay) { //get the stake weight - weight is equal to coin amount uint256 bnCoinDayWeight = uint256(nValueIn) / 100; // Now check if proof-of-stake hash meets target protocol bool res = hashProofOfStake < (bnCoinDayWeight * bnTargetPerCoinDay); return res; } bool CheckStake(const CDataStream& ssUniqueID, CAmount nValueIn, const uint64_t nStakeModifier, const uint256& bnTarget, unsigned int nTimeBlockFrom, unsigned int& nTimeTx, uint256& hashProofOfStake) { CDataStream ss(SER_GETHASH, 0); ss << nStakeModifier << nTimeBlockFrom << ssUniqueID << nTimeTx; hashProofOfStake = Hash(ss.begin(), ss.end()); return stakeTargetHit(hashProofOfStake, nValueIn, bnTarget); } bool Stake(CStakeInput* stakeInput, unsigned int nBits, unsigned int nTimeBlockFrom, unsigned int& nTimeTx, uint256& hashProofOfStake) { //grab difficulty uint256 bnTargetPerCoinDay; bnTargetPerCoinDay.SetCompact(nBits); //grab stake modifier uint64_t nStakeModifier = 0; if (!stakeInput->GetModifier(nStakeModifier)) return error("failed to get kernel stake modifier"); CDataStream ssUniqueID = stakeInput->GetUniqueness(); CAmount nValueIn = stakeInput->GetValue(); for (int i = 0; i < nHashDrift; i++) //iterate the hashing { if (!CheckStake(ssUniqueID, nValueIn, nStakeModifier, bnTargetPerCoinDay, nTimeBlockFrom, nTryTime, hashProofOfStake)) continue; fSuccess = true; // if we make it this far then we have successfully created a stake hash } return fSuccess; }