Changeset View
Changeset View
Standalone View
Standalone View
src/coins.h
Show All 14 Lines | |||||
#include <cassert> | #include <cassert> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <unordered_map> | #include <unordered_map> | ||||
/** | /** | ||||
* A UTXO entry. | * A UTXO entry. | ||||
* | * | ||||
* Serialized format: | * Serialized format for storage: | ||||
* - VARINT((coinbase ? 1 : 0) | (height << 1)) | * - VARINT((coinbase ? 1 : 0) | (height << 1)) | ||||
* - the non-spent CTxOut (via CTxOutCompressor) | * - the non-spent CTxOut (via CTxOutCompressor) | ||||
* | |||||
* Serialized format for network is used for UTXO commitment | |||||
* - uint32_t(height) | |||||
* - uint8_t(iscoinbase) | |||||
* - the non-spent CTxOut (uncompressed) | |||||
*/ | */ | ||||
class Coin { | class Coin { | ||||
//! Unspent transaction output. | //! Unspent transaction output. | ||||
CTxOut out; | CTxOut out; | ||||
//! Whether containing transaction was a coinbase and height at which the | //! Whether containing transaction was a coinbase and height at which the | ||||
//! transaction was included into a block. | //! transaction was included into a block. | ||||
uint32_t nHeightAndIsCoinBase; | uint32_t nHeightAndIsCoinBase; | ||||
Show All 15 Lines | public: | ||||
const CTxOut &GetTxOut() const { return out; } | const CTxOut &GetTxOut() const { return out; } | ||||
void Clear() { | void Clear() { | ||||
out.SetNull(); | out.SetNull(); | ||||
nHeightAndIsCoinBase = 0; | nHeightAndIsCoinBase = 0; | ||||
} | } | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
if (s.GetType() & SER_DISK) { | |||||
assert(!IsSpent()); | assert(!IsSpent()); | ||||
::Serialize(s, VARINT(nHeightAndIsCoinBase)); | ::Serialize(s, VARINT(nHeightAndIsCoinBase)); | ||||
// only compress for disk format | |||||
::Serialize(s, CTxOutCompressor(REF(out))); | ::Serialize(s, CTxOutCompressor(REF(out))); | ||||
} else { | |||||
// UTXO commitment format | |||||
::Serialize(s, GetHeight()); | |||||
::Serialize(s, static_cast<uint8_t>(IsCoinBase())); | |||||
::Serialize(s, REF(out)); | |||||
} | |||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
::Unserialize(s, VARINT(nHeightAndIsCoinBase)); | ::Unserialize(s, VARINT(nHeightAndIsCoinBase)); | ||||
::Unserialize(s, REF(CTxOutCompressor(out))); | ::Unserialize(s, REF(CTxOutCompressor(out))); | ||||
} | } | ||||
size_t DynamicMemoryUsage() const { | size_t DynamicMemoryUsage() const { | ||||
▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines |