Skip to content

Commit ba1bbb0

Browse files
committed
Merge #10892: Replace traditional for with ranged for in block and transaction primitives
72f0060 Replace traditional for with ranged for in primitives (Dag Robole) Pull request description: Replace traditional for with ranged for in block and transaction primitives to improve readability Tree-SHA512: c0fff603d2939149ca48b6aa72b59738a3658d49bd58b2d4ffbc85bdb774d8d5bb808fe526fe22bb9eb214de632834d373e2aab44f6019a83c0b09440cea6528
2 parents 8a99fe0 + 72f0060 commit ba1bbb0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/primitives/block.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ std::string CBlock::ToString() const
2525
hashMerkleRoot.ToString(),
2626
nTime, nBits, nNonce,
2727
vtx.size());
28-
for (unsigned int i = 0; i < vtx.size(); i++)
29-
{
30-
s << " " << vtx[i]->ToString() << "\n";
28+
for (const auto& tx : vtx) {
29+
s << " " << tx->ToString() << "\n";
3130
}
3231
return s.str();
3332
}

src/primitives/transaction.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vi
8383
CAmount CTransaction::GetValueOut() const
8484
{
8585
CAmount nValueOut = 0;
86-
for (std::vector<CTxOut>::const_iterator it(vout.begin()); it != vout.end(); ++it)
87-
{
88-
nValueOut += it->nValue;
89-
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
86+
for (const auto& tx_out : vout) {
87+
nValueOut += tx_out.nValue;
88+
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut))
9089
throw std::runtime_error(std::string(__func__) + ": value out of range");
9190
}
9291
return nValueOut;
@@ -106,11 +105,11 @@ std::string CTransaction::ToString() const
106105
vin.size(),
107106
vout.size(),
108107
nLockTime);
109-
for (unsigned int i = 0; i < vin.size(); i++)
110-
str += " " + vin[i].ToString() + "\n";
111-
for (unsigned int i = 0; i < vin.size(); i++)
112-
str += " " + vin[i].scriptWitness.ToString() + "\n";
113-
for (unsigned int i = 0; i < vout.size(); i++)
114-
str += " " + vout[i].ToString() + "\n";
108+
for (const auto& tx_in : vin)
109+
str += " " + tx_in.ToString() + "\n";
110+
for (const auto& tx_in : vin)
111+
str += " " + tx_in.scriptWitness.ToString() + "\n";
112+
for (const auto& tx_out : vout)
113+
str += " " + tx_out.ToString() + "\n";
115114
return str;
116115
}

0 commit comments

Comments
 (0)