From c65a10f349411d0585d5e67ef1192ef39d14a42a Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:31:26 +0700 Subject: [PATCH] refactor: use structure binding in for loop in rpc/misc Co-authored-by: Konstantin Akimov --- src/rpc/misc.cpp | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2bf14af50f..bdb9c5f986 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -708,19 +708,16 @@ static UniValue getaddressmempool(const JSONRPCRequest& request) UniValue result(UniValue::VARR); - for (const auto& index : indexes) { - const auto& mempoolAddressDeltaKey = index.first; - const auto& mempoolAddressDelta = index.second; - + for (const auto& [mempoolAddressKey, mempoolAddressDelta] : indexes) { std::string address; - if (!getAddressFromIndex(mempoolAddressDeltaKey.m_address_type, mempoolAddressDeltaKey.m_address_bytes, address)) { + if (!getAddressFromIndex(mempoolAddressKey.m_address_type, mempoolAddressKey.m_address_bytes, address)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown address type"); } UniValue delta(UniValue::VOBJ); delta.pushKV("address", address); - delta.pushKV("txid", mempoolAddressDeltaKey.m_tx_hash.GetHex()); - delta.pushKV("index", (int)mempoolAddressDeltaKey.m_tx_index); + delta.pushKV("txid", mempoolAddressKey.m_tx_hash.GetHex()); + delta.pushKV("index", (int)mempoolAddressKey.m_tx_index); delta.pushKV("satoshis", mempoolAddressDelta.m_amount); delta.pushKV("timestamp", count_seconds(mempoolAddressDelta.m_time)); if (mempoolAddressDelta.m_amount < 0) { @@ -781,10 +778,7 @@ static UniValue getaddressutxos(const JSONRPCRequest& request) UniValue result(UniValue::VARR); - for (const auto& unspentOutput : unspentOutputs) { - const auto& unspentKey = unspentOutput.first; - const auto& unspentValue = unspentOutput.second; - + for (const auto& [unspentKey, unspentValue] : unspentOutputs) { UniValue output(UniValue::VOBJ); std::string address; if (!getAddressFromIndex(unspentKey.m_address_type, unspentKey.m_address_bytes, address)) { @@ -870,9 +864,7 @@ static UniValue getaddressdeltas(const JSONRPCRequest& request) UniValue result(UniValue::VARR); - for (const auto& index : addressIndex) { - const auto& indexKey = index.first; - const auto& indexDelta = index.second; + for (const auto& [indexKey, indexDelta] : addressIndex) { std::string address; if (!getAddressFromIndex(indexKey.m_address_type, indexKey.m_address_bytes, address)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown address type"); @@ -938,9 +930,7 @@ static UniValue getaddressbalance(const JSONRPCRequest& request) CAmount balance_immature = 0; CAmount received = 0; - for (const auto& index : addressIndex) { - const auto& indexKey = index.first; - const auto& indexDelta = index.second; + for (const auto& [indexKey, indexDelta] : addressIndex) { if (indexDelta > 0) { received += indexDelta; } @@ -1017,9 +1007,7 @@ static UniValue getaddresstxids(const JSONRPCRequest& request) std::set > txids; UniValue result(UniValue::VARR); - for (const auto& index : addressIndex) { - const auto& indexKey = index.first; - + for (const auto& [indexKey, _]: addressIndex) { int height = indexKey.m_block_height; std::string txid = indexKey.m_tx_hash.GetHex();