Add getlastsegidstakes RPC
This commit is contained in:
@@ -606,6 +606,68 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
|
|||||||
return pblockindex->GetBlockHash().GetHex();
|
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 _komodo_getblockhash(int32_t nHeight)
|
||||||
{
|
{
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "listunspent", 2 },
|
{ "listunspent", 2 },
|
||||||
{ "getblock", 1 },
|
{ "getblock", 1 },
|
||||||
{ "getblockheader", 1 },
|
{ "getblockheader", 1 },
|
||||||
|
{ "getlastsegidstakes", 0 },
|
||||||
{ "gettransaction", 1 },
|
{ "gettransaction", 1 },
|
||||||
{ "getrawtransaction", 1 },
|
{ "getrawtransaction", 1 },
|
||||||
{ "createrawtransaction", 0 },
|
{ "createrawtransaction", 0 },
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "blockchain", "getblockhashes", &getblockhashes, true },
|
{ "blockchain", "getblockhashes", &getblockhashes, true },
|
||||||
{ "blockchain", "getblockhash", &getblockhash, true },
|
{ "blockchain", "getblockhash", &getblockhash, true },
|
||||||
{ "blockchain", "getblockheader", &getblockheader, true },
|
{ "blockchain", "getblockheader", &getblockheader, true },
|
||||||
|
{ "blockchain", "getlastsegidstakes", &getlastsegidstakes, true },
|
||||||
{ "blockchain", "getchaintips", &getchaintips, true },
|
{ "blockchain", "getchaintips", &getchaintips, true },
|
||||||
{ "blockchain", "getdifficulty", &getdifficulty, true },
|
{ "blockchain", "getdifficulty", &getdifficulty, true },
|
||||||
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
|
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
|
||||||
|
|||||||
@@ -385,6 +385,7 @@ extern UniValue getblockhashes(const UniValue& params, bool fHelp);
|
|||||||
extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
|
extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getblockhash(const UniValue& params, bool fHelp);
|
extern UniValue getblockhash(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getblockheader(const UniValue& params, bool fHelp);
|
extern UniValue getblockheader(const UniValue& params, bool fHelp);
|
||||||
|
extern UniValue getlastsegidstakes(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getblock(const UniValue& params, bool fHelp);
|
extern UniValue getblock(const UniValue& params, bool fHelp);
|
||||||
extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
|
extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
|
||||||
extern UniValue gettxout(const UniValue& params, bool fHelp);
|
extern UniValue gettxout(const UniValue& params, bool fHelp);
|
||||||
|
|||||||
Reference in New Issue
Block a user