Skip to content

Commit

Permalink
Merge bitcoin#12193: RPC: Consistently use UniValue.pushKV instead o…
Browse files Browse the repository at this point in the history
…f push_back(Pair()) (karel-3d) (dashpay#3532)

* Begin Merge 12193 Squashed 'src/univalue/' changes from 07947ff..51d3ab3

51d3ab3 Merge #10: Add pushKV(key, boolean) function (replaces #5)
129bad9 [tests] test pushKV for boolean values
b3c44c9 Pushing boolean value to univalue correctly

git-subtree-dir: src/univalue
git-subtree-split: 51d3ab3

* scripted-diff: Use UniValue.pushKV instead of push_back(Pair()) (end bitcoin#12193)

-BEGIN VERIFY SCRIPT-
git grep -l "push_back(Pair" | xargs sed -i "s/push_back(Pair(\(.*\)));/pushKV(\1);/g"
-END VERIFY SCRIPT-

Signed-off-by: pasta <[email protected]>

Co-authored-by: MarcoFalke <[email protected]>
  • Loading branch information
PastaPastaPasta and MarcoFalke authored Jun 18, 2020
1 parent ed057da commit 3f8a7b2
Show file tree
Hide file tree
Showing 29 changed files with 816 additions and 800 deletions.
30 changes: 15 additions & 15 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
auto it = ptxSpentInfo->mSpentInfo.find(spentKey);
if (it != ptxSpentInfo->mSpentInfo.end()) {
auto spentInfo = it->second;
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
in.push_back(Pair("valueSat", spentInfo.satoshis));
in.pushKV("value", ValueFromAmount(spentInfo.satoshis));
in.pushKV("valueSat", spentInfo.satoshis);
if (spentInfo.addressType == 1) {
in.push_back(Pair("address", EncodeDestination(CKeyID(spentInfo.addressHash))));
in.pushKV("address", EncodeDestination(CKeyID(spentInfo.addressHash)));
} else if (spentInfo.addressType == 2) {
in.push_back(Pair("address", EncodeDestination(CScriptID(spentInfo.addressHash))));
in.pushKV("address", EncodeDestination(CScriptID(spentInfo.addressHash)));
}
}
}
Expand Down Expand Up @@ -223,61 +223,61 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
auto it = ptxSpentInfo->mSpentInfo.find(spentKey);
if (it != ptxSpentInfo->mSpentInfo.end()) {
auto spentInfo = it->second;
out.push_back(Pair("spentTxId", spentInfo.txid.GetHex()));
out.push_back(Pair("spentIndex", (int)spentInfo.inputIndex));
out.push_back(Pair("spentHeight", spentInfo.blockHeight));
out.pushKV("spentTxId", spentInfo.txid.GetHex());
out.pushKV("spentIndex", (int)spentInfo.inputIndex);
out.pushKV("spentHeight", spentInfo.blockHeight);
}
}
vout.push_back(out);
}
entry.pushKV("vout", vout);

if (!tx.vExtraPayload.empty()) {
entry.push_back(Pair("extraPayloadSize", (int)tx.vExtraPayload.size()));
entry.push_back(Pair("extraPayload", HexStr(tx.vExtraPayload)));
entry.pushKV("extraPayloadSize", (int)tx.vExtraPayload.size());
entry.pushKV("extraPayload", HexStr(tx.vExtraPayload));
}

if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
CProRegTx proTx;
if (GetTxPayload(tx, proTx)) {
UniValue obj;
proTx.ToJson(obj);
entry.push_back(Pair("proRegTx", obj));
entry.pushKV("proRegTx", obj);
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
CProUpServTx proTx;
if (GetTxPayload(tx, proTx)) {
UniValue obj;
proTx.ToJson(obj);
entry.push_back(Pair("proUpServTx", obj));
entry.pushKV("proUpServTx", obj);
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
CProUpRegTx proTx;
if (GetTxPayload(tx, proTx)) {
UniValue obj;
proTx.ToJson(obj);
entry.push_back(Pair("proUpRegTx", obj));
entry.pushKV("proUpRegTx", obj);
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REVOKE) {
CProUpRevTx proTx;
if (GetTxPayload(tx, proTx)) {
UniValue obj;
proTx.ToJson(obj);
entry.push_back(Pair("proUpRevTx", obj));
entry.pushKV("proUpRevTx", obj);
}
} else if (tx.nType == TRANSACTION_COINBASE) {
CCbTx cbTx;
if (GetTxPayload(tx, cbTx)) {
UniValue obj;
cbTx.ToJson(obj);
entry.push_back(Pair("cbTx", obj));
entry.pushKV("cbTx", obj);
}
} else if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
llmq::CFinalCommitmentTxPayload qcTx;
if (GetTxPayload(tx, qcTx)) {
UniValue obj;
qcTx.ToJson(obj);
entry.push_back(Pair("qcTx", obj));
entry.pushKV("qcTx", obj);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/evo/cbtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class CCbTx
{
obj.clear();
obj.setObject();
obj.push_back(Pair("version", (int)nVersion));
obj.push_back(Pair("height", (int)nHeight));
obj.push_back(Pair("merkleRootMNList", merkleRootMNList.ToString()));
obj.pushKV("version", (int)nVersion);
obj.pushKV("height", (int)nHeight);
obj.pushKV("merkleRootMNList", merkleRootMNList.ToString());
if (nVersion >= 2) {
obj.push_back(Pair("merkleRootQuorums", merkleRootQuorums.ToString()));
obj.pushKV("merkleRootQuorums", merkleRootQuorums.ToString());
}
}
};
Expand Down
36 changes: 18 additions & 18 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ void CDeterministicMNState::ToJson(UniValue& obj) const
{
obj.clear();
obj.setObject();
obj.push_back(Pair("service", addr.ToStringIPPort(false)));
obj.push_back(Pair("registeredHeight", nRegisteredHeight));
obj.push_back(Pair("lastPaidHeight", nLastPaidHeight));
obj.push_back(Pair("PoSePenalty", nPoSePenalty));
obj.push_back(Pair("PoSeRevivedHeight", nPoSeRevivedHeight));
obj.push_back(Pair("PoSeBanHeight", nPoSeBanHeight));
obj.push_back(Pair("revocationReason", nRevocationReason));
obj.push_back(Pair("ownerAddress", EncodeDestination(keyIDOwner)));
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
obj.pushKV("service", addr.ToStringIPPort(false));
obj.pushKV("registeredHeight", nRegisteredHeight);
obj.pushKV("lastPaidHeight", nLastPaidHeight);
obj.pushKV("PoSePenalty", nPoSePenalty);
obj.pushKV("PoSeRevivedHeight", nPoSeRevivedHeight);
obj.pushKV("PoSeBanHeight", nPoSeBanHeight);
obj.pushKV("revocationReason", nRevocationReason);
obj.pushKV("ownerAddress", EncodeDestination(keyIDOwner));
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));

CTxDestination dest;
if (ExtractDestination(scriptPayout, dest)) {
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
obj.pushKV("payoutAddress", EncodeDestination(dest));
}
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.Get().ToString()));
obj.pushKV("pubKeyOperator", pubKeyOperator.Get().ToString());
if (ExtractDestination(scriptOperatorPayout, dest)) {
obj.push_back(Pair("operatorPayoutAddress", EncodeDestination(dest)));
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
}
}

Expand All @@ -85,20 +85,20 @@ void CDeterministicMN::ToJson(UniValue& obj) const
UniValue stateObj;
pdmnState->ToJson(stateObj);

obj.push_back(Pair("proTxHash", proTxHash.ToString()));
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
obj.pushKV("proTxHash", proTxHash.ToString());
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);

Coin coin;
if (GetUTXOCoin(collateralOutpoint, coin)) {
CTxDestination dest;
if (ExtractDestination(coin.out.scriptPubKey, dest)) {
obj.push_back(Pair("collateralAddress", EncodeDestination(dest)));
obj.pushKV("collateralAddress", EncodeDestination(dest));
}
}

obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
obj.push_back(Pair("state", stateObj));
obj.pushKV("operatorReward", (double)nOperatorReward / 100);
obj.pushKV("state", stateObj);
}

bool CDeterministicMNList::IsMNValid(const uint256& proTxHash) const
Expand Down
50 changes: 25 additions & 25 deletions src/evo/providertx.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ class CProRegTx
{
obj.clear();
obj.setObject();
obj.push_back(Pair("version", nVersion));
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
obj.push_back(Pair("service", addr.ToString(false)));
obj.push_back(Pair("ownerAddress", EncodeDestination(keyIDOwner)));
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
obj.pushKV("version", nVersion);
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
obj.pushKV("service", addr.ToString(false));
obj.pushKV("ownerAddress", EncodeDestination(keyIDOwner));
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));

CTxDestination dest;
if (ExtractDestination(scriptPayout, dest)) {
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
obj.pushKV("payoutAddress", EncodeDestination(dest));
}
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
obj.pushKV("operatorReward", (double)nOperatorReward / 100);

obj.push_back(Pair("inputsHash", inputsHash.ToString()));
obj.pushKV("inputsHash", inputsHash.ToString());
}
};

Expand Down Expand Up @@ -121,14 +121,14 @@ class CProUpServTx
{
obj.clear();
obj.setObject();
obj.push_back(Pair("version", nVersion));
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
obj.push_back(Pair("service", addr.ToString(false)));
obj.pushKV("version", nVersion);
obj.pushKV("proTxHash", proTxHash.ToString());
obj.pushKV("service", addr.ToString(false));
CTxDestination dest;
if (ExtractDestination(scriptOperatorPayout, dest)) {
obj.push_back(Pair("operatorPayoutAddress", EncodeDestination(dest)));
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
}
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
obj.pushKV("inputsHash", inputsHash.ToString());
}
};

Expand Down Expand Up @@ -172,15 +172,15 @@ class CProUpRegTx
{
obj.clear();
obj.setObject();
obj.push_back(Pair("version", nVersion));
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
obj.pushKV("version", nVersion);
obj.pushKV("proTxHash", proTxHash.ToString());
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
CTxDestination dest;
if (ExtractDestination(scriptPayout, dest)) {
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
obj.pushKV("payoutAddress", EncodeDestination(dest));
}
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
obj.pushKV("inputsHash", inputsHash.ToString());
}
};

Expand Down Expand Up @@ -227,10 +227,10 @@ class CProUpRevTx
{
obj.clear();
obj.setObject();
obj.push_back(Pair("version", nVersion));
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
obj.push_back(Pair("reason", (int)nReason));
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
obj.pushKV("version", nVersion);
obj.pushKV("proTxHash", proTxHash.ToString());
obj.pushKV("reason", (int)nReason);
obj.pushKV("inputsHash", inputsHash.ToString());
}
};

Expand Down
36 changes: 18 additions & 18 deletions src/evo/simplifiedmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ void CSimplifiedMNListEntry::ToJson(UniValue& obj) const
{
obj.clear();
obj.setObject();
obj.push_back(Pair("proRegTxHash", proRegTxHash.ToString()));
obj.push_back(Pair("confirmedHash", confirmedHash.ToString()));
obj.push_back(Pair("service", service.ToString(false)));
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.Get().ToString()));
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
obj.push_back(Pair("isValid", isValid));
obj.pushKV("proRegTxHash", proRegTxHash.ToString());
obj.pushKV("confirmedHash", confirmedHash.ToString());
obj.pushKV("service", service.ToString(false));
obj.pushKV("pubKeyOperator", pubKeyOperator.Get().ToString());
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
obj.pushKV("isValid", isValid);
}

CSimplifiedMNList::CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>& smlEntries)
Expand Down Expand Up @@ -136,51 +136,51 @@ void CSimplifiedMNListDiff::ToJson(UniValue& obj) const
{
obj.setObject();

obj.push_back(Pair("baseBlockHash", baseBlockHash.ToString()));
obj.push_back(Pair("blockHash", blockHash.ToString()));
obj.pushKV("baseBlockHash", baseBlockHash.ToString());
obj.pushKV("blockHash", blockHash.ToString());

CDataStream ssCbTxMerkleTree(SER_NETWORK, PROTOCOL_VERSION);
ssCbTxMerkleTree << cbTxMerkleTree;
obj.push_back(Pair("cbTxMerkleTree", HexStr(ssCbTxMerkleTree.begin(), ssCbTxMerkleTree.end())));
obj.pushKV("cbTxMerkleTree", HexStr(ssCbTxMerkleTree.begin(), ssCbTxMerkleTree.end()));

obj.push_back(Pair("cbTx", EncodeHexTx(*cbTx)));
obj.pushKV("cbTx", EncodeHexTx(*cbTx));

UniValue deletedMNsArr(UniValue::VARR);
for (const auto& h : deletedMNs) {
deletedMNsArr.push_back(h.ToString());
}
obj.push_back(Pair("deletedMNs", deletedMNsArr));
obj.pushKV("deletedMNs", deletedMNsArr);

UniValue mnListArr(UniValue::VARR);
for (const auto& e : mnList) {
UniValue eObj;
e.ToJson(eObj);
mnListArr.push_back(eObj);
}
obj.push_back(Pair("mnList", mnListArr));
obj.pushKV("mnList", mnListArr);

UniValue deletedQuorumsArr(UniValue::VARR);
for (const auto& e : deletedQuorums) {
UniValue eObj(UniValue::VOBJ);
eObj.push_back(Pair("llmqType", e.first));
eObj.push_back(Pair("quorumHash", e.second.ToString()));
eObj.pushKV("llmqType", e.first);
eObj.pushKV("quorumHash", e.second.ToString());
deletedQuorumsArr.push_back(eObj);
}
obj.push_back(Pair("deletedQuorums", deletedQuorumsArr));
obj.pushKV("deletedQuorums", deletedQuorumsArr);

UniValue newQuorumsArr(UniValue::VARR);
for (const auto& e : newQuorums) {
UniValue eObj;
e.ToJson(eObj);
newQuorumsArr.push_back(eObj);
}
obj.push_back(Pair("newQuorums", newQuorumsArr));
obj.pushKV("newQuorums", newQuorumsArr);

CCbTx cbTxPayload;
if (GetTxPayload(*cbTx, cbTxPayload)) {
obj.push_back(Pair("merkleRootMNList", cbTxPayload.merkleRootMNList.ToString()));
obj.pushKV("merkleRootMNList", cbTxPayload.merkleRootMNList.ToString());
if (cbTxPayload.nVersion >= 2) {
obj.push_back(Pair("merkleRootQuorums", cbTxPayload.merkleRootQuorums.ToString()));
obj.pushKV("merkleRootQuorums", cbTxPayload.merkleRootQuorums.ToString());
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,12 @@ UniValue CGovernanceManager::ToJson() const
}

UniValue jsonObj(UniValue::VOBJ);
jsonObj.push_back(Pair("objects_total", (int)mapObjects.size()));
jsonObj.push_back(Pair("proposals", nProposalCount));
jsonObj.push_back(Pair("triggers", nTriggerCount));
jsonObj.push_back(Pair("other", nOtherCount));
jsonObj.push_back(Pair("erased", (int)mapErasedGovernanceObjects.size()));
jsonObj.push_back(Pair("votes", (int)cmapVoteToObject.GetSize()));
jsonObj.pushKV("objects_total", (int)mapObjects.size());
jsonObj.pushKV("proposals", nProposalCount);
jsonObj.pushKV("triggers", nTriggerCount);
jsonObj.pushKV("other", nOtherCount);
jsonObj.pushKV("erased", (int)mapErasedGovernanceObjects.size());
jsonObj.pushKV("votes", (int)cmapVoteToObject.GetSize());
return jsonObj;
}

Expand Down
2 changes: 1 addition & 1 deletion src/keepass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void CKeePassIntegrator::init()

void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const std::string& strValue)
{
requestObj.push_back(Pair(strName, strValue));
requestObj.pushKV(strName, strValue);
}

void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const SecureString& sValue)
Expand Down
Loading

0 comments on commit 3f8a7b2

Please sign in to comment.