Skip to content

Commit 3f8a7b2

Browse files
PastaPastaPastaMarcoFalke
andauthored
Merge bitcoin#12193: RPC: Consistently use UniValue.pushKV instead of 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]>
1 parent ed057da commit 3f8a7b2

29 files changed

+816
-800
lines changed

src/core_write.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
188188
auto it = ptxSpentInfo->mSpentInfo.find(spentKey);
189189
if (it != ptxSpentInfo->mSpentInfo.end()) {
190190
auto spentInfo = it->second;
191-
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
192-
in.push_back(Pair("valueSat", spentInfo.satoshis));
191+
in.pushKV("value", ValueFromAmount(spentInfo.satoshis));
192+
in.pushKV("valueSat", spentInfo.satoshis);
193193
if (spentInfo.addressType == 1) {
194-
in.push_back(Pair("address", EncodeDestination(CKeyID(spentInfo.addressHash))));
194+
in.pushKV("address", EncodeDestination(CKeyID(spentInfo.addressHash)));
195195
} else if (spentInfo.addressType == 2) {
196-
in.push_back(Pair("address", EncodeDestination(CScriptID(spentInfo.addressHash))));
196+
in.pushKV("address", EncodeDestination(CScriptID(spentInfo.addressHash)));
197197
}
198198
}
199199
}
@@ -223,61 +223,61 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
223223
auto it = ptxSpentInfo->mSpentInfo.find(spentKey);
224224
if (it != ptxSpentInfo->mSpentInfo.end()) {
225225
auto spentInfo = it->second;
226-
out.push_back(Pair("spentTxId", spentInfo.txid.GetHex()));
227-
out.push_back(Pair("spentIndex", (int)spentInfo.inputIndex));
228-
out.push_back(Pair("spentHeight", spentInfo.blockHeight));
226+
out.pushKV("spentTxId", spentInfo.txid.GetHex());
227+
out.pushKV("spentIndex", (int)spentInfo.inputIndex);
228+
out.pushKV("spentHeight", spentInfo.blockHeight);
229229
}
230230
}
231231
vout.push_back(out);
232232
}
233233
entry.pushKV("vout", vout);
234234

235235
if (!tx.vExtraPayload.empty()) {
236-
entry.push_back(Pair("extraPayloadSize", (int)tx.vExtraPayload.size()));
237-
entry.push_back(Pair("extraPayload", HexStr(tx.vExtraPayload)));
236+
entry.pushKV("extraPayloadSize", (int)tx.vExtraPayload.size());
237+
entry.pushKV("extraPayload", HexStr(tx.vExtraPayload));
238238
}
239239

240240
if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
241241
CProRegTx proTx;
242242
if (GetTxPayload(tx, proTx)) {
243243
UniValue obj;
244244
proTx.ToJson(obj);
245-
entry.push_back(Pair("proRegTx", obj));
245+
entry.pushKV("proRegTx", obj);
246246
}
247247
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
248248
CProUpServTx proTx;
249249
if (GetTxPayload(tx, proTx)) {
250250
UniValue obj;
251251
proTx.ToJson(obj);
252-
entry.push_back(Pair("proUpServTx", obj));
252+
entry.pushKV("proUpServTx", obj);
253253
}
254254
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
255255
CProUpRegTx proTx;
256256
if (GetTxPayload(tx, proTx)) {
257257
UniValue obj;
258258
proTx.ToJson(obj);
259-
entry.push_back(Pair("proUpRegTx", obj));
259+
entry.pushKV("proUpRegTx", obj);
260260
}
261261
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REVOKE) {
262262
CProUpRevTx proTx;
263263
if (GetTxPayload(tx, proTx)) {
264264
UniValue obj;
265265
proTx.ToJson(obj);
266-
entry.push_back(Pair("proUpRevTx", obj));
266+
entry.pushKV("proUpRevTx", obj);
267267
}
268268
} else if (tx.nType == TRANSACTION_COINBASE) {
269269
CCbTx cbTx;
270270
if (GetTxPayload(tx, cbTx)) {
271271
UniValue obj;
272272
cbTx.ToJson(obj);
273-
entry.push_back(Pair("cbTx", obj));
273+
entry.pushKV("cbTx", obj);
274274
}
275275
} else if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
276276
llmq::CFinalCommitmentTxPayload qcTx;
277277
if (GetTxPayload(tx, qcTx)) {
278278
UniValue obj;
279279
qcTx.ToJson(obj);
280-
entry.push_back(Pair("qcTx", obj));
280+
entry.pushKV("qcTx", obj);
281281
}
282282
}
283283

src/evo/cbtx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class CCbTx
4545
{
4646
obj.clear();
4747
obj.setObject();
48-
obj.push_back(Pair("version", (int)nVersion));
49-
obj.push_back(Pair("height", (int)nHeight));
50-
obj.push_back(Pair("merkleRootMNList", merkleRootMNList.ToString()));
48+
obj.pushKV("version", (int)nVersion);
49+
obj.pushKV("height", (int)nHeight);
50+
obj.pushKV("merkleRootMNList", merkleRootMNList.ToString());
5151
if (nVersion >= 2) {
52-
obj.push_back(Pair("merkleRootQuorums", merkleRootQuorums.ToString()));
52+
obj.pushKV("merkleRootQuorums", merkleRootQuorums.ToString());
5353
}
5454
}
5555
};

src/evo/deterministicmns.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ void CDeterministicMNState::ToJson(UniValue& obj) const
4545
{
4646
obj.clear();
4747
obj.setObject();
48-
obj.push_back(Pair("service", addr.ToStringIPPort(false)));
49-
obj.push_back(Pair("registeredHeight", nRegisteredHeight));
50-
obj.push_back(Pair("lastPaidHeight", nLastPaidHeight));
51-
obj.push_back(Pair("PoSePenalty", nPoSePenalty));
52-
obj.push_back(Pair("PoSeRevivedHeight", nPoSeRevivedHeight));
53-
obj.push_back(Pair("PoSeBanHeight", nPoSeBanHeight));
54-
obj.push_back(Pair("revocationReason", nRevocationReason));
55-
obj.push_back(Pair("ownerAddress", EncodeDestination(keyIDOwner)));
56-
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
48+
obj.pushKV("service", addr.ToStringIPPort(false));
49+
obj.pushKV("registeredHeight", nRegisteredHeight);
50+
obj.pushKV("lastPaidHeight", nLastPaidHeight);
51+
obj.pushKV("PoSePenalty", nPoSePenalty);
52+
obj.pushKV("PoSeRevivedHeight", nPoSeRevivedHeight);
53+
obj.pushKV("PoSeBanHeight", nPoSeBanHeight);
54+
obj.pushKV("revocationReason", nRevocationReason);
55+
obj.pushKV("ownerAddress", EncodeDestination(keyIDOwner));
56+
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
5757

5858
CTxDestination dest;
5959
if (ExtractDestination(scriptPayout, dest)) {
60-
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
60+
obj.pushKV("payoutAddress", EncodeDestination(dest));
6161
}
62-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.Get().ToString()));
62+
obj.pushKV("pubKeyOperator", pubKeyOperator.Get().ToString());
6363
if (ExtractDestination(scriptOperatorPayout, dest)) {
64-
obj.push_back(Pair("operatorPayoutAddress", EncodeDestination(dest)));
64+
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
6565
}
6666
}
6767

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

88-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
89-
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
90-
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
88+
obj.pushKV("proTxHash", proTxHash.ToString());
89+
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
90+
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
9191

9292
Coin coin;
9393
if (GetUTXOCoin(collateralOutpoint, coin)) {
9494
CTxDestination dest;
9595
if (ExtractDestination(coin.out.scriptPubKey, dest)) {
96-
obj.push_back(Pair("collateralAddress", EncodeDestination(dest)));
96+
obj.pushKV("collateralAddress", EncodeDestination(dest));
9797
}
9898
}
9999

100-
obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
101-
obj.push_back(Pair("state", stateObj));
100+
obj.pushKV("operatorReward", (double)nOperatorReward / 100);
101+
obj.pushKV("state", stateObj);
102102
}
103103

104104
bool CDeterministicMNList::IsMNValid(const uint256& proTxHash) const

src/evo/providertx.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ class CProRegTx
6767
{
6868
obj.clear();
6969
obj.setObject();
70-
obj.push_back(Pair("version", nVersion));
71-
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
72-
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
73-
obj.push_back(Pair("service", addr.ToString(false)));
74-
obj.push_back(Pair("ownerAddress", EncodeDestination(keyIDOwner)));
75-
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
70+
obj.pushKV("version", nVersion);
71+
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
72+
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
73+
obj.pushKV("service", addr.ToString(false));
74+
obj.pushKV("ownerAddress", EncodeDestination(keyIDOwner));
75+
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
7676

7777
CTxDestination dest;
7878
if (ExtractDestination(scriptPayout, dest)) {
79-
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
79+
obj.pushKV("payoutAddress", EncodeDestination(dest));
8080
}
81-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
82-
obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
81+
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
82+
obj.pushKV("operatorReward", (double)nOperatorReward / 100);
8383

84-
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
84+
obj.pushKV("inputsHash", inputsHash.ToString());
8585
}
8686
};
8787

@@ -121,14 +121,14 @@ class CProUpServTx
121121
{
122122
obj.clear();
123123
obj.setObject();
124-
obj.push_back(Pair("version", nVersion));
125-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
126-
obj.push_back(Pair("service", addr.ToString(false)));
124+
obj.pushKV("version", nVersion);
125+
obj.pushKV("proTxHash", proTxHash.ToString());
126+
obj.pushKV("service", addr.ToString(false));
127127
CTxDestination dest;
128128
if (ExtractDestination(scriptOperatorPayout, dest)) {
129-
obj.push_back(Pair("operatorPayoutAddress", EncodeDestination(dest)));
129+
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
130130
}
131-
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
131+
obj.pushKV("inputsHash", inputsHash.ToString());
132132
}
133133
};
134134

@@ -172,15 +172,15 @@ class CProUpRegTx
172172
{
173173
obj.clear();
174174
obj.setObject();
175-
obj.push_back(Pair("version", nVersion));
176-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
177-
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
175+
obj.pushKV("version", nVersion);
176+
obj.pushKV("proTxHash", proTxHash.ToString());
177+
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
178178
CTxDestination dest;
179179
if (ExtractDestination(scriptPayout, dest)) {
180-
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
180+
obj.pushKV("payoutAddress", EncodeDestination(dest));
181181
}
182-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
183-
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
182+
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
183+
obj.pushKV("inputsHash", inputsHash.ToString());
184184
}
185185
};
186186

@@ -227,10 +227,10 @@ class CProUpRevTx
227227
{
228228
obj.clear();
229229
obj.setObject();
230-
obj.push_back(Pair("version", nVersion));
231-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
232-
obj.push_back(Pair("reason", (int)nReason));
233-
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
230+
obj.pushKV("version", nVersion);
231+
obj.pushKV("proTxHash", proTxHash.ToString());
232+
obj.pushKV("reason", (int)nReason);
233+
obj.pushKV("inputsHash", inputsHash.ToString());
234234
}
235235
};
236236

src/evo/simplifiedmns.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ void CSimplifiedMNListEntry::ToJson(UniValue& obj) const
4444
{
4545
obj.clear();
4646
obj.setObject();
47-
obj.push_back(Pair("proRegTxHash", proRegTxHash.ToString()));
48-
obj.push_back(Pair("confirmedHash", confirmedHash.ToString()));
49-
obj.push_back(Pair("service", service.ToString(false)));
50-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.Get().ToString()));
51-
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
52-
obj.push_back(Pair("isValid", isValid));
47+
obj.pushKV("proRegTxHash", proRegTxHash.ToString());
48+
obj.pushKV("confirmedHash", confirmedHash.ToString());
49+
obj.pushKV("service", service.ToString(false));
50+
obj.pushKV("pubKeyOperator", pubKeyOperator.Get().ToString());
51+
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
52+
obj.pushKV("isValid", isValid);
5353
}
5454

5555
CSimplifiedMNList::CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>& smlEntries)
@@ -136,51 +136,51 @@ void CSimplifiedMNListDiff::ToJson(UniValue& obj) const
136136
{
137137
obj.setObject();
138138

139-
obj.push_back(Pair("baseBlockHash", baseBlockHash.ToString()));
140-
obj.push_back(Pair("blockHash", blockHash.ToString()));
139+
obj.pushKV("baseBlockHash", baseBlockHash.ToString());
140+
obj.pushKV("blockHash", blockHash.ToString());
141141

142142
CDataStream ssCbTxMerkleTree(SER_NETWORK, PROTOCOL_VERSION);
143143
ssCbTxMerkleTree << cbTxMerkleTree;
144-
obj.push_back(Pair("cbTxMerkleTree", HexStr(ssCbTxMerkleTree.begin(), ssCbTxMerkleTree.end())));
144+
obj.pushKV("cbTxMerkleTree", HexStr(ssCbTxMerkleTree.begin(), ssCbTxMerkleTree.end()));
145145

146-
obj.push_back(Pair("cbTx", EncodeHexTx(*cbTx)));
146+
obj.pushKV("cbTx", EncodeHexTx(*cbTx));
147147

148148
UniValue deletedMNsArr(UniValue::VARR);
149149
for (const auto& h : deletedMNs) {
150150
deletedMNsArr.push_back(h.ToString());
151151
}
152-
obj.push_back(Pair("deletedMNs", deletedMNsArr));
152+
obj.pushKV("deletedMNs", deletedMNsArr);
153153

154154
UniValue mnListArr(UniValue::VARR);
155155
for (const auto& e : mnList) {
156156
UniValue eObj;
157157
e.ToJson(eObj);
158158
mnListArr.push_back(eObj);
159159
}
160-
obj.push_back(Pair("mnList", mnListArr));
160+
obj.pushKV("mnList", mnListArr);
161161

162162
UniValue deletedQuorumsArr(UniValue::VARR);
163163
for (const auto& e : deletedQuorums) {
164164
UniValue eObj(UniValue::VOBJ);
165-
eObj.push_back(Pair("llmqType", e.first));
166-
eObj.push_back(Pair("quorumHash", e.second.ToString()));
165+
eObj.pushKV("llmqType", e.first);
166+
eObj.pushKV("quorumHash", e.second.ToString());
167167
deletedQuorumsArr.push_back(eObj);
168168
}
169-
obj.push_back(Pair("deletedQuorums", deletedQuorumsArr));
169+
obj.pushKV("deletedQuorums", deletedQuorumsArr);
170170

171171
UniValue newQuorumsArr(UniValue::VARR);
172172
for (const auto& e : newQuorums) {
173173
UniValue eObj;
174174
e.ToJson(eObj);
175175
newQuorumsArr.push_back(eObj);
176176
}
177-
obj.push_back(Pair("newQuorums", newQuorumsArr));
177+
obj.pushKV("newQuorums", newQuorumsArr);
178178

179179
CCbTx cbTxPayload;
180180
if (GetTxPayload(*cbTx, cbTxPayload)) {
181-
obj.push_back(Pair("merkleRootMNList", cbTxPayload.merkleRootMNList.ToString()));
181+
obj.pushKV("merkleRootMNList", cbTxPayload.merkleRootMNList.ToString());
182182
if (cbTxPayload.nVersion >= 2) {
183-
obj.push_back(Pair("merkleRootQuorums", cbTxPayload.merkleRootQuorums.ToString()));
183+
obj.pushKV("merkleRootQuorums", cbTxPayload.merkleRootQuorums.ToString());
184184
}
185185
}
186186
}

src/governance/governance.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,12 +1188,12 @@ UniValue CGovernanceManager::ToJson() const
11881188
}
11891189

11901190
UniValue jsonObj(UniValue::VOBJ);
1191-
jsonObj.push_back(Pair("objects_total", (int)mapObjects.size()));
1192-
jsonObj.push_back(Pair("proposals", nProposalCount));
1193-
jsonObj.push_back(Pair("triggers", nTriggerCount));
1194-
jsonObj.push_back(Pair("other", nOtherCount));
1195-
jsonObj.push_back(Pair("erased", (int)mapErasedGovernanceObjects.size()));
1196-
jsonObj.push_back(Pair("votes", (int)cmapVoteToObject.GetSize()));
1191+
jsonObj.pushKV("objects_total", (int)mapObjects.size());
1192+
jsonObj.pushKV("proposals", nProposalCount);
1193+
jsonObj.pushKV("triggers", nTriggerCount);
1194+
jsonObj.pushKV("other", nOtherCount);
1195+
jsonObj.pushKV("erased", (int)mapErasedGovernanceObjects.size());
1196+
jsonObj.pushKV("votes", (int)cmapVoteToObject.GetSize());
11971197
return jsonObj;
11981198
}
11991199

src/keepass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void CKeePassIntegrator::init()
122122

123123
void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const std::string& strValue)
124124
{
125-
requestObj.push_back(Pair(strName, strValue));
125+
requestObj.pushKV(strName, strValue);
126126
}
127127

128128
void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const SecureString& sValue)

0 commit comments

Comments
 (0)