diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index 6459d0e957..6766246109 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -29,9 +29,8 @@ std::string CBlock::ToString() const hashMerkleRoot.ToString(), nTime, nBits, nNonce, vtx.size()); - for (unsigned int i = 0; i < vtx.size(); i++) - { - s << " " << vtx[i]->ToString() << "\n"; + for (const auto& tx : vtx) { + s << " " << tx->ToString() << "\n"; } return s.str(); } diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index a6bec1411e..772408f43e 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -99,10 +99,9 @@ CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), nT CAmount CTransaction::GetValueOut() const { CAmount nValueOut = 0; - for (std::vector::const_iterator it(vout.begin()); it != vout.end(); ++it) - { - nValueOut += it->nValue; - if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut)) + for (const auto& tx_out : vout) { + nValueOut += tx_out.nValue; + if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) throw std::runtime_error(std::string(__func__) + ": value out of range"); } return nValueOut; @@ -124,9 +123,9 @@ std::string CTransaction::ToString() const vout.size(), nLockTime, vExtraPayload.size()); - for (unsigned int i = 0; i < vin.size(); i++) - str += " " + vin[i].ToString() + "\n"; - for (unsigned int i = 0; i < vout.size(); i++) - str += " " + vout[i].ToString() + "\n"; + for (const auto& tx_in : vin) + str += " " + tx_in.ToString() + "\n"; + for (const auto& tx_out : vout) + str += " " + tx_out.ToString() + "\n"; return str; }