@@ -24,31 +24,35 @@ static uint64_t GetBogoSize(const CScript& scriptPubKey)
24
24
scriptPubKey.size () /* scriptPubKey */ ;
25
25
}
26
26
27
- static void ApplyStats (CCoinsStats& stats, CHashWriter& ss, const uint256& hash, const std::map<uint32_t , Coin>& outputs)
27
+ static void ApplyHash (CCoinsStats& stats, CHashWriter& ss, const uint256& hash, const std::map<uint32_t , Coin>& outputs, std::map< uint32_t , Coin>::const_iterator it )
28
28
{
29
- assert (! outputs.empty ());
30
- ss << hash;
31
- ss << VARINT (outputs. begin () ->second .nHeight * 2 + outputs. begin () ->second .fCoinBase ? 1u : 0u );
32
- stats. nTransactions ++;
33
- for ( const auto & output : outputs) {
34
- ss << VARINT (output. first + 1 );
35
- ss << output. second .out .scriptPubKey ;
36
- ss << VARINT_MODE (output. second .out .nValue , VarIntMode::NONNEGATIVE_SIGNED);
37
- stats. nTransactionOutputs ++;
38
- stats. nTotalAmount += output. second . out . nValue ;
39
- stats. nBogoSize += GetBogoSize (output. second . out . scriptPubKey );
29
+ if (it == outputs.begin ()) {
30
+ ss << hash;
31
+ ss << VARINT (it ->second .nHeight * 2 + it ->second .fCoinBase ? 1u : 0u );
32
+ }
33
+
34
+ ss << VARINT (it-> first + 1 );
35
+ ss << it-> second .out .scriptPubKey ;
36
+ ss << VARINT_MODE (it-> second .out .nValue , VarIntMode::NONNEGATIVE_SIGNED);
37
+
38
+ if (it == std::prev (outputs. end ())) {
39
+ ss << VARINT ( 0u );
40
40
}
41
- ss << VARINT (0u );
42
41
}
43
42
44
- static void ApplyStats (CCoinsStats& stats, std::nullptr_t , const uint256& hash, const std::map<uint32_t , Coin>& outputs)
43
+ static void ApplyHash (CCoinsStats& stats, std::nullptr_t , const uint256& hash, const std::map<uint32_t , Coin>& outputs, std::map<uint32_t , Coin>::const_iterator it) {}
44
+
45
+ template <typename T>
46
+ static void ApplyStats (CCoinsStats &stats, T& hash_obj, const uint256& hash, const std::map<uint32_t , Coin>& outputs)
45
47
{
46
48
assert (!outputs.empty ());
47
49
stats.nTransactions ++;
48
- for (const auto & output : outputs) {
50
+ for (auto it = outputs.begin (); it != outputs.end (); ++it) {
51
+ ApplyHash (stats, hash_obj, hash, outputs, it);
52
+
49
53
stats.nTransactionOutputs ++;
50
- stats.nTotalAmount += output. second .out .nValue ;
51
- stats.nBogoSize += GetBogoSize (output. second .out .scriptPubKey );
54
+ stats.nTotalAmount += it-> second .out .nValue ;
55
+ stats.nBogoSize += GetBogoSize (it-> second .out .scriptPubKey );
52
56
}
53
57
}
54
58
0 commit comments