| 1335 | } |
| 1336 | |
| 1337 | Value listdelegates(const Array& params, bool fHelp) { |
| 1338 | if (fHelp || params.size() > 1) { |
| 1339 | throw runtime_error( |
| 1340 | "listdelegates \n" |
| 1341 | "\nreturns the specified number delegates by reversed order voting number.\n" |
| 1342 | "\nArguments:\n" |
| 1343 | "1. count: (number, optional) the count of the delegates, default to all delegates.\n" |
| 1344 | "\nResult:\n" |
| 1345 | "\nExamples:\n" + |
| 1346 | HelpExampleCli("listdelegates", "11") + "\nAs json rpc call\n" + HelpExampleRpc("listdelegates", "11")); |
| 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | int32_t defaultDelegateNum = pCdMan->pDelegateCache->GetActivedDelegateNum(); |
| 1351 | |
| 1352 | int32_t delegateNum = (params.size() == 1) ? params[0].get_int() : defaultDelegateNum; |
| 1353 | if (delegateNum < 1 || delegateNum > defaultDelegateNum) { |
| 1354 | throw JSONRPCError(RPC_INVALID_PARAMETER, |
| 1355 | strprintf("Delegate number not between 1 and %u", defaultDelegateNum)); |
| 1356 | } |
| 1357 | |
| 1358 | VoteDelegateVector delegates; |
| 1359 | if (!pCdMan->pDelegateCache->GetActiveDelegates(delegates)) { |
| 1360 | throw JSONRPCError(RPC_INTERNAL_ERROR, "get active delegates failed"); |
| 1361 | } |
| 1362 | |
| 1363 | Object obj; |
| 1364 | Array delegateArray; |
| 1365 | |
| 1366 | CAccount account; |
| 1367 | int i = 0; |
| 1368 | for (const auto& delegate : delegates) { |
| 1369 | |
| 1370 | if (!pCdMan->pAccountCache->GetAccount(delegate.regid, account)) { |
| 1371 | throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed to get account info"); |
| 1372 | } |
| 1373 | Object accountObj = account.ToJsonObj(); |
| 1374 | accountObj.push_back(Pair("active_votes", delegate.votes)); |
| 1375 | delegateArray.push_back(accountObj); |
| 1376 | if(++i == delegateNum) |
| 1377 | break; |
| 1378 | } |
| 1379 | |
| 1380 | obj.push_back(Pair("delegates", delegateArray)); |
| 1381 | |
| 1382 | return obj; |
| 1383 | } |
nothing calls this directly
no test coverage detected