Skip to content

Commit 27cffb1

Browse files
committed
refactor: shed avoidable casts in Dash-specific UniValue-ret functions
1 parent 32958da commit 27cffb1

File tree

12 files changed

+44
-41
lines changed

12 files changed

+44
-41
lines changed

src/core_write.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
270270
if (it != ptxSpentInfo->mSpentInfo.end()) {
271271
auto spentInfo = it->second;
272272
out.pushKV("spentTxId", spentInfo.m_tx_hash.GetHex());
273-
out.pushKV("spentIndex", (int)spentInfo.m_tx_index);
273+
out.pushKV("spentIndex", spentInfo.m_tx_index);
274274
out.pushKV("spentHeight", spentInfo.m_block_height);
275275
}
276276
}
@@ -283,7 +283,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
283283
entry.pushKV("vout", vout);
284284

285285
if (!tx.vExtraPayload.empty()) {
286-
entry.pushKV("extraPayloadSize", (int)tx.vExtraPayload.size());
286+
entry.pushKV("extraPayloadSize", tx.vExtraPayload.size());
287287
entry.pushKV("extraPayload", HexStr(tx.vExtraPayload));
288288
}
289289

src/evo/core_write.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <core_io.h>
6+
#include <util/underlying.h>
7+
68
#include <evo/assetlocktx.h>
79
#include <evo/cbtx.h>
810
#include <evo/mnhftx.h>
@@ -28,18 +30,18 @@
2830
}
2931

3032
UniValue ret(UniValue::VOBJ);
31-
ret.pushKV("version", int(nVersion));
33+
ret.pushKV("version", nVersion);
3234
ret.pushKV("creditOutputs", outputs);
3335
return ret;
3436
}
3537

3638
[[nodiscard]] UniValue CAssetUnlockPayload::ToJson() const
3739
{
3840
UniValue ret(UniValue::VOBJ);
39-
ret.pushKV("version", int(nVersion));
40-
ret.pushKV("index", int(index));
41-
ret.pushKV("fee", int(fee));
42-
ret.pushKV("requestedHeight", int(requestedHeight));
41+
ret.pushKV("version", nVersion);
42+
ret.pushKV("index", index);
43+
ret.pushKV("fee", fee);
44+
ret.pushKV("requestedHeight", requestedHeight);
4345
ret.pushKV("quorumHash", quorumHash.ToString());
4446
ret.pushKV("quorumSig", quorumSig.ToString());
4547
return ret;
@@ -48,13 +50,13 @@
4850
[[nodiscard]] UniValue CCbTx::ToJson() const
4951
{
5052
UniValue ret(UniValue::VOBJ);
51-
ret.pushKV("version", (int)nVersion);
53+
ret.pushKV("version", ToUnderlying(nVersion));
5254
ret.pushKV("height", nHeight);
5355
ret.pushKV("merkleRootMNList", merkleRootMNList.ToString());
5456
if (nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) {
5557
ret.pushKV("merkleRootQuorums", merkleRootQuorums.ToString());
5658
if (nVersion >= CCbTx::Version::CLSIG_AND_BALANCE) {
57-
ret.pushKV("bestCLHeightDiff", static_cast<int>(bestCLHeightDiff));
59+
ret.pushKV("bestCLHeightDiff", bestCLHeightDiff);
5860
ret.pushKV("bestCLSignature", bestCLSignature.ToString());
5961
ret.pushKV("creditPoolBalance", ValueFromAmount(creditPoolBalance));
6062
}
@@ -68,7 +70,7 @@
6870
ret.pushKV("version", nVersion);
6971
ret.pushKV("type", ToUnderlying(nType));
7072
ret.pushKV("collateralHash", collateralOutpoint.hash.ToString());
71-
ret.pushKV("collateralIndex", (int)collateralOutpoint.n);
73+
ret.pushKV("collateralIndex", collateralOutpoint.n);
7274
if (IsServiceDeprecatedRPCEnabled()) {
7375
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
7476
}
@@ -108,7 +110,7 @@
108110
UniValue ret(UniValue::VOBJ);
109111
ret.pushKV("version", nVersion);
110112
ret.pushKV("proTxHash", proTxHash.ToString());
111-
ret.pushKV("reason", (int)nReason);
113+
ret.pushKV("reason", nReason);
112114
ret.pushKV("inputsHash", inputsHash.ToString());
113115
return ret;
114116
}
@@ -138,16 +140,16 @@
138140
[[nodiscard]] UniValue MNHFTxPayload::ToJson() const
139141
{
140142
UniValue ret(UniValue::VOBJ);
141-
ret.pushKV("version", (int)nVersion);
143+
ret.pushKV("version", nVersion);
142144
ret.pushKV("signal", signal.ToJson());
143145
return ret;
144146
}
145147

146148
[[nodiscard]] UniValue llmq::CFinalCommitmentTxPayload::ToJson() const
147149
{
148150
UniValue ret(UniValue::VOBJ);
149-
ret.pushKV("version", int{nVersion});
150-
ret.pushKV("height", int(nHeight));
151+
ret.pushKV("version", nVersion);
152+
ret.pushKV("height", nHeight);
151153
ret.pushKV("commitment", commitment.ToJson());
152154
return ret;
153155
}

src/evo/deterministicmns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ UniValue CDeterministicMN::ToJson() const
5656
obj.pushKV("type", std::string(GetMnType(nType).description));
5757
obj.pushKV("proTxHash", proTxHash.ToString());
5858
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
59-
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
59+
obj.pushKV("collateralIndex", collateralOutpoint.n);
6060

6161
if (g_txindex) {
6262
CTransactionRef collateralTx;

src/governance/governance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,12 +1504,12 @@ UniValue CGovernanceManager::ToJson() const
15041504
}
15051505

15061506
UniValue jsonObj(UniValue::VOBJ);
1507-
jsonObj.pushKV("objects_total", (int)mapObjects.size());
1507+
jsonObj.pushKV("objects_total", mapObjects.size());
15081508
jsonObj.pushKV("proposals", nProposalCount);
15091509
jsonObj.pushKV("triggers", nTriggerCount);
15101510
jsonObj.pushKV("other", nOtherCount);
1511-
jsonObj.pushKV("erased", (int)mapErasedGovernanceObjects.size());
1512-
jsonObj.pushKV("votes", (int)cmapVoteToObject.GetSize());
1511+
jsonObj.pushKV("erased", mapErasedGovernanceObjects.size());
1512+
jsonObj.pushKV("votes", cmapVoteToObject.GetSize());
15131513
return jsonObj;
15141514
}
15151515

src/llmq/commitment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CFinalCommitment
122122
[[nodiscard]] UniValue ToJson() const
123123
{
124124
UniValue obj(UniValue::VOBJ);
125-
obj.pushKV("version", int{nVersion});
125+
obj.pushKV("version", nVersion);
126126
obj.pushKV("llmqType", ToUnderlying(llmqType));
127127
obj.pushKV("quorumHash", quorumHash.ToString());
128128
obj.pushKV("quorumIndex", quorumIndex);

src/rpc/governance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ static RPCHelpMan getgovernanceinfo()
10181018
obj.pushKV("superblockmaturitywindow", Params().GetConsensus().nSuperblockMaturityWindow);
10191019
obj.pushKV("lastsuperblock", nLastSuperblock);
10201020
obj.pushKV("nextsuperblock", nNextSuperblock);
1021-
obj.pushKV("fundingthreshold", int(CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetValidWeightedMNsCount() / 10));
1021+
obj.pushKV("fundingthreshold", CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetValidWeightedMNsCount() / 10);
10221022
obj.pushKV("governancebudget", ValueFromAmount(CSuperblock::GetPaymentsLimit(chainman.ActiveChain(), nNextSuperblock)));
10231023

10241024
return obj;

src/rpc/masternode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static RPCHelpMan masternode_status()
180180
mnObj.pushKV("proTxHash", dmn->proTxHash.ToString());
181181
mnObj.pushKV("type", std::string(GetMnType(dmn->nType).description));
182182
mnObj.pushKV("collateralHash", dmn->collateralOutpoint.hash.ToString());
183-
mnObj.pushKV("collateralIndex", (int)dmn->collateralOutpoint.n);
183+
mnObj.pushKV("collateralIndex", dmn->collateralOutpoint.n);
184184
mnObj.pushKV("dmnState", dmn->pdmnState->ToJson(dmn->nType));
185185
}
186186
mnObj.pushKV("state", node.mn_activeman->GetStateString());

src/rpc/mempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, const llmq::CInstantSendManag
395395
ret.pushKV("maxmempool", maxmempool);
396396
ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee).GetFeePerK()));
397397
ret.pushKV("minrelaytxfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));
398-
ret.pushKV("instantsendlocks", (int64_t)isman.GetInstantSendLockCount());
399-
ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()});
398+
ret.pushKV("instantsendlocks", isman.GetInstantSendLockCount());
399+
ret.pushKV("unbroadcastcount", pool.GetUnbroadcastTxs().size());
400400
return ret;
401401
}
402402

src/rpc/node.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,12 @@ static RPCHelpMan getaddressmempool()
435435
UniValue delta(UniValue::VOBJ);
436436
delta.pushKV("address", address);
437437
delta.pushKV("txid", mempoolAddressKey.m_tx_hash.GetHex());
438-
delta.pushKV("index", (int)mempoolAddressKey.m_tx_index);
438+
delta.pushKV("index", mempoolAddressKey.m_tx_index);
439439
delta.pushKV("satoshis", mempoolAddressDelta.m_amount);
440440
delta.pushKV("timestamp", count_seconds(mempoolAddressDelta.m_time));
441441
if (mempoolAddressDelta.m_amount < 0) {
442442
delta.pushKV("prevtxid", mempoolAddressDelta.m_prev_hash.GetHex());
443-
delta.pushKV("prevout", (int)mempoolAddressDelta.m_prev_out);
443+
delta.pushKV("prevout", mempoolAddressDelta.m_prev_out);
444444
}
445445
result.push_back(delta);
446446
}
@@ -509,7 +509,7 @@ static RPCHelpMan getaddressutxos()
509509

510510
output.pushKV("address", address);
511511
output.pushKV("txid", unspentKey.m_tx_hash.GetHex());
512-
output.pushKV("outputIndex", (int)unspentKey.m_tx_index);
512+
output.pushKV("outputIndex", unspentKey.m_tx_index);
513513
output.pushKV("script", HexStr(unspentValue.m_tx_script));
514514
output.pushKV("satoshis", unspentValue.m_amount);
515515
output.pushKV("height", unspentValue.m_block_height);
@@ -596,8 +596,8 @@ static RPCHelpMan getaddressdeltas()
596596
UniValue delta(UniValue::VOBJ);
597597
delta.pushKV("satoshis", indexDelta);
598598
delta.pushKV("txid", indexKey.m_tx_hash.GetHex());
599-
delta.pushKV("index", (int)indexKey.m_tx_index);
600-
delta.pushKV("blockindex", (int)indexKey.m_block_tx_pos);
599+
delta.pushKV("index", indexKey.m_tx_index);
600+
delta.pushKV("blockindex", indexKey.m_block_tx_pos);
601601
delta.pushKV("height", indexKey.m_block_height);
602602
delta.pushKV("address", address);
603603
result.push_back(delta);

src/rpc/quorums.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static RPCHelpMan quorum_list_extended()
164164
}
165165
j.pushKV("creationHeight", q->m_quorum_base_block_index->nHeight);
166166
j.pushKV("minedBlockHash", q->minedBlockHash.ToString());
167-
j.pushKV("numValidMembers", (int32_t)num_valid_members);
167+
j.pushKV("numValidMembers", num_valid_members);
168168
j.pushKV("healthRatio", ss.str());
169169
obj.pushKV(q->qc->quorumHash.ToString(),j);
170170
}
@@ -916,7 +916,7 @@ static RPCHelpMan quorum_dkginfo()
916916
llmq::CDKGDebugStatus status;
917917
llmq_ctx.dkg_debugman->GetLocalDebugStatus(status);
918918
UniValue ret(UniValue::VOBJ);
919-
ret.pushKV("active_dkgs", int(status.sessions.size()));
919+
ret.pushKV("active_dkgs", status.sessions.size());
920920

921921
const int nTipHeight{WITH_LOCK(cs_main, return chainman.ActiveChain().Height())};
922922
auto minNextDKG = [](const Consensus::Params& consensusParams, int nTipHeight) {

0 commit comments

Comments
 (0)