From 35b5b0ff9e043c1e26a3e29fa3d9d914a0a86ad1 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 13 May 2024 20:20:10 +0000 Subject: [PATCH] rpc: avoid copying into UniValue These are simple (and hopefully obviously correct) copies that can be moves instead. --- src/bitcoin-cli.cpp | 6 +- src/core_write.cpp | 18 +++--- src/net_types.cpp | 2 +- src/rest.cpp | 6 +- src/rpc/blockchain.cpp | 24 +++---- src/rpc/client.cpp | 2 +- src/rpc/external_signer.cpp | 4 +- src/rpc/fees.cpp | 12 ++-- src/rpc/mempool.cpp | 34 +++++----- src/rpc/mining.cpp | 18 +++--- src/rpc/net.cpp | 32 +++++----- src/rpc/node.cpp | 2 +- src/rpc/output_script.cpp | 4 +- src/rpc/rawtransaction.cpp | 106 +++++++++++++++---------------- src/rpc/rawtransaction_util.cpp | 6 +- src/rpc/server.cpp | 6 +- src/rpc/util.cpp | 10 +-- src/test/script_tests.cpp | 2 +- src/wallet/rpc/addresses.cpp | 14 ++-- src/wallet/rpc/backup.cpp | 6 +- src/wallet/rpc/coins.cpp | 8 +-- src/wallet/rpc/spend.cpp | 6 +- src/wallet/rpc/transactions.cpp | 22 +++---- src/wallet/rpc/util.cpp | 4 +- src/wallet/rpc/wallet.cpp | 6 +- src/wallet/test/wallet_tests.cpp | 4 +- src/zmq/zmqrpc.cpp | 2 +- 27 files changed, 183 insertions(+), 183 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index c7ba2204c3fda..011f887cf0900 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -297,7 +297,7 @@ class AddrinfoRequestHandler : public BaseRequestHandler total += counts.at(i); } addresses.pushKV("total", total); - result.pushKV("addresses_known", addresses); + result.pushKV("addresses_known", std::move(addresses)); return JSONRPCReplyObj(result, NullUniValue, 1); } }; @@ -348,7 +348,7 @@ class GetinfoRequestHandler: public BaseRequestHandler connections.pushKV("in", batch[ID_NETWORKINFO]["result"]["connections_in"]); connections.pushKV("out", batch[ID_NETWORKINFO]["result"]["connections_out"]); connections.pushKV("total", batch[ID_NETWORKINFO]["result"]["connections"]); - result.pushKV("connections", connections); + result.pushKV("connections", std::move(connections)); result.pushKV("networks", batch[ID_NETWORKINFO]["result"]["networks"]); result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]); @@ -940,7 +940,7 @@ static void GetWalletBalances(UniValue& result) const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"]; balances.pushKV(wallet_name, balance); } - result.pushKV("balances", balances); + result.pushKV("balances", std::move(balances)); } /** diff --git a/src/core_write.cpp b/src/core_write.cpp index 63f2c36b5af23..3a2bf865fcbab 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -201,14 +201,14 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry UniValue o(UniValue::VOBJ); o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); o.pushKV("hex", HexStr(txin.scriptSig)); - in.pushKV("scriptSig", o); + in.pushKV("scriptSig", std::move(o)); } if (!tx.vin[i].scriptWitness.IsNull()) { UniValue txinwitness(UniValue::VARR); for (const auto& item : tx.vin[i].scriptWitness.stack) { txinwitness.push_back(HexStr(item)); } - in.pushKV("txinwitness", txinwitness); + in.pushKV("txinwitness", std::move(txinwitness)); } if (have_undo) { const Coin& prev_coin = txundo->vprevout[i]; @@ -224,14 +224,14 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry p.pushKV("generated", bool(prev_coin.fCoinBase)); p.pushKV("height", uint64_t(prev_coin.nHeight)); p.pushKV("value", ValueFromAmount(prev_txout.nValue)); - p.pushKV("scriptPubKey", o_script_pub_key); - in.pushKV("prevout", p); + p.pushKV("scriptPubKey", std::move(o_script_pub_key)); + in.pushKV("prevout", std::move(p)); } } in.pushKV("sequence", (int64_t)txin.nSequence); - vin.push_back(in); + vin.push_back(std::move(in)); } - entry.pushKV("vin", vin); + entry.pushKV("vin", std::move(vin)); UniValue vout(UniValue::VARR); for (unsigned int i = 0; i < tx.vout.size(); i++) { @@ -244,14 +244,14 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry UniValue o(UniValue::VOBJ); ScriptToUniv(txout.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true); - out.pushKV("scriptPubKey", o); - vout.push_back(out); + out.pushKV("scriptPubKey", std::move(o)); + vout.push_back(std::move(out)); if (have_undo) { amt_total_out += txout.nValue; } } - entry.pushKV("vout", vout); + entry.pushKV("vout", std::move(vout)); if (have_undo) { const CAmount fee = amt_total_in - amt_total_out; diff --git a/src/net_types.cpp b/src/net_types.cpp index fd6ad80404254..fb6ad595998e8 100644 --- a/src/net_types.cpp +++ b/src/net_types.cpp @@ -43,7 +43,7 @@ UniValue BanMapToJson(const banmap_t& bans) const auto& ban_entry = it.second; UniValue j = ban_entry.ToJson(); j.pushKV(BANMAN_JSON_ADDR_KEY, address.ToString()); - bans_json.push_back(j); + bans_json.push_back(std::move(j)); } return bans_json; } diff --git a/src/rest.cpp b/src/rest.cpp index 9fc5d4af047cf..4e9d8fd2b1845 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -934,10 +934,10 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std:: // include the script in a json output UniValue o(UniValue::VOBJ); ScriptToUniv(coin.out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true); - utxo.pushKV("scriptPubKey", o); - utxos.push_back(utxo); + utxo.pushKV("scriptPubKey", std::move(o)); + utxos.push_back(std::move(utxo)); } - objGetUTXOResponse.pushKV("utxos", utxos); + objGetUTXOResponse.pushKV("utxos", std::move(utxos)); // return json string std::string strJSON = objGetUTXOResponse.write() + "\n"; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1abaeafb2af5d..263d9f1e0ab23 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1025,9 +1025,9 @@ static RPCHelpMan gettxoutsetinfo() unspendables.pushKV("bip30", ValueFromAmount(stats.total_unspendables_bip30 - prev_stats.total_unspendables_bip30)); unspendables.pushKV("scripts", ValueFromAmount(stats.total_unspendables_scripts - prev_stats.total_unspendables_scripts)); unspendables.pushKV("unclaimed_rewards", ValueFromAmount(stats.total_unspendables_unclaimed_rewards - prev_stats.total_unspendables_unclaimed_rewards)); - block_info.pushKV("unspendables", unspendables); + block_info.pushKV("unspendables", std::move(unspendables)); - ret.pushKV("block_info", block_info); + ret.pushKV("block_info", std::move(block_info)); } } else { throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set"); @@ -1111,7 +1111,7 @@ static RPCHelpMan gettxout() ret.pushKV("value", ValueFromAmount(coin.out.nValue)); UniValue o(UniValue::VOBJ); ScriptToUniv(coin.out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true); - ret.pushKV("scriptPubKey", o); + ret.pushKV("scriptPubKey", std::move(o)); ret.pushKV("coinbase", (bool)coin.fCoinBase); return ret; @@ -1161,7 +1161,7 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo // one below the activation height rv.pushKV("active", DeploymentActiveAfter(blockindex, chainman, dep)); rv.pushKV("height", chainman.GetConsensus().DeploymentHeight(dep)); - softforks.pushKV(DeploymentName(dep), rv); + softforks.pushKV(DeploymentName(dep), std::move(rv)); } static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const ChainstateManager& chainman, Consensus::DeploymentPos id) @@ -1214,7 +1214,7 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo statsUV.pushKV("threshold", statsStruct.threshold); statsUV.pushKV("possible", statsStruct.possible); } - bip9.pushKV("statistics", statsUV); + bip9.pushKV("statistics", std::move(statsUV)); std::string sig; sig.reserve(signals.size()); @@ -1230,9 +1230,9 @@ static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softfo rv.pushKV("height", chainman.m_versionbitscache.StateSinceHeight(blockindex, chainman.GetConsensus(), id)); } rv.pushKV("active", ThresholdState::ACTIVE == next_state); - rv.pushKV("bip9", bip9); + rv.pushKV("bip9", std::move(bip9)); - softforks.pushKV(DeploymentName(id), rv); + softforks.pushKV(DeploymentName(id), std::move(rv)); } // used by rest.cpp:rest_chaininfo, so cannot be static @@ -1498,7 +1498,7 @@ static RPCHelpMan getchaintips() } obj.pushKV("status", status); - res.push_back(obj); + res.push_back(std::move(obj)); } return res; @@ -1978,7 +1978,7 @@ static RPCHelpMan getblockstats() ret_all.pushKV("avgfeerate", total_weight ? (totalfee * WITNESS_SCALE_FACTOR) / total_weight : 0); // Unit: sat/vbyte ret_all.pushKV("avgtxsize", (block.vtx.size() > 1) ? total_size / (block.vtx.size() - 1) : 0); ret_all.pushKV("blockhash", pindex.GetBlockHash().GetHex()); - ret_all.pushKV("feerate_percentiles", feerates_res); + ret_all.pushKV("feerate_percentiles", std::move(feerates_res)); ret_all.pushKV("height", (int64_t)pindex.nHeight); ret_all.pushKV("ins", inputs); ret_all.pushKV("maxfee", maxfee); @@ -2262,9 +2262,9 @@ static RPCHelpMan scantxoutset() unspent.pushKV("coinbase", coin.IsCoinBase()); unspent.pushKV("height", (int32_t)coin.nHeight); - unspents.push_back(unspent); + unspents.push_back(std::move(unspent)); } - result.pushKV("unspents", unspents); + result.pushKV("unspents", std::move(unspents)); result.pushKV("total_amount", ValueFromAmount(total_in)); } else { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", action)); @@ -2504,7 +2504,7 @@ static RPCHelpMan scanblocks() ret.pushKV("from_height", start_block_height); ret.pushKV("to_height", start_index->nHeight); // start_index is always the last scanned block here - ret.pushKV("relevant_blocks", blocks); + ret.pushKV("relevant_blocks", std::move(blocks)); ret.pushKV("completed", completed); } else { diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index b8dc148eaea2d..7dfe69a6c5021 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -391,7 +391,7 @@ UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vectorGetWitnessHash()); if (exit_early || it == package_result.m_tx_results.end()) { // Validation unfinished. Just return the txid and wtxid. - rpc_result.push_back(result_inner); + rpc_result.push_back(std::move(result_inner)); continue; } const auto& tx_result = it->second; @@ -229,8 +229,8 @@ static RPCHelpMan testmempoolaccept() for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) { effective_includes_res.push_back(wtxid.ToString()); } - fees.pushKV("effective-includes", effective_includes_res); - result_inner.pushKV("fees", fees); + fees.pushKV("effective-includes", std::move(effective_includes_res)); + result_inner.pushKV("fees", std::move(fees)); } } else { result_inner.pushKV("allowed", false); @@ -241,7 +241,7 @@ static RPCHelpMan testmempoolaccept() result_inner.pushKV("reject-reason", state.GetRejectReason()); } } - rpc_result.push_back(result_inner); + rpc_result.push_back(std::move(result_inner)); } return rpc_result; }, @@ -295,7 +295,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee())); fees.pushKV("ancestor", ValueFromAmount(e.GetModFeesWithAncestors())); fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants())); - info.pushKV("fees", fees); + info.pushKV("fees", std::move(fees)); const CTransaction& tx = e.GetTx(); std::set setDepends; @@ -311,14 +311,14 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool depends.push_back(dep); } - info.pushKV("depends", depends); + info.pushKV("depends", std::move(depends)); UniValue spent(UniValue::VARR); for (const CTxMemPoolEntry& child : e.GetMemPoolChildrenConst()) { spent.push_back(child.GetTx().GetHash().ToString()); } - info.pushKV("spentby", spent); + info.pushKV("spentby", std::move(spent)); // Add opt-in RBF status bool rbfStatus = false; @@ -347,7 +347,7 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo // Mempool has unique entries so there is no advantage in using // UniValue::pushKV, which checks if the key already exists in O(N). // UniValue::pushKVEnd is used instead which currently is O(1). - o.pushKVEnd(e.GetTx().GetHash().ToString(), info); + o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info)); } return o; } else { @@ -364,7 +364,7 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo return a; } else { UniValue o(UniValue::VOBJ); - o.pushKV("txids", a); + o.pushKV("txids", std::move(a)); o.pushKV("mempool_sequence", mempool_sequence); return o; } @@ -474,7 +474,7 @@ static RPCHelpMan getmempoolancestors() const uint256& _hash = e.GetTx().GetHash(); UniValue info(UniValue::VOBJ); entryToJSON(mempool, info, e); - o.pushKV(_hash.ToString(), info); + o.pushKV(_hash.ToString(), std::move(info)); } return o; } @@ -539,7 +539,7 @@ static RPCHelpMan getmempooldescendants() const uint256& _hash = e.GetTx().GetHash(); UniValue info(UniValue::VOBJ); entryToJSON(mempool, info, e); - o.pushKV(_hash.ToString(), info); + o.pushKV(_hash.ToString(), std::move(info)); } return o; } @@ -653,7 +653,7 @@ static RPCHelpMan gettxspendingprevout() o.pushKV("spendingtxid", spendingTx->GetHash().ToString()); } - result.push_back(o); + result.push_back(std::move(o)); } return result; @@ -992,20 +992,20 @@ static RPCHelpMan submitpackage() for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) { effective_includes_res.push_back(wtxid.ToString()); } - fees.pushKV("effective-includes", effective_includes_res); + fees.pushKV("effective-includes", std::move(effective_includes_res)); } - result_inner.pushKV("fees", fees); + result_inner.pushKV("fees", std::move(fees)); for (const auto& ptx : it->second.m_replaced_transactions) { replaced_txids.insert(ptx->GetHash()); } break; } - tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), result_inner); + tx_result_map.pushKV(tx->GetWitnessHash().GetHex(), std::move(result_inner)); } - rpc_result.pushKV("tx-results", tx_result_map); + rpc_result.pushKV("tx-results", std::move(tx_result_map)); UniValue replaced_list(UniValue::VARR); for (const uint256& hash : replaced_txids) replaced_list.push_back(hash.ToString()); - rpc_result.pushKV("replaced-transactions", replaced_list); + rpc_result.pushKV("replaced-transactions", std::move(replaced_list)); return rpc_result; }, }; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 2391392bd752c..606fc62dbe95d 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -529,7 +529,7 @@ static RPCHelpMan getprioritisedtransactions() if (delta_info.in_mempool) { result_inner.pushKV("modified_fee", *delta_info.modified_fee); } - rpc_result.pushKV(delta_info.txid.GetHex(), result_inner); + rpc_result.pushKV(delta_info.txid.GetHex(), std::move(result_inner)); } return rpc_result; }, @@ -854,7 +854,7 @@ static RPCHelpMan getblocktemplate() if (setTxIndex.count(in.prevout.hash)) deps.push_back(setTxIndex[in.prevout.hash]); } - entry.pushKV("depends", deps); + entry.pushKV("depends", std::move(deps)); int index_in_template = i - 1; entry.pushKV("fee", pblocktemplate->vTxFees[index_in_template]); @@ -866,7 +866,7 @@ static RPCHelpMan getblocktemplate() entry.pushKV("sigops", nTxSigOps); entry.pushKV("weight", GetTransactionWeight(tx)); - transactions.push_back(entry); + transactions.push_back(std::move(entry)); } UniValue aux(UniValue::VOBJ); @@ -879,7 +879,7 @@ static RPCHelpMan getblocktemplate() aMutable.push_back("prevblock"); UniValue result(UniValue::VOBJ); - result.pushKV("capabilities", aCaps); + result.pushKV("capabilities", std::move(aCaps)); UniValue aRules(UniValue::VARR); aRules.push_back("csv"); @@ -931,18 +931,18 @@ static RPCHelpMan getblocktemplate() } } result.pushKV("version", pblock->nVersion); - result.pushKV("rules", aRules); - result.pushKV("vbavailable", vbavailable); + result.pushKV("rules", std::move(aRules)); + result.pushKV("vbavailable", std::move(vbavailable)); result.pushKV("vbrequired", int(0)); result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex()); - result.pushKV("transactions", transactions); - result.pushKV("coinbaseaux", aux); + result.pushKV("transactions", std::move(transactions)); + result.pushKV("coinbaseaux", std::move(aux)); result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue); result.pushKV("longpollid", active_chain.Tip()->GetBlockHash().GetHex() + ToString(nTransactionsUpdatedLast)); result.pushKV("target", hashTarget.GetHex()); result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1); - result.pushKV("mutable", aMutable); + result.pushKV("mutable", std::move(aMutable)); result.pushKV("noncerange", "00000000ffffffff"); int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST; int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 59397aa84dd0c..b001b9c3529c0 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -263,7 +263,7 @@ static RPCHelpMan getpeerinfo() for (const int height : statestats.vHeightInFlight) { heights.push_back(height); } - obj.pushKV("inflight", heights); + obj.pushKV("inflight", std::move(heights)); obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled); obj.pushKV("addr_processed", statestats.m_addr_processed); obj.pushKV("addr_rate_limited", statestats.m_addr_rate_limited); @@ -271,7 +271,7 @@ static RPCHelpMan getpeerinfo() for (const auto& permission : NetPermissions::ToStrings(stats.m_permission_flags)) { permissions.push_back(permission); } - obj.pushKV("permissions", permissions); + obj.pushKV("permissions", std::move(permissions)); obj.pushKV("minfeefilter", ValueFromAmount(statestats.m_fee_filter_received)); UniValue sendPerMsgType(UniValue::VOBJ); @@ -279,19 +279,19 @@ static RPCHelpMan getpeerinfo() if (i.second > 0) sendPerMsgType.pushKV(i.first, i.second); } - obj.pushKV("bytessent_per_msg", sendPerMsgType); + obj.pushKV("bytessent_per_msg", std::move(sendPerMsgType)); UniValue recvPerMsgType(UniValue::VOBJ); for (const auto& i : stats.mapRecvBytesPerMsgType) { if (i.second > 0) recvPerMsgType.pushKV(i.first, i.second); } - obj.pushKV("bytesrecv_per_msg", recvPerMsgType); + obj.pushKV("bytesrecv_per_msg", std::move(recvPerMsgType)); obj.pushKV("connection_type", ConnectionTypeAsString(stats.m_conn_type)); obj.pushKV("transport_protocol_type", TransportTypeAsString(stats.m_transport_type)); obj.pushKV("session_id", stats.m_session_id); - ret.push_back(obj); + ret.push_back(std::move(obj)); } return ret; @@ -532,10 +532,10 @@ static RPCHelpMan getaddednodeinfo() UniValue address(UniValue::VOBJ); address.pushKV("address", info.resolvedAddress.ToStringAddrPort()); address.pushKV("connected", info.fInbound ? "inbound" : "outbound"); - addresses.push_back(address); + addresses.push_back(std::move(address)); } - obj.pushKV("addresses", addresses); - ret.push_back(obj); + obj.pushKV("addresses", std::move(addresses)); + ret.push_back(std::move(obj)); } return ret; @@ -587,7 +587,7 @@ static RPCHelpMan getnettotals() outboundLimit.pushKV("serve_historical_blocks", !connman.OutboundTargetReached(true)); outboundLimit.pushKV("bytes_left_in_cycle", connman.GetOutboundTargetBytesLeft()); outboundLimit.pushKV("time_left_in_cycle", count_seconds(connman.GetMaxOutboundTimeLeftInCycle())); - obj.pushKV("uploadtarget", outboundLimit); + obj.pushKV("uploadtarget", std::move(outboundLimit)); return obj; }, }; @@ -607,7 +607,7 @@ static UniValue GetNetworksInfo() obj.pushKV("reachable", g_reachable_nets.Contains(network)); obj.pushKV("proxy", proxy.IsValid() ? proxy.ToString() : std::string()); obj.pushKV("proxy_randomize_credentials", proxy.m_randomize_credentials); - networks.push_back(obj); + networks.push_back(std::move(obj)); } return networks; } @@ -709,10 +709,10 @@ static RPCHelpMan getnetworkinfo() rec.pushKV("address", item.first.ToStringAddr()); rec.pushKV("port", item.second.nPort); rec.pushKV("score", item.second.nScore); - localAddresses.push_back(rec); + localAddresses.push_back(std::move(rec)); } } - obj.pushKV("localaddresses", localAddresses); + obj.pushKV("localaddresses", std::move(localAddresses)); obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings"))); return obj; }, @@ -843,7 +843,7 @@ static RPCHelpMan listbanned() rec.pushKV("ban_duration", (banEntry.nBanUntil - banEntry.nCreateTime)); rec.pushKV("time_remaining", (banEntry.nBanUntil - current_time)); - bannedAddresses.push_back(rec); + bannedAddresses.push_back(std::move(rec)); } return bannedAddresses; @@ -947,7 +947,7 @@ static RPCHelpMan getnodeaddresses() obj.pushKV("address", addr.ToStringAddr()); obj.pushKV("port", addr.GetPort()); obj.pushKV("network", GetNetworkName(addr.GetNetClass())); - ret.push_back(obj); + ret.push_back(std::move(obj)); } return ret; }, @@ -1087,13 +1087,13 @@ static RPCHelpMan getaddrmaninfo() obj.pushKV("new", addrman.Size(network, true)); obj.pushKV("tried", addrman.Size(network, false)); obj.pushKV("total", addrman.Size(network)); - ret.pushKV(GetNetworkName(network), obj); + ret.pushKV(GetNetworkName(network), std::move(obj)); } UniValue obj(UniValue::VOBJ); obj.pushKV("new", addrman.Size(std::nullopt, true)); obj.pushKV("tried", addrman.Size(std::nullopt, false)); obj.pushKV("total", addrman.Size()); - ret.pushKV("all_networks", obj); + ret.pushKV("all_networks", std::move(obj)); return ret; }, }; diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 447be2cf6440a..65b0a93cdd576 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -351,7 +351,7 @@ static UniValue SummaryToJSON(const IndexSummary&& summary, std::string index_na UniValue entry(UniValue::VOBJ); entry.pushKV("synced", summary.synced); entry.pushKV("best_block_height", summary.best_block_height); - ret_summary.pushKV(summary.name, entry); + ret_summary.pushKV(summary.name, std::move(entry)); return ret_summary; } diff --git a/src/rpc/output_script.cpp b/src/rpc/output_script.cpp index 474d9076be031..f771b31db0083 100644 --- a/src/rpc/output_script.cpp +++ b/src/rpc/output_script.cpp @@ -72,11 +72,11 @@ static RPCHelpMan validateaddress() ret.pushKV("scriptPubKey", HexStr(scriptPubKey)); UniValue detail = DescribeAddress(dest); - ret.pushKVs(detail); + ret.pushKVs(std::move(detail)); } else { UniValue error_indices(UniValue::VARR); for (int i : error_locations) error_indices.push_back(i); - ret.pushKV("error_locations", error_indices); + ret.pushKV("error_locations", std::move(error_indices)); ret.pushKV("error", error_msg); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 634be2f7fb9d6..7fa6652f9eb9d 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -618,7 +618,7 @@ static RPCHelpMan decodescript() } ScriptToUniv(segwitScr, /*out=*/sr, /*include_hex=*/true, /*include_address=*/true, /*provider=*/&provider); sr.pushKV("p2sh-segwit", EncodeDestination(ScriptHash(segwitScr))); - r.pushKV("segwit", sr); + r.pushKV("segwit", std::move(sr)); } } @@ -1069,7 +1069,7 @@ static RPCHelpMan decodepsbt() // Add the decoded tx UniValue tx_univ(UniValue::VOBJ); TxToUniv(CTransaction(*psbtx.tx), /*block_hash=*/uint256(), /*entry=*/tx_univ, /*include_hex=*/false); - result.pushKV("tx", tx_univ); + result.pushKV("tx", std::move(tx_univ)); // Add the global xpubs UniValue global_xpubs(UniValue::VARR); @@ -1083,10 +1083,10 @@ static RPCHelpMan decodepsbt() keypath.pushKV("xpub", EncodeBase58Check(ser_xpub)); keypath.pushKV("master_fingerprint", HexStr(Span(xpub_pair.first.fingerprint, xpub_pair.first.fingerprint + 4))); keypath.pushKV("path", WriteHDKeypath(xpub_pair.first.path)); - global_xpubs.push_back(keypath); + global_xpubs.push_back(std::move(keypath)); } } - result.pushKV("global_xpubs", global_xpubs); + result.pushKV("global_xpubs", std::move(global_xpubs)); // PSBT version result.pushKV("psbt_version", static_cast(psbtx.GetVersion())); @@ -1099,16 +1099,16 @@ static RPCHelpMan decodepsbt() this_prop.pushKV("subtype", entry.subtype); this_prop.pushKV("key", HexStr(entry.key)); this_prop.pushKV("value", HexStr(entry.value)); - proprietary.push_back(this_prop); + proprietary.push_back(std::move(this_prop)); } - result.pushKV("proprietary", proprietary); + result.pushKV("proprietary", std::move(proprietary)); // Unknown data UniValue unknowns(UniValue::VOBJ); for (auto entry : psbtx.unknown) { unknowns.pushKV(HexStr(entry.first), HexStr(entry.second)); } - result.pushKV("unknown", unknowns); + result.pushKV("unknown", std::move(unknowns)); // inputs CAmount total_in = 0; @@ -1128,9 +1128,9 @@ static RPCHelpMan decodepsbt() UniValue out(UniValue::VOBJ); out.pushKV("amount", ValueFromAmount(txout.nValue)); - out.pushKV("scriptPubKey", o); + out.pushKV("scriptPubKey", std::move(o)); - in.pushKV("witness_utxo", out); + in.pushKV("witness_utxo", std::move(out)); have_a_utxo = true; } @@ -1139,7 +1139,7 @@ static RPCHelpMan decodepsbt() UniValue non_wit(UniValue::VOBJ); TxToUniv(*input.non_witness_utxo, /*block_hash=*/uint256(), /*entry=*/non_wit, /*include_hex=*/false); - in.pushKV("non_witness_utxo", non_wit); + in.pushKV("non_witness_utxo", std::move(non_wit)); have_a_utxo = true; } @@ -1160,7 +1160,7 @@ static RPCHelpMan decodepsbt() for (const auto& sig : input.partial_sigs) { partial_sigs.pushKV(HexStr(sig.second.first), HexStr(sig.second.second)); } - in.pushKV("partial_signatures", partial_sigs); + in.pushKV("partial_signatures", std::move(partial_sigs)); } // Sighash @@ -1172,12 +1172,12 @@ static RPCHelpMan decodepsbt() if (!input.redeem_script.empty()) { UniValue r(UniValue::VOBJ); ScriptToUniv(input.redeem_script, /*out=*/r); - in.pushKV("redeem_script", r); + in.pushKV("redeem_script", std::move(r)); } if (!input.witness_script.empty()) { UniValue r(UniValue::VOBJ); ScriptToUniv(input.witness_script, /*out=*/r); - in.pushKV("witness_script", r); + in.pushKV("witness_script", std::move(r)); } // keypaths @@ -1189,9 +1189,9 @@ static RPCHelpMan decodepsbt() keypath.pushKV("master_fingerprint", strprintf("%08x", ReadBE32(entry.second.fingerprint))); keypath.pushKV("path", WriteHDKeypath(entry.second.path)); - keypaths.push_back(keypath); + keypaths.push_back(std::move(keypath)); } - in.pushKV("bip32_derivs", keypaths); + in.pushKV("bip32_derivs", std::move(keypaths)); } // Final scriptSig and scriptwitness @@ -1199,14 +1199,14 @@ static RPCHelpMan decodepsbt() UniValue scriptsig(UniValue::VOBJ); scriptsig.pushKV("asm", ScriptToAsmStr(input.final_script_sig, true)); scriptsig.pushKV("hex", HexStr(input.final_script_sig)); - in.pushKV("final_scriptSig", scriptsig); + in.pushKV("final_scriptSig", std::move(scriptsig)); } if (!input.final_script_witness.IsNull()) { UniValue txinwitness(UniValue::VARR); for (const auto& item : input.final_script_witness.stack) { txinwitness.push_back(HexStr(item)); } - in.pushKV("final_scriptwitness", txinwitness); + in.pushKV("final_scriptwitness", std::move(txinwitness)); } // Ripemd160 hash preimages @@ -1215,7 +1215,7 @@ static RPCHelpMan decodepsbt() for (const auto& [hash, preimage] : input.ripemd160_preimages) { ripemd160_preimages.pushKV(HexStr(hash), HexStr(preimage)); } - in.pushKV("ripemd160_preimages", ripemd160_preimages); + in.pushKV("ripemd160_preimages", std::move(ripemd160_preimages)); } // Sha256 hash preimages @@ -1224,7 +1224,7 @@ static RPCHelpMan decodepsbt() for (const auto& [hash, preimage] : input.sha256_preimages) { sha256_preimages.pushKV(HexStr(hash), HexStr(preimage)); } - in.pushKV("sha256_preimages", sha256_preimages); + in.pushKV("sha256_preimages", std::move(sha256_preimages)); } // Hash160 hash preimages @@ -1233,7 +1233,7 @@ static RPCHelpMan decodepsbt() for (const auto& [hash, preimage] : input.hash160_preimages) { hash160_preimages.pushKV(HexStr(hash), HexStr(preimage)); } - in.pushKV("hash160_preimages", hash160_preimages); + in.pushKV("hash160_preimages", std::move(hash160_preimages)); } // Hash256 hash preimages @@ -1242,7 +1242,7 @@ static RPCHelpMan decodepsbt() for (const auto& [hash, preimage] : input.hash256_preimages) { hash256_preimages.pushKV(HexStr(hash), HexStr(preimage)); } - in.pushKV("hash256_preimages", hash256_preimages); + in.pushKV("hash256_preimages", std::move(hash256_preimages)); } // Taproot key path signature @@ -1259,9 +1259,9 @@ static RPCHelpMan decodepsbt() sigobj.pushKV("pubkey", HexStr(xonly)); sigobj.pushKV("leaf_hash", HexStr(leaf_hash)); sigobj.pushKV("sig", HexStr(sig)); - script_sigs.push_back(sigobj); + script_sigs.push_back(std::move(sigobj)); } - in.pushKV("taproot_script_path_sigs", script_sigs); + in.pushKV("taproot_script_path_sigs", std::move(script_sigs)); } // Taproot leaf scripts @@ -1276,10 +1276,10 @@ static RPCHelpMan decodepsbt() for (const auto& control_block : control_blocks) { control_blocks_univ.push_back(HexStr(control_block)); } - script_info.pushKV("control_blocks", control_blocks_univ); - tap_scripts.push_back(script_info); + script_info.pushKV("control_blocks", std::move(control_blocks_univ)); + tap_scripts.push_back(std::move(script_info)); } - in.pushKV("taproot_scripts", tap_scripts); + in.pushKV("taproot_scripts", std::move(tap_scripts)); } // Taproot bip32 keypaths @@ -1295,10 +1295,10 @@ static RPCHelpMan decodepsbt() for (const auto& leaf_hash : leaf_hashes) { leaf_hashes_arr.push_back(HexStr(leaf_hash)); } - path_obj.pushKV("leaf_hashes", leaf_hashes_arr); - keypaths.push_back(path_obj); + path_obj.pushKV("leaf_hashes", std::move(leaf_hashes_arr)); + keypaths.push_back(std::move(path_obj)); } - in.pushKV("taproot_bip32_derivs", keypaths); + in.pushKV("taproot_bip32_derivs", std::move(keypaths)); } // Taproot internal key @@ -1320,9 +1320,9 @@ static RPCHelpMan decodepsbt() this_prop.pushKV("subtype", entry.subtype); this_prop.pushKV("key", HexStr(entry.key)); this_prop.pushKV("value", HexStr(entry.value)); - proprietary.push_back(this_prop); + proprietary.push_back(std::move(this_prop)); } - in.pushKV("proprietary", proprietary); + in.pushKV("proprietary", std::move(proprietary)); } // Unknown data @@ -1331,12 +1331,12 @@ static RPCHelpMan decodepsbt() for (auto entry : input.unknown) { unknowns.pushKV(HexStr(entry.first), HexStr(entry.second)); } - in.pushKV("unknown", unknowns); + in.pushKV("unknown", std::move(unknowns)); } - inputs.push_back(in); + inputs.push_back(std::move(in)); } - result.pushKV("inputs", inputs); + result.pushKV("inputs", std::move(inputs)); // outputs CAmount output_value = 0; @@ -1348,12 +1348,12 @@ static RPCHelpMan decodepsbt() if (!output.redeem_script.empty()) { UniValue r(UniValue::VOBJ); ScriptToUniv(output.redeem_script, /*out=*/r); - out.pushKV("redeem_script", r); + out.pushKV("redeem_script", std::move(r)); } if (!output.witness_script.empty()) { UniValue r(UniValue::VOBJ); ScriptToUniv(output.witness_script, /*out=*/r); - out.pushKV("witness_script", r); + out.pushKV("witness_script", std::move(r)); } // keypaths @@ -1364,9 +1364,9 @@ static RPCHelpMan decodepsbt() keypath.pushKV("pubkey", HexStr(entry.first)); keypath.pushKV("master_fingerprint", strprintf("%08x", ReadBE32(entry.second.fingerprint))); keypath.pushKV("path", WriteHDKeypath(entry.second.path)); - keypaths.push_back(keypath); + keypaths.push_back(std::move(keypath)); } - out.pushKV("bip32_derivs", keypaths); + out.pushKV("bip32_derivs", std::move(keypaths)); } // Taproot internal key @@ -1382,9 +1382,9 @@ static RPCHelpMan decodepsbt() elem.pushKV("depth", (int)depth); elem.pushKV("leaf_ver", (int)leaf_ver); elem.pushKV("script", HexStr(script)); - tree.push_back(elem); + tree.push_back(std::move(elem)); } - out.pushKV("taproot_tree", tree); + out.pushKV("taproot_tree", std::move(tree)); } // Taproot bip32 keypaths @@ -1400,10 +1400,10 @@ static RPCHelpMan decodepsbt() for (const auto& leaf_hash : leaf_hashes) { leaf_hashes_arr.push_back(HexStr(leaf_hash)); } - path_obj.pushKV("leaf_hashes", leaf_hashes_arr); - keypaths.push_back(path_obj); + path_obj.pushKV("leaf_hashes", std::move(leaf_hashes_arr)); + keypaths.push_back(std::move(path_obj)); } - out.pushKV("taproot_bip32_derivs", keypaths); + out.pushKV("taproot_bip32_derivs", std::move(keypaths)); } // Proprietary @@ -1415,9 +1415,9 @@ static RPCHelpMan decodepsbt() this_prop.pushKV("subtype", entry.subtype); this_prop.pushKV("key", HexStr(entry.key)); this_prop.pushKV("value", HexStr(entry.value)); - proprietary.push_back(this_prop); + proprietary.push_back(std::move(this_prop)); } - out.pushKV("proprietary", proprietary); + out.pushKV("proprietary", std::move(proprietary)); } // Unknown data @@ -1426,10 +1426,10 @@ static RPCHelpMan decodepsbt() for (auto entry : output.unknown) { unknowns.pushKV(HexStr(entry.first), HexStr(entry.second)); } - out.pushKV("unknown", unknowns); + out.pushKV("unknown", std::move(unknowns)); } - outputs.push_back(out); + outputs.push_back(std::move(out)); // Fee calculation if (MoneyRange(psbtx.tx->vout[i].nValue) && MoneyRange(output_value + psbtx.tx->vout[i].nValue)) { @@ -1439,7 +1439,7 @@ static RPCHelpMan decodepsbt() have_all_utxos = false; } } - result.pushKV("outputs", outputs); + result.pushKV("outputs", std::move(outputs)); if (have_all_utxos) { result.pushKV("fee", ValueFromAmount(total_in - output_value)); } @@ -1876,7 +1876,7 @@ static RPCHelpMan analyzepsbt() for (const CKeyID& pubkey : input.missing_pubkeys) { missing_pubkeys_univ.push_back(HexStr(pubkey)); } - missing.pushKV("pubkeys", missing_pubkeys_univ); + missing.pushKV("pubkeys", std::move(missing_pubkeys_univ)); } if (!input.missing_redeem_script.IsNull()) { missing.pushKV("redeemscript", HexStr(input.missing_redeem_script)); @@ -1889,14 +1889,14 @@ static RPCHelpMan analyzepsbt() for (const CKeyID& pubkey : input.missing_sigs) { missing_sigs_univ.push_back(HexStr(pubkey)); } - missing.pushKV("signatures", missing_sigs_univ); + missing.pushKV("signatures", std::move(missing_sigs_univ)); } if (!missing.getKeys().empty()) { - input_univ.pushKV("missing", missing); + input_univ.pushKV("missing", std::move(missing)); } - inputs_result.push_back(input_univ); + inputs_result.push_back(std::move(input_univ)); } - if (!inputs_result.empty()) result.pushKV("inputs", inputs_result); + if (!inputs_result.empty()) result.pushKV("inputs", std::move(inputs_result)); if (psbta.estimated_vsize != std::nullopt) { result.pushKV("estimated_vsize", (int)*psbta.estimated_vsize); diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp index a9e11622a7aea..a62f90215a023 100644 --- a/src/rpc/rawtransaction_util.cpp +++ b/src/rpc/rawtransaction_util.cpp @@ -174,11 +174,11 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std:: for (unsigned int i = 0; i < txin.scriptWitness.stack.size(); i++) { witness.push_back(HexStr(txin.scriptWitness.stack[i])); } - entry.pushKV("witness", witness); + entry.pushKV("witness", std::move(witness)); entry.pushKV("scriptSig", HexStr(txin.scriptSig)); entry.pushKV("sequence", (uint64_t)txin.nSequence); entry.pushKV("error", strMessage); - vErrorsRet.push_back(entry); + vErrorsRet.push_back(std::move(entry)); } void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keystore, std::map& coins) @@ -331,6 +331,6 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const if (result.exists("errors")) { vErrors.push_backV(result["errors"].getValues()); } - result.pushKV("errors", vErrors); + result.pushKV("errors", std::move(vErrors)); } } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index a800451f4a04f..182700d785957 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -241,15 +241,15 @@ static RPCHelpMan getrpcinfo() UniValue entry(UniValue::VOBJ); entry.pushKV("method", info.method); entry.pushKV("duration", int64_t{Ticks(SteadyClock::now() - info.start)}); - active_commands.push_back(entry); + active_commands.push_back(std::move(entry)); } UniValue result(UniValue::VOBJ); - result.pushKV("active_commands", active_commands); + result.pushKV("active_commands", std::move(active_commands)); const std::string path = LogInstance().m_file_path.utf8string(); UniValue log_path(UniValue::VSTR, path); - result.pushKV("logpath", log_path); + result.pushKV("logpath", std::move(log_path)); return result; } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 9a7c731afe903..97ca3a48ca369 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -645,7 +645,7 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) const mismatch.setNull(); break; } - mismatch.push_back(match); + mismatch.push_back(std::move(match)); } if (!mismatch.isNull()) { std::string explain{ @@ -818,7 +818,7 @@ UniValue RPCHelpMan::GetArgMap() const map.push_back(arg_name); map.push_back(type == RPCArg::Type::STR || type == RPCArg::Type::STR_HEX); - arr.push_back(map); + arr.push_back(std::move(map)); }; for (int i{0}; i < int(m_args.size()); ++i) { @@ -1124,7 +1124,7 @@ UniValue RPCResult::MatchesType(const UniValue& result) const // If there are more results than documented, reuse the last doc_inner. const RPCResult& doc_inner{m_inner.at(std::min(m_inner.size() - 1, i))}; UniValue match{doc_inner.MatchesType(result.get_array()[i])}; - if (!match.isTrue()) errors.pushKV(strprintf("%d", i), match); + if (!match.isTrue()) errors.pushKV(strprintf("%d", i), std::move(match)); } if (errors.empty()) return true; // empty result array is valid return errors; @@ -1137,7 +1137,7 @@ UniValue RPCResult::MatchesType(const UniValue& result) const const RPCResult& doc_inner{m_inner.at(0)}; // Assume all types are the same, randomly pick the first for (size_t i{0}; i < result.get_obj().size(); ++i) { UniValue match{doc_inner.MatchesType(result.get_obj()[i])}; - if (!match.isTrue()) errors.pushKV(result.getKeys()[i], match); + if (!match.isTrue()) errors.pushKV(result.getKeys()[i], std::move(match)); } if (errors.empty()) return true; // empty result obj is valid return errors; @@ -1163,7 +1163,7 @@ UniValue RPCResult::MatchesType(const UniValue& result) const continue; } UniValue match{doc_entry.MatchesType(result_it->second)}; - if (!match.isTrue()) errors.pushKV(doc_entry.m_key_name, match); + if (!match.isTrue()) errors.pushKV(doc_entry.m_key_name, std::move(match)); } if (errors.empty()) return true; return errors; diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index e4142e203cb04..4618e8e2ffe2b 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -396,7 +396,7 @@ class TestBuilder wit.push_back(HexStr(scriptWitness.stack[i])); } wit.push_back(ValueFromAmount(nValue)); - array.push_back(wit); + array.push_back(std::move(wit)); } array.push_back(FormatScript(spendTx.vin[0].scriptSig)); array.push_back(FormatScript(creditTx->vout[0].scriptPubKey)); diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index 65587f0b18802..17bb6320a12ca 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -206,9 +206,9 @@ RPCHelpMan listaddressgroupings() addressInfo.push_back(address_book_entry->GetLabel()); } } - jsonGrouping.push_back(addressInfo); + jsonGrouping.push_back(std::move(addressInfo)); } - jsonGroupings.push_back(jsonGrouping); + jsonGroupings.push_back(std::move(jsonGrouping)); } return jsonGroupings; }, @@ -407,9 +407,9 @@ class DescribeWalletAddressVisitor // Only when the script corresponds to an address. UniValue subobj(UniValue::VOBJ); UniValue detail = DescribeAddress(embedded); - subobj.pushKVs(detail); + subobj.pushKVs(std::move(detail)); UniValue wallet_detail = std::visit(*this, embedded); - subobj.pushKVs(wallet_detail); + subobj.pushKVs(std::move(wallet_detail)); subobj.pushKV("address", EncodeDestination(embedded)); subobj.pushKV("scriptPubKey", HexStr(subscript)); // Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works. @@ -490,7 +490,7 @@ static UniValue DescribeWalletAddress(const CWallet& wallet, const CTxDestinatio CScript script = GetScriptForDestination(dest); std::unique_ptr provider = nullptr; provider = wallet.GetSolvingProvider(script); - ret.pushKVs(detail); + ret.pushKVs(std::move(detail)); ret.pushKVs(std::visit(DescribeWalletAddressVisitor(provider.get()), dest)); return ret; } @@ -607,7 +607,7 @@ RPCHelpMan getaddressinfo() ret.pushKV("iswatchonly", bool(mine & ISMINE_WATCH_ONLY)); UniValue detail = DescribeWalletAddress(*pwallet, dest); - ret.pushKVs(detail); + ret.pushKVs(std::move(detail)); ret.pushKV("ischange", ScriptIsChange(*pwallet, scriptPubKey)); @@ -688,7 +688,7 @@ RPCHelpMan getaddressesbylabel() // which currently is O(1). UniValue value(UniValue::VOBJ); value.pushKV("purpose", _purpose ? PurposeToString(*_purpose) : "unknown"); - ret.pushKVEnd(address, value); + ret.pushKVEnd(address, std::move(value)); } }); diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 8d3eea59ee0c6..a76ae7196c94c 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1827,16 +1827,16 @@ RPCHelpMan listdescriptors() UniValue range(UniValue::VARR); range.push_back(info.range->first); range.push_back(info.range->second - 1); - spk.pushKV("range", range); + spk.pushKV("range", std::move(range)); spk.pushKV("next", info.next_index); spk.pushKV("next_index", info.next_index); } - descriptors.push_back(spk); + descriptors.push_back(std::move(spk)); } UniValue response(UniValue::VOBJ); response.pushKV("wallet_name", wallet->GetName()); - response.pushKV("descriptors", descriptors); + response.pushKV("descriptors", std::move(descriptors)); return response; }, diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index b6c7396f4ba2c..2cf94a5722304 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -416,7 +416,7 @@ RPCHelpMan listlockunspent() o.pushKV("txid", outpt.hash.GetHex()); o.pushKV("vout", (int)outpt.n); - ret.push_back(o); + ret.push_back(std::move(o)); } return ret; @@ -477,7 +477,7 @@ RPCHelpMan getbalances() const auto full_bal = GetBalance(wallet, 0, false); balances_mine.pushKV("used", ValueFromAmount(full_bal.m_mine_trusted + full_bal.m_mine_untrusted_pending - bal.m_mine_trusted - bal.m_mine_untrusted_pending)); } - balances.pushKV("mine", balances_mine); + balances.pushKV("mine", std::move(balances_mine)); } auto spk_man = wallet.GetLegacyScriptPubKeyMan(); if (spk_man && spk_man->HaveWatchOnly()) { @@ -485,7 +485,7 @@ RPCHelpMan getbalances() balances_watchonly.pushKV("trusted", ValueFromAmount(bal.m_watchonly_trusted)); balances_watchonly.pushKV("untrusted_pending", ValueFromAmount(bal.m_watchonly_untrusted_pending)); balances_watchonly.pushKV("immature", ValueFromAmount(bal.m_watchonly_immature)); - balances.pushKV("watchonly", balances_watchonly); + balances.pushKV("watchonly", std::move(balances_watchonly)); } AppendLastProcessedBlock(balances, wallet); @@ -724,7 +724,7 @@ RPCHelpMan listunspent() PushParentDescriptors(*pwallet, scriptPubKey, entry); if (avoid_reuse) entry.pushKV("reused", reused); entry.pushKV("safe", out.safe); - results.push_back(entry); + results.push_back(std::move(entry)); } return results; diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index 1a364a75edcd2..86c5492e0139d 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -718,7 +718,7 @@ static void SetOptionsInputWeights(const UniValue& inputs, UniValue& options) weights.push_back(input); } } - options.pushKV("input_weights", weights); + options.pushKV("input_weights", std::move(weights)); } RPCHelpMan fundrawtransaction() @@ -1167,7 +1167,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name) for (const bilingual_str& error : errors) { result_errors.push_back(error.original); } - result.pushKV("errors", result_errors); + result.pushKV("errors", std::move(result_errors)); return result; }, @@ -1388,7 +1388,7 @@ RPCHelpMan sendall() if (recipient.isStr()) { UniValue rkvp(UniValue::VOBJ); rkvp.pushKV(recipient.get_str(), 0); - recipient_key_value_pairs.push_back(rkvp); + recipient_key_value_pairs.push_back(std::move(rkvp)); addresses_without_amount.insert(recipient.get_str()); } else { recipient_key_value_pairs.push_back(recipient); diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index 05b340995d08f..5abc983701750 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -39,11 +39,11 @@ static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue UniValue conflicts(UniValue::VARR); for (const uint256& conflict : wallet.GetTxConflicts(wtx)) conflicts.push_back(conflict.GetHex()); - entry.pushKV("walletconflicts", conflicts); + entry.pushKV("walletconflicts", std::move(conflicts)); UniValue mempool_conflicts(UniValue::VARR); for (const Txid& mempool_conflict : wtx.mempool_conflicts) mempool_conflicts.push_back(mempool_conflict.GetHex()); - entry.pushKV("mempoolconflicts", mempool_conflicts); + entry.pushKV("mempoolconflicts", std::move(mempool_conflicts)); entry.pushKV("time", wtx.GetTxTime()); entry.pushKV("timereceived", int64_t{wtx.nTimeReceived}); @@ -172,8 +172,8 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons transactions.push_back(_item.GetHex()); } } - obj.pushKV("txids", transactions); - ret.push_back(obj); + obj.pushKV("txids", std::move(transactions)); + ret.push_back(std::move(obj)); } }; @@ -195,7 +195,7 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons obj.pushKV("amount", ValueFromAmount(nAmount)); obj.pushKV("confirmations", (nConf == std::numeric_limits::max() ? 0 : nConf)); obj.pushKV("label", entry.first); - ret.push_back(obj); + ret.push_back(std::move(obj)); } } @@ -353,7 +353,7 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM if (fLong) WalletTxToJSON(wallet, wtx, entry); entry.pushKV("abandoned", wtx.isAbandoned()); - ret.push_back(entry); + ret.push_back(std::move(entry)); } } @@ -396,7 +396,7 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM entry.pushKV("abandoned", wtx.isAbandoned()); if (fLong) WalletTxToJSON(wallet, wtx, entry); - ret.push_back(entry); + ret.push_back(std::move(entry)); } } } @@ -682,8 +682,8 @@ RPCHelpMan listsinceblock() CHECK_NONFATAL(wallet.chain().findAncestorByHeight(wallet.GetLastBlockHash(), wallet.GetLastBlockHeight() + 1 - target_confirms, FoundBlock().hash(lastblock))); UniValue ret(UniValue::VOBJ); - ret.pushKV("transactions", transactions); - if (include_removed) ret.pushKV("removed", removed); + ret.pushKV("transactions", std::move(transactions)); + if (include_removed) ret.pushKV("removed", std::move(removed)); ret.pushKV("lastblock", lastblock.GetHex()); return ret; @@ -789,14 +789,14 @@ RPCHelpMan gettransaction() UniValue details(UniValue::VARR); ListTransactions(*pwallet, wtx, 0, false, details, filter, /*filter_label=*/std::nullopt); - entry.pushKV("details", details); + entry.pushKV("details", std::move(details)); entry.pushKV("hex", EncodeHexTx(*wtx.tx)); if (verbose) { UniValue decoded(UniValue::VOBJ); TxToUniv(*wtx.tx, /*block_hash=*/uint256(), /*entry=*/decoded, /*include_hex=*/false); - entry.pushKV("decoded", decoded); + entry.pushKV("decoded", std::move(decoded)); } AppendLastProcessedBlock(entry, *pwallet); diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index 1252843e9d0c3..eb23c4555bb31 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -149,7 +149,7 @@ void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, for (const auto& desc: wallet.GetWalletDescriptors(script_pubkey)) { parent_descs.push_back(desc.descriptor->ToString()); } - entry.pushKV("parent_descs", parent_descs); + entry.pushKV("parent_descs", std::move(parent_descs)); } void HandleWalletError(const std::shared_ptr wallet, DatabaseStatus& status, bilingual_str& error) @@ -185,7 +185,7 @@ void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_ UniValue lastprocessedblock{UniValue::VOBJ}; lastprocessedblock.pushKV("hash", wallet.GetLastBlockHash().GetHex()); lastprocessedblock.pushKV("height", wallet.GetLastBlockHeight()); - entry.pushKV("lastprocessedblock", lastprocessedblock); + entry.pushKV("lastprocessedblock", std::move(lastprocessedblock)); } } // namespace wallet diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index f1cb595271e5e..68331bf85f925 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -128,7 +128,7 @@ static RPCHelpMan getwalletinfo() UniValue scanning(UniValue::VOBJ); scanning.pushKV("duration", Ticks(pwallet->ScanningDuration())); scanning.pushKV("progress", pwallet->ScanningProgress()); - obj.pushKV("scanning", scanning); + obj.pushKV("scanning", std::move(scanning)); } else { obj.pushKV("scanning", false); } @@ -172,11 +172,11 @@ static RPCHelpMan listwalletdir() for (const auto& path : ListDatabases(GetWalletDir())) { UniValue wallet(UniValue::VOBJ); wallet.pushKV("name", path.utf8string()); - wallets.push_back(wallet); + wallets.push_back(std::move(wallet)); } UniValue result(UniValue::VOBJ); - result.pushKV("wallets", wallets); + result.pushKV("wallets", std::move(wallets)); return result; }, }; diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 3a67b9a4333c2..a04670de999dc 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -235,11 +235,11 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(futureKey.GetPubKey()))); key.pushKV("timestamp", newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1); key.pushKV("internal", UniValue(true)); - keys.push_back(key); + keys.push_back(std::move(key)); JSONRPCRequest request; request.context = &context; request.params.setArray(); - request.params.push_back(keys); + request.params.push_back(std::move(keys)); UniValue response = importmulti().HandleRequest(request); BOOST_CHECK_EQUAL(response.write(), diff --git a/src/zmq/zmqrpc.cpp b/src/zmq/zmqrpc.cpp index fcc2608262895..84995d12d32c0 100644 --- a/src/zmq/zmqrpc.cpp +++ b/src/zmq/zmqrpc.cpp @@ -47,7 +47,7 @@ static RPCHelpMan getzmqnotifications() obj.pushKV("type", n->GetType()); obj.pushKV("address", n->GetAddress()); obj.pushKV("hwm", n->GetOutboundMessageHighWaterMark()); - result.push_back(obj); + result.push_back(std::move(obj)); } }