Skip to content

Commit

Permalink
Finish conversion of rpc to use pushKV
Browse files Browse the repository at this point in the history
Summary: As per title. Fixes missed changes from D1990.

Test Plan:
  make VERBOSE=1 check && ./test/functional/test_runner.py

Reviewers: #bitcoin_abc, deadalnix, schancel

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: Fabien, teamcity

Differential Revision: https://reviews.bitcoinabc.org/D2064
  • Loading branch information
Shammah Chancellor authored and Fabcien committed Nov 22, 2018
1 parent d60344b commit 3d981bc
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 140 deletions.
10 changes: 4 additions & 6 deletions src/rest.cpp
Expand Up @@ -628,12 +628,10 @@ static bool rest_getutxos(Config &config, HTTPRequest *req,

// pack in some essentials
// use more or less the same output as mentioned in Bip64
objGetUTXOResponse.push_back(
Pair("chainHeight", chainActive.Height()));
objGetUTXOResponse.push_back(Pair(
"chaintipHash", chainActive.Tip()->GetBlockHash().GetHex()));
objGetUTXOResponse.push_back(
Pair("bitmap", bitmapStringRepresentation));
objGetUTXOResponse.pushKV("chainHeight", chainActive.Height());
objGetUTXOResponse.pushKV(
"chaintipHash", chainActive.Tip()->GetBlockHash().GetHex());
objGetUTXOResponse.pushKV("bitmap", bitmapStringRepresentation);

UniValue utxos(UniValue::VARR);
for (const CCoin &coin : outs) {
Expand Down
58 changes: 23 additions & 35 deletions src/rpc/blockchain.cpp
Expand Up @@ -78,20 +78,18 @@ UniValue blockheaderToJSON(const CBlockIndex *blockindex) {
result.pushKV("confirmations", confirmations);
result.pushKV("height", blockindex->nHeight);
result.pushKV("version", blockindex->nVersion);
result.push_back(
Pair("versionHex", strprintf("%08x", blockindex->nVersion)));
result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion));
result.pushKV("merkleroot", blockindex->hashMerkleRoot.GetHex());
result.pushKV("time", int64_t(blockindex->nTime));
result.push_back(
Pair("mediantime", int64_t(blockindex->GetMedianTimePast())));
result.pushKV("mediantime", int64_t(blockindex->GetMedianTimePast()));
result.pushKV("nonce", uint64_t(blockindex->nNonce));
result.pushKV("bits", strprintf("%08x", blockindex->nBits));
result.pushKV("difficulty", GetDifficulty(blockindex));
result.pushKV("chainwork", blockindex->nChainWork.GetHex());

if (blockindex->pprev) {
result.push_back(Pair("previousblockhash",
blockindex->pprev->GetBlockHash().GetHex()));
result.pushKV("previousblockhash",
blockindex->pprev->GetBlockHash().GetHex());
}
CBlockIndex *pnext = chainActive.Next(blockindex);
if (pnext) {
Expand All @@ -110,8 +108,8 @@ UniValue blockToJSON(const Config &config, const CBlock &block,
confirmations = chainActive.Height() - blockindex->nHeight + 1;
}
result.pushKV("confirmations", confirmations);
result.push_back(Pair(
"size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
result.pushKV(
"size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION));
result.pushKV("height", blockindex->nHeight);
result.pushKV("version", block.nVersion);
result.pushKV("versionHex", strprintf("%08x", block.nVersion));
Expand All @@ -128,16 +126,15 @@ UniValue blockToJSON(const Config &config, const CBlock &block,
}
result.pushKV("tx", txs);
result.pushKV("time", block.GetBlockTime());
result.push_back(
Pair("mediantime", int64_t(blockindex->GetMedianTimePast())));
result.pushKV("mediantime", int64_t(blockindex->GetMedianTimePast()));
result.pushKV("nonce", uint64_t(block.nNonce));
result.pushKV("bits", strprintf("%08x", block.nBits));
result.pushKV("difficulty", GetDifficulty(blockindex));
result.pushKV("chainwork", blockindex->nChainWork.GetHex());

if (blockindex->pprev) {
result.push_back(Pair("previousblockhash",
blockindex->pprev->GetBlockHash().GetHex()));
result.pushKV("previousblockhash",
blockindex->pprev->GetBlockHash().GetHex());
}
CBlockIndex *pnext = chainActive.Next(blockindex);
if (pnext) {
Expand Down Expand Up @@ -407,12 +404,10 @@ void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) {
info.pushKV("time", e.GetTime());
info.pushKV("height", (int)e.GetHeight());
info.pushKV("startingpriority", e.GetPriority(e.GetHeight()));
info.push_back(
Pair("currentpriority", e.GetPriority(chainActive.Height())));
info.pushKV("currentpriority", e.GetPriority(chainActive.Height()));
info.pushKV("descendantcount", e.GetCountWithDescendants());
info.pushKV("descendantsize", e.GetSizeWithDescendants());
info.push_back(
Pair("descendantfees", e.GetModFeesWithDescendants() / SATOSHI));
info.pushKV("descendantfees", e.GetModFeesWithDescendants() / SATOSHI);
info.pushKV("ancestorcount", e.GetCountWithAncestors());
info.pushKV("ancestorsize", e.GetSizeWithAncestors());
info.pushKV("ancestorfees", e.GetModFeesWithAncestors() / SATOSHI);
Expand Down Expand Up @@ -1040,8 +1035,7 @@ UniValue gettxoutsetinfo(const Config &config, const JSONRPCRequest &request) {
ret.pushKV("bogosize", int64_t(stats.nBogoSize));
ret.pushKV("hash_serialized", stats.hashSerialized.GetHex());
ret.pushKV("disk_size", stats.nDiskSize);
ret.push_back(
Pair("total_amount", ValueFromAmount(stats.nTotalAmount)));
ret.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount));
} else {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
}
Expand Down Expand Up @@ -1126,8 +1120,8 @@ UniValue gettxout(const Config &config, const JSONRPCRequest &request) {
if (coin.GetHeight() == MEMPOOL_HEIGHT) {
ret.pushKV("confirmations", 0);
} else {
ret.push_back(Pair("confirmations",
int64_t(pindex->nHeight - coin.GetHeight() + 1)));
ret.pushKV("confirmations",
int64_t(pindex->nHeight - coin.GetHeight() + 1));
}
ret.pushKV("value", ValueFromAmount(coin.GetTxOut().nValue));
UniValue o(UniValue::VOBJ);
Expand Down Expand Up @@ -1201,8 +1195,7 @@ static UniValue SoftForkDesc(const std::string &name, int version,
UniValue rv(UniValue::VOBJ);
rv.pushKV("id", name);
rv.pushKV("version", version);
rv.push_back(
Pair("reject", SoftForkMajorityDesc(version, pindex, consensusParams)));
rv.pushKV("reject", SoftForkMajorityDesc(version, pindex, consensusParams));
return rv;
}

Expand Down Expand Up @@ -1257,17 +1250,13 @@ UniValue getblockchaininfo(const Config &config,
UniValue obj(UniValue::VOBJ);
obj.pushKV("chain", config.GetChainParams().NetworkIDString());
obj.pushKV("blocks", int(chainActive.Height()));
obj.push_back(
Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
obj.push_back(
Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex());
obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip())));
obj.push_back(
Pair("mediantime", int64_t(chainActive.Tip()->GetMedianTimePast())));
obj.push_back(
Pair("verificationprogress",
GuessVerificationProgress(config.GetChainParams().TxData(),
chainActive.Tip())));
obj.pushKV("mediantime", int64_t(chainActive.Tip()->GetMedianTimePast()));
obj.pushKV("verificationprogress",
GuessVerificationProgress(config.GetChainParams().TxData(),
chainActive.Tip()));
obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex());
obj.pushKV("pruned", fPruneMode);

Expand Down Expand Up @@ -1434,9 +1423,8 @@ UniValue mempoolInfoToJSON() {
size_t maxmempool =
gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
ret.pushKV("maxmempool", (int64_t)maxmempool);
ret.push_back(
Pair("mempoolminfee",
ValueFromAmount(mempool.GetMinFee(maxmempool).GetFeePerK())));
ret.pushKV("mempoolminfee",
ValueFromAmount(mempool.GetMinFee(maxmempool).GetFeePerK()));

return ret;
}
Expand Down
26 changes: 11 additions & 15 deletions src/rpc/mining.cpp
Expand Up @@ -252,10 +252,9 @@ static UniValue getmininginfo(const Config &config,
obj.pushKV("currentblocksize", uint64_t(nLastBlockSize));
obj.pushKV("currentblocktx", uint64_t(nLastBlockTx));
obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip())));
obj.push_back(
Pair("blockprioritypercentage",
uint8_t(gArgs.GetArg("-blockprioritypercentage",
DEFAULT_BLOCK_PRIORITY_PERCENTAGE))));
obj.pushKV("blockprioritypercentage",
uint8_t(gArgs.GetArg("-blockprioritypercentage",
DEFAULT_BLOCK_PRIORITY_PERCENTAGE)));
obj.pushKV("errors", GetWarnings("statusbar"));
obj.pushKV("networkhashps", getnetworkhashps(config, request));
obj.pushKV("pooledtx", uint64_t(mempool.size()));
Expand Down Expand Up @@ -642,8 +641,7 @@ static UniValue getblocktemplate(const Config &config,
}

UniValue aux(UniValue::VOBJ);
aux.push_back(
Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
aux.pushKV("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end()));

arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);

Expand All @@ -660,19 +658,17 @@ static UniValue getblocktemplate(const Config &config,
result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
result.pushKV("transactions", transactions);
result.pushKV("coinbaseaux", aux);
result.push_back(Pair("coinbasevalue",
int64_t(pblock->vtx[0]->vout[0].nValue / SATOSHI)));
result.push_back(Pair("longpollid",
chainActive.Tip()->GetBlockHash().GetHex() +
i64tostr(nTransactionsUpdatedLast)));
result.pushKV("coinbasevalue",
int64_t(pblock->vtx[0]->vout[0].nValue / SATOSHI));
result.pushKV("longpollid",
chainActive.Tip()->GetBlockHash().GetHex() +
i64tostr(nTransactionsUpdatedLast));
result.pushKV("target", hashTarget.GetHex());
result.push_back(
Pair("mintime", int64_t(pindexPrev->GetMedianTimePast()) + 1));
result.pushKV("mintime", int64_t(pindexPrev->GetMedianTimePast()) + 1);
result.pushKV("mutable", aMutable);
result.pushKV("noncerange", "00000000ffffffff");
// FIXME: Allow for mining block greater than 1M.
result.push_back(
Pair("sigoplimit", GetMaxBlockSigOpsCount(DEFAULT_MAX_BLOCK_SIZE)));
result.pushKV("sigoplimit", GetMaxBlockSigOpsCount(DEFAULT_MAX_BLOCK_SIZE));
result.pushKV("sizelimit", DEFAULT_MAX_BLOCK_SIZE);
result.pushKV("curtime", pblock->GetBlockTime());
result.pushKV("bits", strprintf("%08x", pblock->nBits));
Expand Down
33 changes: 15 additions & 18 deletions src/rpc/misc.cpp
Expand Up @@ -109,16 +109,15 @@ static UniValue getinfo(const Config &config, const JSONRPCRequest &request) {
obj.pushKV("blocks", (int)chainActive.Height());
obj.pushKV("timeoffset", GetTimeOffset());
if (g_connman) {
obj.push_back(
Pair("connections",
(int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
obj.pushKV("connections",
(int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
}
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort()
: std::string())));
obj.pushKV("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort()
: std::string()));
obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip())));
obj.push_back(Pair("testnet",
config.GetChainParams().NetworkIDString() ==
CBaseChainParams::TESTNET));
obj.pushKV("testnet",
config.GetChainParams().NetworkIDString() ==
CBaseChainParams::TESTNET);
#ifdef ENABLE_WALLET
if (pwallet) {
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime());
Expand All @@ -129,8 +128,8 @@ static UniValue getinfo(const Config &config, const JSONRPCRequest &request) {
}
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()));
#endif
obj.push_back(Pair("relayfee",
ValueFromAmount(config.GetMinFeePerKB().GetFeePerK())));
obj.pushKV("relayfee",
ValueFromAmount(config.GetMinFeePerKB().GetFeePerK()));
obj.pushKV("errors", GetWarnings("statusbar"));
return obj;
}
Expand Down Expand Up @@ -167,8 +166,7 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue> {
int nRequired;
ExtractDestinations(subscript, whichType, addresses, nRequired);
obj.pushKV("script", GetTxnOutputType(whichType));
obj.push_back(
Pair("hex", HexStr(subscript.begin(), subscript.end())));
obj.pushKV("hex", HexStr(subscript.begin(), subscript.end()));
UniValue a(UniValue::VARR);
for (const CTxDestination &addr : addresses) {
a.push_back(EncodeDestination(addr));
Expand Down Expand Up @@ -246,14 +244,13 @@ static UniValue validateaddress(const Config &config,
ret.pushKV("address", currentAddress);

CScript scriptPubKey = GetScriptForDestination(dest);
ret.push_back(Pair("scriptPubKey",
HexStr(scriptPubKey.begin(), scriptPubKey.end())));
ret.pushKV("scriptPubKey",
HexStr(scriptPubKey.begin(), scriptPubKey.end()));

#ifdef ENABLE_WALLET
isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO;
ret.pushKV("ismine", (mine & ISMINE_SPENDABLE) ? true : false);
ret.push_back(
Pair("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true : false));
ret.pushKV("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true : false);
UniValue detail =
boost::apply_visitor(DescribeAddressVisitor(pwallet), dest);
ret.pushKVs(detail);
Expand All @@ -271,8 +268,8 @@ static UniValue validateaddress(const Config &config,
ret.pushKV("timestamp", it->second.nCreateTime);
if (!it->second.hdKeypath.empty()) {
ret.pushKV("hdkeypath", it->second.hdKeypath);
ret.push_back(Pair("hdmasterkeyid",
it->second.hdMasterKeyID.GetHex()));
ret.pushKV("hdmasterkeyid",
it->second.hdMasterKeyID.GetHex());
}
}
}
Expand Down
47 changes: 22 additions & 25 deletions src/rpc/net.cpp
Expand Up @@ -409,8 +409,7 @@ static UniValue getaddednodeinfo(const Config &config,
if (info.fConnected) {
UniValue address(UniValue::VOBJ);
address.pushKV("address", info.resolvedAddress.ToString());
address.push_back(
Pair("connected", info.fInbound ? "inbound" : "outbound"));
address.pushKV("connected", info.fInbound ? "inbound" : "outbound");
addresses.push_back(address);
}
obj.pushKV("addresses", addresses);
Expand Down Expand Up @@ -467,17 +466,16 @@ static UniValue getnettotals(const Config &config,
obj.pushKV("timemillis", GetTimeMillis());

UniValue outboundLimit(UniValue::VOBJ);
outboundLimit.push_back(
Pair("timeframe", g_connman->GetMaxOutboundTimeframe()));
outboundLimit.pushKV("timeframe", g_connman->GetMaxOutboundTimeframe());
outboundLimit.pushKV("target", g_connman->GetMaxOutboundTarget());
outboundLimit.push_back(
Pair("target_reached", g_connman->OutboundTargetReached(false)));
outboundLimit.push_back(Pair("serve_historical_blocks",
!g_connman->OutboundTargetReached(true)));
outboundLimit.push_back(
Pair("bytes_left_in_cycle", g_connman->GetOutboundTargetBytesLeft()));
outboundLimit.push_back(
Pair("time_left_in_cycle", g_connman->GetMaxOutboundTimeLeftInCycle()));
outboundLimit.pushKV("target_reached",
g_connman->OutboundTargetReached(false));
outboundLimit.pushKV("serve_historical_blocks",
!g_connman->OutboundTargetReached(true));
outboundLimit.pushKV("bytes_left_in_cycle",
g_connman->GetOutboundTargetBytesLeft());
outboundLimit.pushKV("time_left_in_cycle",
g_connman->GetMaxOutboundTimeLeftInCycle());
obj.pushKV("uploadtarget", outboundLimit);
return obj;
}
Expand All @@ -495,11 +493,10 @@ static UniValue GetNetworksInfo() {
obj.pushKV("name", GetNetworkName(network));
obj.pushKV("limited", IsLimited(network));
obj.pushKV("reachable", IsReachable(network));
obj.push_back(Pair("proxy",
proxy.IsValid() ? proxy.proxy.ToStringIPPort()
: std::string()));
obj.push_back(
Pair("proxy_randomize_credentials", proxy.randomize_credentials));
obj.pushKV("proxy",
proxy.IsValid() ? proxy.proxy.ToStringIPPort()
: std::string());
obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
networks.push_back(obj);
}
return networks;
Expand Down Expand Up @@ -579,21 +576,21 @@ static UniValue getnetworkinfo(const Config &config,
obj.pushKV("subversion", userAgent(config));
obj.pushKV("protocolversion", PROTOCOL_VERSION);
if (g_connman) {
obj.push_back(Pair("localservices",
strprintf("%016x", g_connman->GetLocalServices())));
obj.pushKV("localservices",
strprintf("%016x", g_connman->GetLocalServices()));
}
obj.pushKV("localrelay", fRelayTxes);
obj.pushKV("timeoffset", GetTimeOffset());
if (g_connman) {
obj.pushKV("networkactive", g_connman->GetNetworkActive());
obj.push_back(Pair("connections", int(g_connman->GetNodeCount(
CConnman::CONNECTIONS_ALL))));
obj.pushKV("connections",
int(g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
}
obj.pushKV("networks", GetNetworksInfo());
obj.push_back(Pair("relayfee",
ValueFromAmount(config.GetMinFeePerKB().GetFeePerK())));
obj.push_back(Pair("excessutxocharge",
ValueFromAmount(config.GetExcessUTXOCharge())));
obj.pushKV("relayfee",
ValueFromAmount(config.GetMinFeePerKB().GetFeePerK()));
obj.pushKV("excessutxocharge",
ValueFromAmount(config.GetExcessUTXOCharge()));
UniValue localAddresses(UniValue::VARR);
{
LOCK(cs_mapLocalHost);
Expand Down

0 comments on commit 3d981bc

Please sign in to comment.