Remove/ignore tx version in utxo and undo
[bitcoinplatinum.git] / src / undo.h
blobd21b82e2ec34e5394afc22f324eef6e685b0cdad
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_UNDO_H
7 #define BITCOIN_UNDO_H
9 #include "compressor.h"
10 #include "primitives/transaction.h"
11 #include "serialize.h"
13 /** Undo information for a CTxIn
15 * Contains the prevout's CTxOut being spent, and if this was the
16 * last output of the affected transaction, its metadata as well
17 * (coinbase or not, height). Earlier versions also stored the transaction
18 * version.
20 class CTxInUndo
22 public:
23 CTxOut txout; // the txout data before being spent
24 bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
25 unsigned int nHeight; // if the outpoint was the last unspent: its height
27 CTxInUndo() : txout(), fCoinBase(false), nHeight(0) {}
28 CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn = false, unsigned int nHeightIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn) { }
30 template<typename Stream>
31 void Serialize(Stream &s) const {
32 ::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)));
33 if (nHeight > 0) {
34 int nVersionDummy = 0;
35 ::Serialize(s, VARINT(nVersionDummy));
37 ::Serialize(s, CTxOutCompressor(REF(txout)));
40 template<typename Stream>
41 void Unserialize(Stream &s) {
42 unsigned int nCode = 0;
43 ::Unserialize(s, VARINT(nCode));
44 nHeight = nCode / 2;
45 fCoinBase = nCode & 1;
46 if (nHeight > 0) {
47 int nVersionDummy;
48 ::Unserialize(s, VARINT(nVersionDummy));
50 ::Unserialize(s, REF(CTxOutCompressor(REF(txout))));
54 /** Undo information for a CTransaction */
55 class CTxUndo
57 public:
58 // undo information for all txins
59 std::vector<CTxInUndo> vprevout;
61 ADD_SERIALIZE_METHODS;
63 template <typename Stream, typename Operation>
64 inline void SerializationOp(Stream& s, Operation ser_action) {
65 READWRITE(vprevout);
69 /** Undo information for a CBlock */
70 class CBlockUndo
72 public:
73 std::vector<CTxUndo> vtxundo; // for all but the coinbase
75 ADD_SERIALIZE_METHODS;
77 template <typename Stream, typename Operation>
78 inline void SerializationOp(Stream& s, Operation ser_action) {
79 READWRITE(vtxundo);
83 #endif // BITCOIN_UNDO_H