| 229 | |
| 230 | |
| 231 | extern Value getminerbyblocktime(const Array& params, bool fHelp) { |
| 232 | if (fHelp || params.size() != 2) { |
| 233 | throw runtime_error( |
| 234 | "getminerbyblocktime height time\n" |
| 235 | "\ncalculate the miner of block by time." |
| 236 | "\nArguments:\n" |
| 237 | "1. height (numeric, required) block height,\n" |
| 238 | "2. time (numeric, required) block time,\n" |
| 239 | "\nResult:\n" |
| 240 | "{\n" |
| 241 | " \"miner_regid\": n (numeric) block time\n" |
| 242 | " \"miner_addr\": n (numeric) block height\n" |
| 243 | " \"top_idx\": n (numeric) block nonce\n" |
| 244 | "}\n" |
| 245 | "\nExamples:\n" + |
| 246 | HelpExampleCli("getminerbyblocktime", "100 1571039490") + "\nAs json rpc call\n" + |
| 247 | HelpExampleRpc("getminerbyblocktime", "100, 1571039490")); |
| 248 | } |
| 249 | |
| 250 | int64_t blockHeight = params[0].get_int64(); |
| 251 | int64_t blockTime = params[1].get_int64(); |
| 252 | |
| 253 | if (blockHeight <= 0) { |
| 254 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("invalid blockHeight=%lld <= 0\n", blockHeight)); |
| 255 | } |
| 256 | |
| 257 | if (blockTime <= 0) { |
| 258 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("invalid blockTime=%lld <= 0\n", blockTime)); |
| 259 | } |
| 260 | |
| 261 | VoteDelegateVector delegates; |
| 262 | if (!pCdMan->pDelegateCache->GetActiveDelegates(delegates)) { |
| 263 | LogPrint(BCLog::ERROR, "GetActiveDelegates failed\n"); |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | uint16_t index = 0; |
| 268 | for (auto &delegate : delegates) |
| 269 | LogPrint(BCLog::DEBUG, "[%d] before shuffle: index=%d, regId=%s\n", blockHeight, index++, delegate.regid.ToString()); |
| 270 | |
| 271 | ShuffleDelegates(blockHeight, blockTime, delegates); |
| 272 | |
| 273 | index = 0; |
| 274 | for (auto &delegate : delegates) |
| 275 | LogPrint(BCLog::DEBUG, "[%d] after shuffle: index=%d, regId=%s\n", blockHeight, index++, delegate.regid.ToString()); |
| 276 | |
| 277 | CRegID regid; |
| 278 | VoteDelegate curDelegate; |
| 279 | GetCurrentDelegate(blockTime, blockHeight, delegates, curDelegate); |
| 280 | |
| 281 | index = 0; |
| 282 | for (; index < delegates.size(); index++) { |
| 283 | if (delegates.at(index).regid == curDelegate.regid) { |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | if (index >= delegates.size()) |
| 288 | throw JSONRPCError(RPC_INVALID_PARAMETER, "find current delegate failed!\n"); |
nothing calls this directly
no test coverage detected