Changeset View
Changeset View
Standalone View
Standalone View
src/undo.h
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | template <typename Stream> void Unserialize(Stream &s) { | ||||
// Old versions stored the version number for the last spend of a | // Old versions stored the version number for the last spend of a | ||||
// transaction's outputs. Non-final spends were indicated with | // transaction's outputs. Non-final spends were indicated with | ||||
// height = 0. | // height = 0. | ||||
int nVersionDummy; | int nVersionDummy; | ||||
::Unserialize(s, VARINT(nVersionDummy)); | ::Unserialize(s, VARINT(nVersionDummy)); | ||||
} | } | ||||
CTxOut txout; | CTxOut txout; | ||||
::Unserialize(s, REF(CTxOutCompressor(REF(txout)))); | ::Unserialize(s, CTxOutCompressor(REF(txout))); | ||||
*pcoin = Coin(std::move(txout), nHeight, fCoinBase); | *pcoin = Coin(std::move(txout), nHeight, fCoinBase); | ||||
} | } | ||||
}; | }; | ||||
static const size_t MAX_INPUTS_PER_TX = | static const size_t MAX_INPUTS_PER_TX = | ||||
MAX_TX_SIZE / ::GetSerializeSize(CTxIn(), SER_NETWORK, PROTOCOL_VERSION); | MAX_TX_SIZE / ::GetSerializeSize(CTxIn(), SER_NETWORK, PROTOCOL_VERSION); | ||||
/** Restore the UTXO in a Coin at a given COutPoint */ | /** Restore the UTXO in a Coin at a given COutPoint */ | ||||
class CTxUndo { | class CTxUndo { | ||||
public: | public: | ||||
// Undo information for all txins | // Undo information for all txins | ||||
std::vector<Coin> vprevout; | std::vector<Coin> vprevout; | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
// TODO: avoid reimplementing vector serializer. | // TODO: avoid reimplementing vector serializer. | ||||
uint64_t count = vprevout.size(); | uint64_t count = vprevout.size(); | ||||
::Serialize(s, COMPACTSIZE(REF(count))); | ::Serialize(s, COMPACTSIZE(REF(count))); | ||||
for (const auto &prevout : vprevout) { | for (const auto &prevout : vprevout) { | ||||
::Serialize(s, REF(TxInUndoSerializer(&prevout))); | ::Serialize(s, TxInUndoSerializer(&prevout)); | ||||
} | } | ||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
// TODO: avoid reimplementing vector deserializer. | // TODO: avoid reimplementing vector deserializer. | ||||
uint64_t count = 0; | uint64_t count = 0; | ||||
::Unserialize(s, COMPACTSIZE(count)); | ::Unserialize(s, COMPACTSIZE(count)); | ||||
if (count > MAX_INPUTS_PER_TX) { | if (count > MAX_INPUTS_PER_TX) { | ||||
throw std::ios_base::failure("Too many input undo records"); | throw std::ios_base::failure("Too many input undo records"); | ||||
} | } | ||||
vprevout.resize(count); | vprevout.resize(count); | ||||
for (auto &prevout : vprevout) { | for (auto &prevout : vprevout) { | ||||
::Unserialize(s, REF(TxInUndoDeserializer(&prevout))); | ::Unserialize(s, TxInUndoDeserializer(&prevout)); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
/** Undo information for a CBlock */ | /** Undo information for a CBlock */ | ||||
class CBlockUndo { | class CBlockUndo { | ||||
public: | public: | ||||
// For all but the coinbase | // For all but the coinbase | ||||
Show All 38 Lines |