Changeset View
Changeset View
Standalone View
Standalone View
src/undo.h
Show All 23 Lines | |||||
* or not, height). The serialization contains a dummy value of zero. This is be | * or not, height). The serialization contains a dummy value of zero. This is be | ||||
* compatible with older versions which expect to see the transaction version | * compatible with older versions which expect to see the transaction version | ||||
* there. | * there. | ||||
*/ | */ | ||||
class TxInUndoSerializer { | class TxInUndoSerializer { | ||||
const Coin *pcoin; | const Coin *pcoin; | ||||
public: | public: | ||||
TxInUndoSerializer(const Coin *pcoinIn) : pcoin(pcoinIn) {} | explicit TxInUndoSerializer(const Coin *pcoinIn) : pcoin(pcoinIn) {} | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
::Serialize( | ::Serialize( | ||||
s, VARINT(pcoin->GetHeight() * 2 + (pcoin->IsCoinBase() ? 1 : 0))); | s, VARINT(pcoin->GetHeight() * 2 + (pcoin->IsCoinBase() ? 1 : 0))); | ||||
if (pcoin->GetHeight() > 0) { | if (pcoin->GetHeight() > 0) { | ||||
// Required to maintain compatibility with older undo format. | // Required to maintain compatibility with older undo format. | ||||
::Serialize(s, uint8_t(0)); | ::Serialize(s, uint8_t(0)); | ||||
} | } | ||||
::Serialize(s, CTxOutCompressor(REF(pcoin->GetTxOut()))); | ::Serialize(s, CTxOutCompressor(REF(pcoin->GetTxOut()))); | ||||
} | } | ||||
}; | }; | ||||
class TxInUndoDeserializer { | class TxInUndoDeserializer { | ||||
Coin *pcoin; | Coin *pcoin; | ||||
public: | public: | ||||
TxInUndoDeserializer(Coin *pcoinIn) : pcoin(pcoinIn) {} | explicit TxInUndoDeserializer(Coin *pcoinIn) : pcoin(pcoinIn) {} | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
uint32_t nCode = 0; | uint32_t nCode = 0; | ||||
::Unserialize(s, VARINT(nCode)); | ::Unserialize(s, VARINT(nCode)); | ||||
uint32_t nHeight = nCode / 2; | uint32_t nHeight = nCode / 2; | ||||
bool fCoinBase = nCode & 1; | bool fCoinBase = nCode & 1; | ||||
if (nHeight > 0) { | if (nHeight > 0) { | ||||
// Old versions stored the version number for the last spend of a | // Old versions stored the version number for the last spend of a | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |