mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 14:37:42 -03:00
coins,refactor: Unify Coin Serialization styles
This commit is contained in:
parent
5658c51871
commit
ff9d484876
3 changed files with 5 additions and 4 deletions
|
@ -26,7 +26,7 @@
|
||||||
* A UTXO entry.
|
* A UTXO entry.
|
||||||
*
|
*
|
||||||
* Serialized format:
|
* Serialized format:
|
||||||
* - VARINT((coinbase ? 1 : 0) | (height << 1))
|
* - VARINT((height << 1) | (coinbase ? 1 : 0))
|
||||||
* - the non-spent CTxOut (via TxOutCompression)
|
* - the non-spent CTxOut (via TxOutCompression)
|
||||||
*/
|
*/
|
||||||
class Coin
|
class Coin
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Serialize(Stream &s) const {
|
void Serialize(Stream &s) const {
|
||||||
assert(!IsSpent());
|
assert(!IsSpent());
|
||||||
uint32_t code = nHeight * uint32_t{2} + fCoinBase;
|
uint32_t code{static_cast<uint32_t>(nHeight << 1) | fCoinBase};
|
||||||
::Serialize(s, VARINT(code));
|
::Serialize(s, VARINT(code));
|
||||||
::Serialize(s, Using<TxOutCompression>(out));
|
::Serialize(s, Using<TxOutCompression>(out));
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ template <typename T>
|
||||||
static void TxOutSer(T& ss, const COutPoint& outpoint, const Coin& coin)
|
static void TxOutSer(T& ss, const COutPoint& outpoint, const Coin& coin)
|
||||||
{
|
{
|
||||||
ss << outpoint;
|
ss << outpoint;
|
||||||
ss << static_cast<uint32_t>((coin.nHeight << 1) + coin.fCoinBase);
|
ss << (static_cast<uint32_t>(coin.nHeight << 1) | coin.fCoinBase);
|
||||||
ss << coin.out;
|
ss << coin.out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ struct TxInUndoFormatter
|
||||||
{
|
{
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Ser(Stream &s, const Coin& txout) {
|
void Ser(Stream &s, const Coin& txout) {
|
||||||
::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase ));
|
uint32_t nCode{static_cast<uint32_t>(txout.nHeight << 1) | txout.fCoinBase};
|
||||||
|
::Serialize(s, VARINT(nCode));
|
||||||
if (txout.nHeight > 0) {
|
if (txout.nHeight > 0) {
|
||||||
// Required to maintain compatibility with older undo format.
|
// Required to maintain compatibility with older undo format.
|
||||||
::Serialize(s, (unsigned char)0);
|
::Serialize(s, (unsigned char)0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue