Skip to content

Commit 5dc00f6

Browse files
author
MarcoFalke
committed
Merge #12193: RPC: Consistently use UniValue.pushKV instead of push_back(Pair()) (karel-3d)
91986ed scripted-diff: Use UniValue.pushKV instead of push_back(Pair()) (Karel Bilek) a570098 Squashed 'src/univalue/' changes from 07947ff2da..51d3ab34ba (MarcoFalke) Pull request description: Rebased version of #11386 by karel-3d. Closes: #11386 Tree-SHA512: f3a81447e573c17e75813f4d41ceb34b9980eac81efdd98ddb149d7c51f792be7e2b32239b6ea7e6da68af23897afa6b4ce3f4e8070f9c4adf5105bf6075f2a0
2 parents 8e6f9f4 + 91986ed commit 5dc00f6

File tree

11 files changed

+427
-411
lines changed

11 files changed

+427
-411
lines changed

src/rest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,23 +540,23 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
540540

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

547547
UniValue utxos(UniValue::VARR);
548548
for (const CCoin& coin : outs) {
549549
UniValue utxo(UniValue::VOBJ);
550-
utxo.push_back(Pair("height", (int32_t)coin.nHeight));
551-
utxo.push_back(Pair("value", ValueFromAmount(coin.out.nValue)));
550+
utxo.pushKV("height", (int32_t)coin.nHeight);
551+
utxo.pushKV("value", ValueFromAmount(coin.out.nValue));
552552

553553
// include the script in a json output
554554
UniValue o(UniValue::VOBJ);
555555
ScriptPubKeyToUniv(coin.out.scriptPubKey, o, true);
556-
utxo.push_back(Pair("scriptPubKey", o));
556+
utxo.pushKV("scriptPubKey", o);
557557
utxos.push_back(utxo);
558558
}
559-
objGetUTXOResponse.push_back(Pair("utxos", utxos));
559+
objGetUTXOResponse.pushKV("utxos", utxos);
560560

561561
// return json string
562562
std::string strJSON = objGetUTXOResponse.write() + "\n";

src/rpc/blockchain.cpp

Lines changed: 122 additions & 122 deletions
Large diffs are not rendered by default.

src/rpc/mining.cpp

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ UniValue getmininginfo(const JSONRPCRequest& request)
211211
LOCK(cs_main);
212212

213213
UniValue obj(UniValue::VOBJ);
214-
obj.push_back(Pair("blocks", (int)chainActive.Height()));
215-
obj.push_back(Pair("currentblockweight", (uint64_t)nLastBlockWeight));
216-
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
217-
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
218-
obj.push_back(Pair("networkhashps", getnetworkhashps(request)));
219-
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
220-
obj.push_back(Pair("chain", Params().NetworkIDString()));
221-
obj.push_back(Pair("warnings", GetWarnings("statusbar")));
214+
obj.pushKV("blocks", (int)chainActive.Height());
215+
obj.pushKV("currentblockweight", (uint64_t)nLastBlockWeight);
216+
obj.pushKV("currentblocktx", (uint64_t)nLastBlockTx);
217+
obj.pushKV("difficulty", (double)GetDifficulty());
218+
obj.pushKV("networkhashps", getnetworkhashps(request));
219+
obj.pushKV("pooledtx", (uint64_t)mempool.size());
220+
obj.pushKV("chain", Params().NetworkIDString());
221+
obj.pushKV("warnings", GetWarnings("statusbar"));
222222
return obj;
223223
}
224224

@@ -550,33 +550,33 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
550550

551551
UniValue entry(UniValue::VOBJ);
552552

553-
entry.push_back(Pair("data", EncodeHexTx(tx)));
554-
entry.push_back(Pair("txid", txHash.GetHex()));
555-
entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex()));
553+
entry.pushKV("data", EncodeHexTx(tx));
554+
entry.pushKV("txid", txHash.GetHex());
555+
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
556556

557557
UniValue deps(UniValue::VARR);
558558
for (const CTxIn &in : tx.vin)
559559
{
560560
if (setTxIndex.count(in.prevout.hash))
561561
deps.push_back(setTxIndex[in.prevout.hash]);
562562
}
563-
entry.push_back(Pair("depends", deps));
563+
entry.pushKV("depends", deps);
564564

565565
int index_in_template = i - 1;
566-
entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template]));
566+
entry.pushKV("fee", pblocktemplate->vTxFees[index_in_template]);
567567
int64_t nTxSigOps = pblocktemplate->vTxSigOpsCost[index_in_template];
568568
if (fPreSegWit) {
569569
assert(nTxSigOps % WITNESS_SCALE_FACTOR == 0);
570570
nTxSigOps /= WITNESS_SCALE_FACTOR;
571571
}
572-
entry.push_back(Pair("sigops", nTxSigOps));
573-
entry.push_back(Pair("weight", GetTransactionWeight(tx)));
572+
entry.pushKV("sigops", nTxSigOps);
573+
entry.pushKV("weight", GetTransactionWeight(tx));
574574

575575
transactions.push_back(entry);
576576
}
577577

578578
UniValue aux(UniValue::VOBJ);
579-
aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
579+
aux.pushKV("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end()));
580580

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

@@ -586,7 +586,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
586586
aMutable.push_back("prevblock");
587587

588588
UniValue result(UniValue::VOBJ);
589-
result.push_back(Pair("capabilities", aCaps));
589+
result.pushKV("capabilities", aCaps);
590590

591591
UniValue aRules(UniValue::VARR);
592592
UniValue vbavailable(UniValue::VOBJ);
@@ -605,7 +605,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
605605
case THRESHOLD_STARTED:
606606
{
607607
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
608-
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
608+
vbavailable.pushKV(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit);
609609
if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
610610
if (!vbinfo.gbt_force) {
611611
// If the client doesn't support this, don't indicate it in the [default] version
@@ -630,10 +630,10 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
630630
}
631631
}
632632
}
633-
result.push_back(Pair("version", pblock->nVersion));
634-
result.push_back(Pair("rules", aRules));
635-
result.push_back(Pair("vbavailable", vbavailable));
636-
result.push_back(Pair("vbrequired", int(0)));
633+
result.pushKV("version", pblock->nVersion);
634+
result.pushKV("rules", aRules);
635+
result.pushKV("vbavailable", vbavailable);
636+
result.pushKV("vbrequired", int(0));
637637

638638
if (nMaxVersionPreVB >= 2) {
639639
// If VB is supported by the client, nMaxVersionPreVB is -1, so we won't get here
@@ -643,15 +643,15 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
643643
aMutable.push_back("version/force");
644644
}
645645

646-
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
647-
result.push_back(Pair("transactions", transactions));
648-
result.push_back(Pair("coinbaseaux", aux));
649-
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue));
650-
result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
651-
result.push_back(Pair("target", hashTarget.GetHex()));
652-
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
653-
result.push_back(Pair("mutable", aMutable));
654-
result.push_back(Pair("noncerange", "00000000ffffffff"));
646+
result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
647+
result.pushKV("transactions", transactions);
648+
result.pushKV("coinbaseaux", aux);
649+
result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue);
650+
result.pushKV("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast));
651+
result.pushKV("target", hashTarget.GetHex());
652+
result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
653+
result.pushKV("mutable", aMutable);
654+
result.pushKV("noncerange", "00000000ffffffff");
655655
int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
656656
int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE;
657657
if (fPreSegWit) {
@@ -660,17 +660,17 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
660660
assert(nSizeLimit % WITNESS_SCALE_FACTOR == 0);
661661
nSizeLimit /= WITNESS_SCALE_FACTOR;
662662
}
663-
result.push_back(Pair("sigoplimit", nSigOpLimit));
664-
result.push_back(Pair("sizelimit", nSizeLimit));
663+
result.pushKV("sigoplimit", nSigOpLimit);
664+
result.pushKV("sizelimit", nSizeLimit);
665665
if (!fPreSegWit) {
666-
result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT));
666+
result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT);
667667
}
668-
result.push_back(Pair("curtime", pblock->GetBlockTime()));
669-
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
670-
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
668+
result.pushKV("curtime", pblock->GetBlockTime());
669+
result.pushKV("bits", strprintf("%08x", pblock->nBits));
670+
result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));
671671

672672
if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) {
673-
result.push_back(Pair("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())));
673+
result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end()));
674674
}
675675

676676
return result;
@@ -823,12 +823,12 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
823823
FeeCalculation feeCalc;
824824
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
825825
if (feeRate != CFeeRate(0)) {
826-
result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK())));
826+
result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
827827
} else {
828828
errors.push_back("Insufficient data or no feerate found");
829-
result.push_back(Pair("errors", errors));
829+
result.pushKV("errors", errors);
830830
}
831-
result.push_back(Pair("blocks", feeCalc.returnedTarget));
831+
result.pushKV("blocks", feeCalc.returnedTarget);
832832
return result;
833833
}
834834

@@ -899,37 +899,37 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
899899
UniValue horizon_result(UniValue::VOBJ);
900900
UniValue errors(UniValue::VARR);
901901
UniValue passbucket(UniValue::VOBJ);
902-
passbucket.push_back(Pair("startrange", round(buckets.pass.start)));
903-
passbucket.push_back(Pair("endrange", round(buckets.pass.end)));
904-
passbucket.push_back(Pair("withintarget", round(buckets.pass.withinTarget * 100.0) / 100.0));
905-
passbucket.push_back(Pair("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0));
906-
passbucket.push_back(Pair("inmempool", round(buckets.pass.inMempool * 100.0) / 100.0));
907-
passbucket.push_back(Pair("leftmempool", round(buckets.pass.leftMempool * 100.0) / 100.0));
902+
passbucket.pushKV("startrange", round(buckets.pass.start));
903+
passbucket.pushKV("endrange", round(buckets.pass.end));
904+
passbucket.pushKV("withintarget", round(buckets.pass.withinTarget * 100.0) / 100.0);
905+
passbucket.pushKV("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0);
906+
passbucket.pushKV("inmempool", round(buckets.pass.inMempool * 100.0) / 100.0);
907+
passbucket.pushKV("leftmempool", round(buckets.pass.leftMempool * 100.0) / 100.0);
908908
UniValue failbucket(UniValue::VOBJ);
909-
failbucket.push_back(Pair("startrange", round(buckets.fail.start)));
910-
failbucket.push_back(Pair("endrange", round(buckets.fail.end)));
911-
failbucket.push_back(Pair("withintarget", round(buckets.fail.withinTarget * 100.0) / 100.0));
912-
failbucket.push_back(Pair("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0));
913-
failbucket.push_back(Pair("inmempool", round(buckets.fail.inMempool * 100.0) / 100.0));
914-
failbucket.push_back(Pair("leftmempool", round(buckets.fail.leftMempool * 100.0) / 100.0));
909+
failbucket.pushKV("startrange", round(buckets.fail.start));
910+
failbucket.pushKV("endrange", round(buckets.fail.end));
911+
failbucket.pushKV("withintarget", round(buckets.fail.withinTarget * 100.0) / 100.0);
912+
failbucket.pushKV("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0);
913+
failbucket.pushKV("inmempool", round(buckets.fail.inMempool * 100.0) / 100.0);
914+
failbucket.pushKV("leftmempool", round(buckets.fail.leftMempool * 100.0) / 100.0);
915915

916916
// CFeeRate(0) is used to indicate error as a return value from estimateRawFee
917917
if (feeRate != CFeeRate(0)) {
918-
horizon_result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK())));
919-
horizon_result.push_back(Pair("decay", buckets.decay));
920-
horizon_result.push_back(Pair("scale", (int)buckets.scale));
921-
horizon_result.push_back(Pair("pass", passbucket));
918+
horizon_result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
919+
horizon_result.pushKV("decay", buckets.decay);
920+
horizon_result.pushKV("scale", (int)buckets.scale);
921+
horizon_result.pushKV("pass", passbucket);
922922
// buckets.fail.start == -1 indicates that all buckets passed, there is no fail bucket to output
923-
if (buckets.fail.start != -1) horizon_result.push_back(Pair("fail", failbucket));
923+
if (buckets.fail.start != -1) horizon_result.pushKV("fail", failbucket);
924924
} else {
925925
// Output only information that is still meaningful in the event of error
926-
horizon_result.push_back(Pair("decay", buckets.decay));
927-
horizon_result.push_back(Pair("scale", (int)buckets.scale));
928-
horizon_result.push_back(Pair("fail", failbucket));
926+
horizon_result.pushKV("decay", buckets.decay);
927+
horizon_result.pushKV("scale", (int)buckets.scale);
928+
horizon_result.pushKV("fail", failbucket);
929929
errors.push_back("Insufficient data or no feerate found which meets threshold");
930-
horizon_result.push_back(Pair("errors",errors));
930+
horizon_result.pushKV("errors",errors);
931931
}
932-
result.push_back(Pair(StringForFeeEstimateHorizon(horizon), horizon_result));
932+
result.pushKV(StringForFeeEstimateHorizon(horizon), horizon_result);
933933
}
934934
return result;
935935
}

0 commit comments

Comments
 (0)