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.
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
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)));
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
));
45 fCoinBase
= nCode
& 1;
48 ::Unserialize(s
, VARINT(nVersionDummy
));
50 ::Unserialize(s
, REF(CTxOutCompressor(REF(txout
))));
54 /** Undo information for a CTransaction */
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
) {
69 /** Undo information for a CBlock */
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
) {
83 #endif // BITCOIN_UNDO_H