|
|
@ -606,6 +606,68 @@ UniValue getblockhash(const UniValue& params, bool fHelp) |
|
|
|
return pblockindex->GetBlockHash().GetHex(); |
|
|
|
} |
|
|
|
|
|
|
|
extern uint64_t ASSETCHAINS_STAKED; |
|
|
|
int32_t komodo_isPoS(CBlock *pblock); |
|
|
|
uint32_t komodo_segid32(char *coinaddr); |
|
|
|
|
|
|
|
UniValue getlastsegidstakes(const UniValue& params, bool fHelp) |
|
|
|
{ |
|
|
|
if (fHelp || params.size() != 1) |
|
|
|
throw runtime_error( |
|
|
|
"getlastsegidstakes depth\n" |
|
|
|
"\nReturns object containing the counts of the last X blocks staked by each segid.\n" |
|
|
|
"\nArguments:\n" |
|
|
|
"1. depth (numeric, required) The amount of blocks to scan back." |
|
|
|
"\nResult:\n" |
|
|
|
"{\n" |
|
|
|
" \"0\" : n, (numeric) number of stakes from segid 0 in the last X blocks.\n" |
|
|
|
" .....\n" |
|
|
|
"}\n" |
|
|
|
"\nExamples:\n" |
|
|
|
+ HelpExampleCli("getlastsegidstakes", "1000") |
|
|
|
+ HelpExampleRpc("getlastsegidstakes", "1000") |
|
|
|
); |
|
|
|
|
|
|
|
if ( ASSETCHAINS_STAKED == 0 ) |
|
|
|
throw runtime_error("Only applies to ac_staked chains\n"); |
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
|
|
|
|
int depth = params[0].get_int(); |
|
|
|
int32_t segids[64] = {0}; |
|
|
|
|
|
|
|
for (int64_t i = chainActive.Height(); i > chainActive.Height()-depth; i--) |
|
|
|
{ |
|
|
|
CBlockIndex* pblockindex = chainActive[i]; |
|
|
|
CBlock block; |
|
|
|
|
|
|
|
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) |
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); |
|
|
|
|
|
|
|
if(!ReadBlockFromDisk(block, pblockindex,1)) |
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); |
|
|
|
|
|
|
|
if ( komodo_isPoS((CBlock *)&block) != 0 ) |
|
|
|
{ |
|
|
|
CTxDestination voutaddress; int32_t segid; |
|
|
|
if ( ExtractDestination(block.vtx[block.vtx.size()-1].vout[0].scriptPubKey,voutaddress) ) |
|
|
|
{ |
|
|
|
segid = (int32_t)komodo_segid32((char *)CBitcoinAddress(voutaddress).ToString().c_str()) & 0x3f; |
|
|
|
segids[segid] += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
UniValue ret(UniValue::VOBJ); |
|
|
|
for (int8_t i = 0; i < 64; i++) |
|
|
|
{ |
|
|
|
char str[4]; |
|
|
|
sprintf(str, "%d", i); |
|
|
|
ret.push_back(Pair(str,segids[i])); |
|
|
|
} |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
/*uint256 _komodo_getblockhash(int32_t nHeight)
|
|
|
|
{ |
|
|
|
uint256 hash; |
|
|
|