Browse Source

Add getlastsegidstakes RPC

jl777
blackjok3r 6 years ago
parent
commit
5ced63c9c9
  1. 64
      src/rpc/blockchain.cpp
  2. 1
      src/rpc/client.cpp
  3. 11
      src/rpc/server.cpp
  4. 1
      src/rpc/server.h

64
src/rpc/blockchain.cpp

@ -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;
@ -859,7 +921,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp)
" \"currentheight\": xxxxx, (numeric) current height of the chain\n"
" \"key\": \"xxxxx\", (string) key\n"
" \"keylen\": xxxxx, (string) length of the key \n"
" \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n"
" \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n"
" \"height\": xxxxx, (numeric) height the key was stored at\n"
" \"expiration\": xxxxx, (numeric) height the key will expire\n"
" \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n"

1
src/rpc/client.cpp

@ -74,6 +74,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listunspent", 2 },
{ "getblock", 1 },
{ "getblockheader", 1 },
{ "getlastsegidstakes", 0 },
{ "gettransaction", 1 },
{ "getrawtransaction", 1 },
{ "createrawtransaction", 0 },

11
src/rpc/server.cpp

@ -304,6 +304,7 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "getblockhashes", &getblockhashes, true },
{ "blockchain", "getblockhash", &getblockhash, true },
{ "blockchain", "getblockheader", &getblockheader, true },
{ "blockchain", "getlastsegidstakes", &getlastsegidstakes, true },
{ "blockchain", "getchaintips", &getchaintips, true },
{ "blockchain", "getdifficulty", &getdifficulty, true },
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
@ -366,16 +367,16 @@ static const CRPCCommand vRPCCommands[] =
// auction
{ "auction", "auctionaddress", &auctionaddress, true },
// lotto
{ "lotto", "lottoaddress", &lottoaddress, true },
// fsm
{ "FSM", "FSMaddress", &FSMaddress, true },
{ "FSM", "FSMcreate", &FSMcreate, true },
{ "FSM", "FSMlist", &FSMlist, true },
{ "FSM", "FSMinfo", &FSMinfo, true },
// rewards
{ "rewards", "rewardslist", &rewardslist, true },
{ "rewards", "rewardsinfo", &rewardsinfo, true },
@ -384,7 +385,7 @@ static const CRPCCommand vRPCCommands[] =
{ "rewards", "rewardslock", &rewardslock, true },
{ "rewards", "rewardsunlock", &rewardsunlock, true },
{ "rewards", "rewardsaddress", &rewardsaddress, true },
// faucet
{ "faucet", "faucetinfo", &faucetinfo, true },
{ "faucet", "faucetfund", &faucetfund, true },
@ -401,7 +402,7 @@ static const CRPCCommand vRPCCommands[] =
{ "channels", "channelspayment", &channelspayment, true },
{ "channels", "channelsclose", &channelsclose, true },
{ "channels", "channelsrefund", &channelsrefund, true },
// Oracles
{ "oracles", "oraclesaddress", &oraclesaddress, true },
{ "oracles", "oracleslist", &oracleslist, true },

1
src/rpc/server.h

@ -385,6 +385,7 @@ extern UniValue getblockhashes(const UniValue& params, bool fHelp);
extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
extern UniValue getblockhash(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 gettxoutsetinfo(const UniValue& params, bool fHelp);
extern UniValue gettxout(const UniValue& params, bool fHelp);

Loading…
Cancel
Save