Initial merge
This commit is contained in:
@@ -13,13 +13,14 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "json/json_spirit_value.h"
|
||||
#include <univalue.h>
|
||||
|
||||
#include <regex>
|
||||
|
||||
using namespace json_spirit;
|
||||
using namespace std;
|
||||
|
||||
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry);
|
||||
void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex);
|
||||
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
|
||||
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
|
||||
|
||||
double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty)
|
||||
{
|
||||
@@ -73,10 +74,36 @@ double GetNetworkDifficulty(const CBlockIndex* blockindex)
|
||||
return GetDifficultyINTERNAL(blockindex, true);
|
||||
}
|
||||
|
||||
|
||||
Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
|
||||
UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
{
|
||||
Object result;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
|
||||
int confirmations = -1;
|
||||
// Only report confirmations if the block is on the main chain
|
||||
if (chainActive.Contains(blockindex))
|
||||
confirmations = chainActive.Height() - blockindex->nHeight + 1;
|
||||
result.push_back(Pair("confirmations", confirmations));
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("version", blockindex->nVersion));
|
||||
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
|
||||
result.push_back(Pair("time", (int64_t)blockindex->nTime));
|
||||
result.push_back(Pair("nonce", blockindex->nNonce.GetHex()));
|
||||
result.push_back(Pair("solution", HexStr(blockindex->nSolution)));
|
||||
result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
|
||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
|
||||
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
|
||||
|
||||
if (blockindex->pprev)
|
||||
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
|
||||
CBlockIndex *pnext = chainActive.Next(blockindex);
|
||||
if (pnext)
|
||||
result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("hash", block.GetHash().GetHex()));
|
||||
int confirmations = -1;
|
||||
// Only report confirmations if the block is on the main chain
|
||||
@@ -87,12 +114,12 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
|
||||
result.push_back(Pair("height", blockindex->nHeight));
|
||||
result.push_back(Pair("version", block.nVersion));
|
||||
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
|
||||
Array txs;
|
||||
UniValue txs(UniValue::VARR);
|
||||
BOOST_FOREACH(const CTransaction&tx, block.vtx)
|
||||
{
|
||||
if(txDetails)
|
||||
{
|
||||
Object objTx;
|
||||
UniValue objTx(UniValue::VOBJ);
|
||||
TxToJSON(tx, uint256(), objTx);
|
||||
txs.push_back(objTx);
|
||||
}
|
||||
@@ -106,6 +133,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
|
||||
result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
|
||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
|
||||
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
|
||||
result.push_back(Pair("anchor", blockindex->hashAnchorEnd.GetHex()));
|
||||
|
||||
if (blockindex->pprev)
|
||||
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
|
||||
@@ -115,8 +143,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Value getblockcount(const Array& params, bool fHelp)
|
||||
UniValue getblockcount(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -133,7 +160,7 @@ Value getblockcount(const Array& params, bool fHelp)
|
||||
return chainActive.Height();
|
||||
}
|
||||
|
||||
Value getbestblockhash(const Array& params, bool fHelp)
|
||||
UniValue getbestblockhash(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -150,7 +177,7 @@ Value getbestblockhash(const Array& params, bool fHelp)
|
||||
return chainActive.Tip()->GetBlockHash().GetHex();
|
||||
}
|
||||
|
||||
Value getdifficulty(const Array& params, bool fHelp)
|
||||
UniValue getdifficulty(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -167,8 +194,56 @@ Value getdifficulty(const Array& params, bool fHelp)
|
||||
return GetNetworkDifficulty();
|
||||
}
|
||||
|
||||
UniValue mempoolToJSON(bool fVerbose = false)
|
||||
{
|
||||
if (fVerbose)
|
||||
{
|
||||
LOCK(mempool.cs);
|
||||
UniValue o(UniValue::VOBJ);
|
||||
BOOST_FOREACH(const PAIRTYPE(uint256, CTxMemPoolEntry)& entry, mempool.mapTx)
|
||||
{
|
||||
const uint256& hash = entry.first;
|
||||
const CTxMemPoolEntry& e = entry.second;
|
||||
UniValue info(UniValue::VOBJ);
|
||||
info.push_back(Pair("size", (int)e.GetTxSize()));
|
||||
info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
|
||||
info.push_back(Pair("time", e.GetTime()));
|
||||
info.push_back(Pair("height", (int)e.GetHeight()));
|
||||
info.push_back(Pair("startingpriority", e.GetPriority(e.GetHeight())));
|
||||
info.push_back(Pair("currentpriority", e.GetPriority(chainActive.Height())));
|
||||
const CTransaction& tx = e.GetTx();
|
||||
set<string> setDepends;
|
||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||
{
|
||||
if (mempool.exists(txin.prevout.hash))
|
||||
setDepends.insert(txin.prevout.hash.ToString());
|
||||
}
|
||||
|
||||
Value getrawmempool(const Array& params, bool fHelp)
|
||||
UniValue depends(UniValue::VARR);
|
||||
BOOST_FOREACH(const string& dep, setDepends)
|
||||
{
|
||||
depends.push_back(dep);
|
||||
}
|
||||
|
||||
info.push_back(Pair("depends", depends));
|
||||
o.push_back(Pair(hash.ToString(), info));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<uint256> vtxid;
|
||||
mempool.queryHashes(vtxid);
|
||||
|
||||
UniValue a(UniValue::VARR);
|
||||
BOOST_FOREACH(const uint256& hash, vtxid)
|
||||
a.push_back(hash.ToString());
|
||||
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
UniValue getrawmempool(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -206,48 +281,10 @@ Value getrawmempool(const Array& params, bool fHelp)
|
||||
if (params.size() > 0)
|
||||
fVerbose = params[0].get_bool();
|
||||
|
||||
if (fVerbose)
|
||||
{
|
||||
LOCK(mempool.cs);
|
||||
Object o;
|
||||
BOOST_FOREACH(const PAIRTYPE(uint256, CTxMemPoolEntry)& entry, mempool.mapTx)
|
||||
{
|
||||
const uint256& hash = entry.first;
|
||||
const CTxMemPoolEntry& e = entry.second;
|
||||
Object info;
|
||||
info.push_back(Pair("size", (int)e.GetTxSize()));
|
||||
info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
|
||||
info.push_back(Pair("time", e.GetTime()));
|
||||
info.push_back(Pair("height", (int)e.GetHeight()));
|
||||
info.push_back(Pair("startingpriority", e.GetPriority(e.GetHeight())));
|
||||
info.push_back(Pair("currentpriority", e.GetPriority(chainActive.Height())));
|
||||
const CTransaction& tx = e.GetTx();
|
||||
set<string> setDepends;
|
||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||
{
|
||||
if (mempool.exists(txin.prevout.hash))
|
||||
setDepends.insert(txin.prevout.hash.ToString());
|
||||
}
|
||||
Array depends(setDepends.begin(), setDepends.end());
|
||||
info.push_back(Pair("depends", depends));
|
||||
o.push_back(Pair(hash.ToString(), info));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<uint256> vtxid;
|
||||
mempool.queryHashes(vtxid);
|
||||
|
||||
Array a;
|
||||
BOOST_FOREACH(const uint256& hash, vtxid)
|
||||
a.push_back(hash.ToString());
|
||||
|
||||
return a;
|
||||
}
|
||||
return mempoolToJSON(fVerbose);
|
||||
}
|
||||
|
||||
Value getblockhash(const Array& params, bool fHelp)
|
||||
UniValue getblockhash(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
@@ -288,13 +325,16 @@ uint256 _komodo_getblockhash(int32_t nHeight)
|
||||
return(hash);
|
||||
}
|
||||
|
||||
Value getblock(const Array& params, bool fHelp)
|
||||
//Value getblock(const Array& params, bool fHelp)
|
||||
//=======
|
||||
UniValue getblockheader(const UniValue& params, bool fHelp)
|
||||
//>>>>>>> zcash/master
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"getblock \"hash\" ( verbose )\n"
|
||||
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
|
||||
"If verbose is true, returns an Object with information about block <hash>.\n"
|
||||
"getblockheader \"hash\" ( verbose )\n"
|
||||
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n"
|
||||
"If verbose is true, returns an Object with information about blockheader <hash>.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"hash\" (string, required) The block hash\n"
|
||||
"2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
|
||||
@@ -302,14 +342,9 @@ Value getblock(const Array& params, bool fHelp)
|
||||
"{\n"
|
||||
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
|
||||
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"size\" : n, (numeric) The block size\n"
|
||||
" \"height\" : n, (numeric) The block height or index\n"
|
||||
" \"version\" : n, (numeric) The block version\n"
|
||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
|
||||
" \"tx\" : [ (array of string) The transaction ids\n"
|
||||
" \"transactionid\" (string) The transaction id\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
" \"nonce\" : n, (numeric) The nonce\n"
|
||||
" \"bits\" : \"1d00ffff\", (string) The bits\n"
|
||||
@@ -320,8 +355,8 @@ Value getblock(const Array& params, bool fHelp)
|
||||
"\nResult (for verbose=false):\n"
|
||||
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
+ HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
+ HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
+ HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
@@ -329,6 +364,92 @@ Value getblock(const Array& params, bool fHelp)
|
||||
std::string strHash = params[0].get_str();
|
||||
uint256 hash(uint256S(strHash));
|
||||
|
||||
bool fVerbose = true;
|
||||
if (params.size() > 1)
|
||||
fVerbose = params[1].get_bool();
|
||||
|
||||
if (mapBlockIndex.count(hash) == 0)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
|
||||
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
||||
|
||||
if (!fVerbose)
|
||||
{
|
||||
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssBlock << pblockindex->GetBlockHeader();
|
||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
|
||||
return strHex;
|
||||
}
|
||||
|
||||
return blockheaderToJSON(pblockindex);
|
||||
}
|
||||
|
||||
UniValue getblock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"getblock \"hash|height\" ( verbose )\n"
|
||||
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash|height'.\n"
|
||||
"If verbose is true, returns an Object with information about block <hash|height>.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"hash|height\" (string, required) The block hash or height\n"
|
||||
"2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
|
||||
"\nResult (for verbose = true):\n"
|
||||
"{\n"
|
||||
" \"hash\" : \"hash\", (string) the block hash (same as provided hash)\n"
|
||||
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"size\" : n, (numeric) The block size\n"
|
||||
" \"height\" : n, (numeric) The block height or index (same as provided height)\n"
|
||||
" \"version\" : n, (numeric) The block version\n"
|
||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
|
||||
" \"tx\" : [ (array of string) The transaction ids\n"
|
||||
" \"transactionid\" (string) The transaction id\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
" \"nonce\" : n, (numeric) The nonce\n"
|
||||
" \"bits\" : \"1d00ffff\", (string) The bits\n"
|
||||
" \"difficulty\" : x.xxx, (numeric) The difficulty\n"
|
||||
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
|
||||
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
|
||||
"}\n"
|
||||
"\nResult (for verbose=false):\n"
|
||||
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
+ HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
+ HelpExampleCli("getblock", "12800")
|
||||
+ HelpExampleRpc("getblock", "12800")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
std::string strHash = params[0].get_str();
|
||||
|
||||
// If height is supplied, find the hash
|
||||
if (strHash.size() < (2 * sizeof(uint256))) {
|
||||
// std::stoi allows characters, whereas we want to be strict
|
||||
regex r("[[:digit:]]+");
|
||||
if (!regex_match(strHash, r)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
||||
}
|
||||
|
||||
int nHeight = -1;
|
||||
try {
|
||||
nHeight = std::stoi(strHash);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
||||
}
|
||||
|
||||
if (nHeight < 0 || nHeight > chainActive.Height()) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
}
|
||||
strHash = chainActive[nHeight]->GetBlockHash().GetHex();
|
||||
}
|
||||
|
||||
uint256 hash(uint256S(strHash));
|
||||
|
||||
bool fVerbose = true;
|
||||
if (params.size() > 1)
|
||||
fVerbose = params[1].get_bool();
|
||||
@@ -356,7 +477,7 @@ Value getblock(const Array& params, bool fHelp)
|
||||
return blockToJSON(block, pblockindex);
|
||||
}
|
||||
|
||||
Value gettxoutsetinfo(const Array& params, bool fHelp)
|
||||
UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -378,9 +499,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
|
||||
+ HelpExampleRpc("gettxoutsetinfo", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
Object ret;
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
CCoinsStats stats;
|
||||
FlushStateToDisk();
|
||||
@@ -655,7 +774,10 @@ Value paxprices(const Array& params, bool fHelp)
|
||||
|
||||
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue);
|
||||
|
||||
Value gettxout(const Array& params, bool fHelp)
|
||||
//Value gettxout(const Array& params, bool fHelp)
|
||||
//=======
|
||||
UniValue gettxout(const UniValue& params, bool fHelp)
|
||||
//>>>>>>> zcash/master
|
||||
{
|
||||
if (fHelp || params.size() < 2 || params.size() > 3)
|
||||
throw runtime_error(
|
||||
@@ -695,7 +817,7 @@ Value gettxout(const Array& params, bool fHelp)
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
Object ret;
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
std::string strHash = params[0].get_str();
|
||||
uint256 hash(uint256S(strHash));
|
||||
@@ -709,14 +831,14 @@ Value gettxout(const Array& params, bool fHelp)
|
||||
LOCK(mempool.cs);
|
||||
CCoinsViewMemPool view(pcoinsTip, mempool);
|
||||
if (!view.GetCoins(hash, coins))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
mempool.pruneSpent(hash, coins); // TODO: this should be done by the CCoinsViewMemPool
|
||||
} else {
|
||||
if (!pcoinsTip->GetCoins(hash, coins))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
if (n<0 || (unsigned int)n>=coins.vout.size() || coins.vout[n].IsNull())
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
|
||||
CBlockIndex *pindex = it->second;
|
||||
@@ -728,7 +850,7 @@ Value gettxout(const Array& params, bool fHelp)
|
||||
uint64_t interest; int32_t txheight; uint32_t locktime;
|
||||
if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 )
|
||||
ret.push_back(Pair("interest", ValueFromAmount(interest)));
|
||||
Object o;
|
||||
UniValue o(UniValue::VOBJ);
|
||||
ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
|
||||
ret.push_back(Pair("scriptPubKey", o));
|
||||
ret.push_back(Pair("version", coins.nVersion));
|
||||
@@ -737,7 +859,7 @@ Value gettxout(const Array& params, bool fHelp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Value verifychain(const Array& params, bool fHelp)
|
||||
UniValue verifychain(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
throw runtime_error(
|
||||
@@ -766,7 +888,7 @@ Value verifychain(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
/** Implementation of IsSuperMajority with better feedback */
|
||||
Object SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
|
||||
static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
|
||||
{
|
||||
int nFound = 0;
|
||||
CBlockIndex* pstart = pindex;
|
||||
@@ -777,7 +899,7 @@ Object SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired,
|
||||
pstart = pstart->pprev;
|
||||
}
|
||||
|
||||
Object rv;
|
||||
UniValue rv(UniValue::VOBJ);
|
||||
rv.push_back(Pair("status", nFound >= nRequired));
|
||||
rv.push_back(Pair("found", nFound));
|
||||
rv.push_back(Pair("required", nRequired));
|
||||
@@ -785,9 +907,9 @@ Object SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired,
|
||||
return rv;
|
||||
}
|
||||
|
||||
Object SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
|
||||
static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
|
||||
{
|
||||
Object rv;
|
||||
UniValue rv(UniValue::VOBJ);
|
||||
rv.push_back(Pair("id", name));
|
||||
rv.push_back(Pair("version", version));
|
||||
rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)));
|
||||
@@ -795,7 +917,7 @@ Object SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex, c
|
||||
return rv;
|
||||
}
|
||||
|
||||
Value getblockchaininfo(const Array& params, bool fHelp)
|
||||
UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -832,7 +954,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("chain", Params().NetworkIDString()));
|
||||
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
||||
obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
|
||||
@@ -848,7 +970,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
|
||||
|
||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||
CBlockIndex* tip = chainActive.Tip();
|
||||
Array softforks;
|
||||
UniValue softforks(UniValue::VARR);
|
||||
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
|
||||
softforks.push_back(SoftForkDesc("bip66", 3, tip, consensusParams));
|
||||
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
|
||||
@@ -880,7 +1002,7 @@ struct CompareBlocksByHeight
|
||||
}
|
||||
};
|
||||
|
||||
Value getchaintips(const Array& params, bool fHelp)
|
||||
UniValue getchaintips(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -932,10 +1054,10 @@ Value getchaintips(const Array& params, bool fHelp)
|
||||
setTips.insert(chainActive.Tip());
|
||||
|
||||
/* Construct the output array. */
|
||||
Array res;
|
||||
UniValue res(UniValue::VARR);
|
||||
BOOST_FOREACH(const CBlockIndex* block, setTips)
|
||||
{
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("height", block->nHeight));
|
||||
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
|
||||
|
||||
@@ -970,7 +1092,17 @@ Value getchaintips(const Array& params, bool fHelp)
|
||||
return res;
|
||||
}
|
||||
|
||||
Value getmempoolinfo(const Array& params, bool fHelp)
|
||||
UniValue mempoolInfoToJSON()
|
||||
{
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.push_back(Pair("size", (int64_t) mempool.size()));
|
||||
ret.push_back(Pair("bytes", (int64_t) mempool.GetTotalTxSize()));
|
||||
ret.push_back(Pair("usage", (int64_t) mempool.DynamicMemoryUsage()));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue getmempoolinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
@@ -980,20 +1112,17 @@ Value getmempoolinfo(const Array& params, bool fHelp)
|
||||
"{\n"
|
||||
" \"size\": xxxxx (numeric) Current tx count\n"
|
||||
" \"bytes\": xxxxx (numeric) Sum of all tx sizes\n"
|
||||
" \"usage\": xxxxx (numeric) Total memory usage for the mempool\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getmempoolinfo", "")
|
||||
+ HelpExampleRpc("getmempoolinfo", "")
|
||||
);
|
||||
|
||||
Object ret;
|
||||
ret.push_back(Pair("size", (int64_t) mempool.size()));
|
||||
ret.push_back(Pair("bytes", (int64_t) mempool.GetTotalTxSize()));
|
||||
|
||||
return ret;
|
||||
return mempoolInfoToJSON();
|
||||
}
|
||||
|
||||
Value invalidateblock(const Array& params, bool fHelp)
|
||||
UniValue invalidateblock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
@@ -1028,10 +1157,10 @@ Value invalidateblock(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason());
|
||||
}
|
||||
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
Value reconsiderblock(const Array& params, bool fHelp)
|
||||
UniValue reconsiderblock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
@@ -1067,5 +1196,5 @@ Value reconsiderblock(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason());
|
||||
}
|
||||
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user