| 162 | } |
| 163 | |
| 164 | void ShuffleDelegates(const int32_t curHeight, const int64_t blockTime, VoteDelegateVector &delegates) { |
| 165 | |
| 166 | int64_t oriSeed = GetShuffleOriginSeed( curHeight,blockTime ); |
| 167 | auto totalDelegateNum = delegates.size(); |
| 168 | |
| 169 | string seedSource = strprintf("%u", oriSeed / totalDelegateNum + (oriSeed % totalDelegateNum > 0 ? 1 : 0)); |
| 170 | CHashWriter ss(SER_GETHASH, 0); |
| 171 | ss << seedSource; |
| 172 | uint256 currentSeed = ss.GetHash(); |
| 173 | uint64_t newIndexSource = 0; |
| 174 | for (uint32_t i = 0; i < totalDelegateNum; i++) { |
| 175 | for (uint32_t x = 0; x < 4 && i < totalDelegateNum; i++, x++) { |
| 176 | memcpy(&newIndexSource, currentSeed.begin() + (x * 8), 8); |
| 177 | uint32_t newIndex = newIndexSource % totalDelegateNum; |
| 178 | VoteDelegate delegate = delegates[newIndex]; |
| 179 | delegates[newIndex] = delegates[i]; |
| 180 | delegates[i] = delegate; |
| 181 | } |
| 182 | ss << currentSeed; |
| 183 | currentSeed = ss.GetHash(); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | bool VerifyRewardTx(const CBlock *pBlock, CCacheWrapper &cwIn, VoteDelegate &curDelegateOut, uint32_t& totalDelegateNumOut) { |
no test coverage detected