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 | |||||
* - CompactSize((coinbase ? 1 : 0) | (height << 1)) | |||||
deadalnix: Just put 32 bits for flags and 32 bits for height. It's not like we are storing this anywhere… | |||||
* - 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 { | |||||
deadalnixUnsubmitted Not Done Inline ActionsThere should be a new type of serialization here for commitments. Not to disc work in that case because theonly place we serialize this is to store on disk, but that doesn't seems to me to be ideal down the road. deadalnix: There should be a new type of serialization here for commitments. Not to disc work in that case… | |||||
// UTXO commitment format | |||||
::WriteCompactSize(s, nHeightAndIsCoinBase); | |||||
::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 |
Just put 32 bits for flags and 32 bits for height. It's not like we are storing this anywhere, so it's all good. et's not try to be smart.