Skip to content

Commit 61cde55

Browse files
committed
coins,refactor: Unify Coin Serialization styles
1 parent d0603fa commit 61cde55

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/coins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* A UTXO entry.
2727
*
2828
* Serialized format:
29-
* - VARINT((coinbase ? 1 : 0) | (height << 1))
29+
* - VARINT((height << 1) | (coinbase ? 1 : 0))
3030
* - the non-spent CTxOut (via TxOutCompression)
3131
*/
3232
class Coin
@@ -61,7 +61,7 @@ class Coin
6161
template<typename Stream>
6262
void Serialize(Stream &s) const {
6363
assert(!IsSpent());
64-
uint32_t code = nHeight * uint32_t{2} + fCoinBase;
64+
uint32_t code{static_cast<uint32_t>(nHeight << 1) | fCoinBase};
6565
::Serialize(s, VARINT(code));
6666
::Serialize(s, Using<TxOutCompression>(out));
6767
}

src/kernel/coinstats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ template <typename T>
5151
static void TxOutSer(T& ss, const COutPoint& outpoint, const Coin& coin)
5252
{
5353
ss << outpoint;
54-
ss << static_cast<uint32_t>((coin.nHeight << 1) + coin.fCoinBase);
54+
ss << (static_cast<uint32_t>(coin.nHeight << 1) | coin.fCoinBase);
5555
ss << coin.out;
5656
}
5757

src/undo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ struct TxInUndoFormatter
2323
{
2424
template<typename Stream>
2525
void Ser(Stream &s, const Coin& txout) {
26-
::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase ));
26+
uint32_t nCode{static_cast<uint32_t>(txout.nHeight << 1) | txout.fCoinBase};
27+
::Serialize(s, VARINT(nCode));
2728
if (txout.nHeight > 0) {
2829
// Required to maintain compatibility with older undo format.
2930
::Serialize(s, (unsigned char)0);

0 commit comments

Comments
 (0)