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, transaction version)
22 CTxOut txout
; // the txout data before being spent
23 bool fCoinBase
; // if the outpoint was the last unspent: whether it belonged to a coinbase
24 unsigned int nHeight
; // if the outpoint was the last unspent: its height
25 int nVersion
; // if the outpoint was the last unspent: its version
27 CTxInUndo() : txout(), fCoinBase(false), nHeight(0), nVersion(0) {}
28 CTxInUndo(const CTxOut
&txoutIn
, bool fCoinBaseIn
= false, unsigned int nHeightIn
= 0, int nVersionIn
= 0) : txout(txoutIn
), fCoinBase(fCoinBaseIn
), nHeight(nHeightIn
), nVersion(nVersionIn
) { }
30 template<typename Stream
>
31 void Serialize(Stream
&s
) const {
32 ::Serialize(s
, VARINT(nHeight
*2+(fCoinBase
? 1 : 0)));
34 ::Serialize(s
, VARINT(this->nVersion
));
35 ::Serialize(s
, CTxOutCompressor(REF(txout
)));
38 template<typename Stream
>
39 void Unserialize(Stream
&s
) {
40 unsigned int nCode
= 0;
41 ::Unserialize(s
, VARINT(nCode
));
43 fCoinBase
= nCode
& 1;
45 ::Unserialize(s
, VARINT(this->nVersion
));
46 ::Unserialize(s
, REF(CTxOutCompressor(REF(txout
))));
50 /** Undo information for a CTransaction */
54 // undo information for all txins
55 std::vector
<CTxInUndo
> vprevout
;
57 ADD_SERIALIZE_METHODS
;
59 template <typename Stream
, typename Operation
>
60 inline void SerializationOp(Stream
& s
, Operation ser_action
) {
65 /** Undo information for a CBlock */
69 std::vector
<CTxUndo
> vtxundo
; // for all but the coinbase
71 ADD_SERIALIZE_METHODS
;
73 template <typename Stream
, typename Operation
>
74 inline void SerializationOp(Stream
& s
, Operation ser_action
) {
79 #endif // BITCOIN_UNDO_H