Skip to content

Commit f83ba2d

Browse files
PastaPastaPastaMarcoFalke
authored andcommitted
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 dashpay#10: Add pushKV(key, boolean) function (replaces dashpay#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 5f5bea5 commit f83ba2d

29 files changed

+820
-802
lines changed

src/core_write.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
189189
auto it = ptxSpentInfo->mSpentInfo.find(spentKey);
190190
if (it != ptxSpentInfo->mSpentInfo.end()) {
191191
auto spentInfo = it->second;
192-
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
193-
in.push_back(Pair("valueSat", spentInfo.satoshis));
192+
in.pushKV("value", ValueFromAmount(spentInfo.satoshis));
193+
in.pushKV("valueSat", spentInfo.satoshis);
194194
if (spentInfo.addressType == 1) {
195-
in.push_back(Pair("address", EncodeDestination(CKeyID(spentInfo.addressHash))));
195+
in.pushKV("address", EncodeDestination(CKeyID(spentInfo.addressHash)));
196196
} else if (spentInfo.addressType == 2) {
197-
in.push_back(Pair("address", EncodeDestination(CScriptID(spentInfo.addressHash))));
197+
in.pushKV("address", EncodeDestination(CScriptID(spentInfo.addressHash)));
198198
}
199199
}
200200
}
@@ -224,61 +224,61 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
224224
auto it = ptxSpentInfo->mSpentInfo.find(spentKey);
225225
if (it != ptxSpentInfo->mSpentInfo.end()) {
226226
auto spentInfo = it->second;
227-
out.push_back(Pair("spentTxId", spentInfo.txid.GetHex()));
228-
out.push_back(Pair("spentIndex", (int)spentInfo.inputIndex));
229-
out.push_back(Pair("spentHeight", spentInfo.blockHeight));
227+
out.pushKV("spentTxId", spentInfo.txid.GetHex());
228+
out.pushKV("spentIndex", (int)spentInfo.inputIndex);
229+
out.pushKV("spentHeight", spentInfo.blockHeight);
230230
}
231231
}
232232
vout.push_back(out);
233233
}
234234
entry.pushKV("vout", vout);
235235

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

241241
if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
242242
CProRegTx proTx;
243243
if (GetTxPayload(tx, proTx)) {
244244
UniValue obj;
245245
proTx.ToJson(obj);
246-
entry.push_back(Pair("proRegTx", obj));
246+
entry.pushKV("proRegTx", obj);
247247
}
248248
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
249249
CProUpServTx proTx;
250250
if (GetTxPayload(tx, proTx)) {
251251
UniValue obj;
252252
proTx.ToJson(obj);
253-
entry.push_back(Pair("proUpServTx", obj));
253+
entry.pushKV("proUpServTx", obj);
254254
}
255255
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
256256
CProUpRegTx proTx;
257257
if (GetTxPayload(tx, proTx)) {
258258
UniValue obj;
259259
proTx.ToJson(obj);
260-
entry.push_back(Pair("proUpRegTx", obj));
260+
entry.pushKV("proUpRegTx", obj);
261261
}
262262
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REVOKE) {
263263
CProUpRevTx proTx;
264264
if (GetTxPayload(tx, proTx)) {
265265
UniValue obj;
266266
proTx.ToJson(obj);
267-
entry.push_back(Pair("proUpRevTx", obj));
267+
entry.pushKV("proUpRevTx", obj);
268268
}
269269
} else if (tx.nType == TRANSACTION_COINBASE) {
270270
CCbTx cbTx;
271271
if (GetTxPayload(tx, cbTx)) {
272272
UniValue obj;
273273
cbTx.ToJson(obj);
274-
entry.push_back(Pair("cbTx", obj));
274+
entry.pushKV("cbTx", obj);
275275
}
276276
} else if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
277277
llmq::CFinalCommitmentTxPayload qcTx;
278278
if (GetTxPayload(tx, qcTx)) {
279279
UniValue obj;
280280
qcTx.ToJson(obj);
281-
entry.push_back(Pair("qcTx", obj));
281+
entry.pushKV("qcTx", obj);
282282
}
283283
}
284284

src/evo/cbtx.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class CCbTx
4646
{
4747
obj.clear();
4848
obj.setObject();
49-
obj.push_back(Pair("version", (int)nVersion));
50-
obj.push_back(Pair("height", (int)nHeight));
51-
obj.push_back(Pair("merkleRootMNList", merkleRootMNList.ToString()));
49+
obj.pushKV("version", (int)nVersion);
50+
obj.pushKV("height", (int)nHeight);
51+
obj.pushKV("merkleRootMNList", merkleRootMNList.ToString());
5252
if (nVersion >= 2) {
53-
obj.push_back(Pair("merkleRootQuorums", merkleRootQuorums.ToString()));
53+
obj.pushKV("merkleRootQuorums", merkleRootQuorums.ToString());
5454
}
5555
}
5656
};

src/evo/deterministicmns.cpp

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

5959
CTxDestination dest;
6060
if (ExtractDestination(scriptPayout, dest)) {
61-
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
61+
obj.pushKV("payoutAddress", EncodeDestination(dest));
6262
}
63-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.Get().ToString()));
63+
obj.pushKV("pubKeyOperator", pubKeyOperator.Get().ToString());
6464
if (ExtractDestination(scriptOperatorPayout, dest)) {
65-
obj.push_back(Pair("operatorPayoutAddress", EncodeDestination(dest)));
65+
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
6666
}
6767
}
6868

@@ -79,20 +79,20 @@ void CDeterministicMN::ToJson(UniValue& obj) const
7979
UniValue stateObj;
8080
pdmnState->ToJson(stateObj);
8181

82-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
83-
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
84-
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
82+
obj.pushKV("proTxHash", proTxHash.ToString());
83+
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
84+
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
8585

8686
Coin coin;
8787
if (GetUTXOCoin(collateralOutpoint, coin)) {
8888
CTxDestination dest;
8989
if (ExtractDestination(coin.out.scriptPubKey, dest)) {
90-
obj.push_back(Pair("collateralAddress", EncodeDestination(dest)));
90+
obj.pushKV("collateralAddress", EncodeDestination(dest));
9191
}
9292
}
9393

94-
obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
95-
obj.push_back(Pair("state", stateObj));
94+
obj.pushKV("operatorReward", (double)nOperatorReward / 100);
95+
obj.pushKV("state", stateObj);
9696
}
9797

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

src/evo/providertx.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ class CProRegTx
6868
{
6969
obj.clear();
7070
obj.setObject();
71-
obj.push_back(Pair("version", nVersion));
72-
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
73-
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
74-
obj.push_back(Pair("service", addr.ToString(false)));
75-
obj.push_back(Pair("ownerAddress", EncodeDestination(keyIDOwner)));
76-
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
71+
obj.pushKV("version", nVersion);
72+
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
73+
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
74+
obj.pushKV("service", addr.ToString(false));
75+
obj.pushKV("ownerAddress", EncodeDestination(keyIDOwner));
76+
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
7777

7878
CTxDestination dest;
7979
if (ExtractDestination(scriptPayout, dest)) {
80-
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
80+
obj.pushKV("payoutAddress", EncodeDestination(dest));
8181
}
82-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
83-
obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
82+
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
83+
obj.pushKV("operatorReward", (double)nOperatorReward / 100);
8484

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

@@ -122,14 +122,14 @@ class CProUpServTx
122122
{
123123
obj.clear();
124124
obj.setObject();
125-
obj.push_back(Pair("version", nVersion));
126-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
127-
obj.push_back(Pair("service", addr.ToString(false)));
125+
obj.pushKV("version", nVersion);
126+
obj.pushKV("proTxHash", proTxHash.ToString());
127+
obj.pushKV("service", addr.ToString(false));
128128
CTxDestination dest;
129129
if (ExtractDestination(scriptOperatorPayout, dest)) {
130-
obj.push_back(Pair("operatorPayoutAddress", EncodeDestination(dest)));
130+
obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
131131
}
132-
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
132+
obj.pushKV("inputsHash", inputsHash.ToString());
133133
}
134134
};
135135

@@ -173,15 +173,15 @@ class CProUpRegTx
173173
{
174174
obj.clear();
175175
obj.setObject();
176-
obj.push_back(Pair("version", nVersion));
177-
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
178-
obj.push_back(Pair("votingAddress", EncodeDestination(keyIDVoting)));
176+
obj.pushKV("version", nVersion);
177+
obj.pushKV("proTxHash", proTxHash.ToString());
178+
obj.pushKV("votingAddress", EncodeDestination(keyIDVoting));
179179
CTxDestination dest;
180180
if (ExtractDestination(scriptPayout, dest)) {
181-
obj.push_back(Pair("payoutAddress", EncodeDestination(dest)));
181+
obj.pushKV("payoutAddress", EncodeDestination(dest));
182182
}
183-
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
184-
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
183+
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
184+
obj.pushKV("inputsHash", inputsHash.ToString());
185185
}
186186
};
187187

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

src/evo/simplifiedmns.cpp

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

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

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

143143
CDataStream ssCbTxMerkleTree(SER_NETWORK, PROTOCOL_VERSION);
144144
ssCbTxMerkleTree << cbTxMerkleTree;
145-
obj.push_back(Pair("cbTxMerkleTree", HexStr(ssCbTxMerkleTree.begin(), ssCbTxMerkleTree.end())));
145+
obj.pushKV("cbTxMerkleTree", HexStr(ssCbTxMerkleTree.begin(), ssCbTxMerkleTree.end()));
146146

147-
obj.push_back(Pair("cbTx", EncodeHexTx(*cbTx)));
147+
obj.pushKV("cbTx", EncodeHexTx(*cbTx));
148148

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

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

163163
UniValue deletedQuorumsArr(UniValue::VARR);
164164
for (const auto& e : deletedQuorums) {
165165
UniValue eObj(UniValue::VOBJ);
166-
eObj.push_back(Pair("llmqType", e.first));
167-
eObj.push_back(Pair("quorumHash", e.second.ToString()));
166+
eObj.pushKV("llmqType", e.first);
167+
eObj.pushKV("quorumHash", e.second.ToString());
168168
deletedQuorumsArr.push_back(eObj);
169169
}
170-
obj.push_back(Pair("deletedQuorums", deletedQuorumsArr));
170+
obj.pushKV("deletedQuorums", deletedQuorumsArr);
171171

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

180180
CCbTx cbTxPayload;
181181
if (GetTxPayload(*cbTx, cbTxPayload)) {
182-
obj.push_back(Pair("merkleRootMNList", cbTxPayload.merkleRootMNList.ToString()));
182+
obj.pushKV("merkleRootMNList", cbTxPayload.merkleRootMNList.ToString());
183183
if (cbTxPayload.nVersion >= 2) {
184-
obj.push_back(Pair("merkleRootQuorums", cbTxPayload.merkleRootQuorums.ToString()));
184+
obj.pushKV("merkleRootQuorums", cbTxPayload.merkleRootQuorums.ToString());
185185
}
186186
}
187187
}

src/governance/governance.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1189,12 +1189,12 @@ UniValue CGovernanceManager::ToJson() const
11891189
}
11901190

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

src/keepass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void CKeePassIntegrator::init()
123123

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

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

0 commit comments

Comments
 (0)