]>
Commit | Line | Data |
---|---|---|
999a2ab4 | 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
f914f1a7 | 2 | // Copyright (c) 2009-2013 The Bitcoin Core developers |
999a2ab4 | 3 | // Distributed under the MIT software license, see the accompanying |
bc909a7a | 4 | // file COPYING or https://www.opensource.org/licenses/mit-license.php . |
999a2ab4 | 5 | |
84738627 PJ |
6 | #ifndef BITCOIN_UNDO_H |
7 | #define BITCOIN_UNDO_H | |
999a2ab4 | 8 | |
561e9e9d | 9 | #include "compressor.h" |
d2270111 | 10 | #include "primitives/transaction.h" |
999a2ab4 | 11 | #include "serialize.h" |
12 | ||
13 | /** Undo information for a CTxIn | |
14 | * | |
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) | |
18 | */ | |
19 | class CTxInUndo | |
20 | { | |
21 | public: | |
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 | |
26 | ||
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) { } | |
29 | ||
999a2ab4 | 30 | template<typename Stream> |
242f1421 PW |
31 | void Serialize(Stream &s) const { |
32 | ::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0))); | |
999a2ab4 | 33 | if (nHeight > 0) |
242f1421 PW |
34 | ::Serialize(s, VARINT(this->nVersion)); |
35 | ::Serialize(s, CTxOutCompressor(REF(txout))); | |
999a2ab4 | 36 | } |
37 | ||
38 | template<typename Stream> | |
242f1421 | 39 | void Unserialize(Stream &s) { |
999a2ab4 | 40 | unsigned int nCode = 0; |
242f1421 | 41 | ::Unserialize(s, VARINT(nCode)); |
999a2ab4 | 42 | nHeight = nCode / 2; |
43 | fCoinBase = nCode & 1; | |
44 | if (nHeight > 0) | |
242f1421 PW |
45 | ::Unserialize(s, VARINT(this->nVersion)); |
46 | ::Unserialize(s, REF(CTxOutCompressor(REF(txout)))); | |
999a2ab4 | 47 | } |
48 | }; | |
49 | ||
50 | /** Undo information for a CTransaction */ | |
51 | class CTxUndo | |
52 | { | |
53 | public: | |
54 | // undo information for all txins | |
55 | std::vector<CTxInUndo> vprevout; | |
56 | ||
57 | ADD_SERIALIZE_METHODS; | |
58 | ||
59 | template <typename Stream, typename Operation> | |
242f1421 | 60 | inline void SerializationOp(Stream& s, Operation ser_action) { |
999a2ab4 | 61 | READWRITE(vprevout); |
62 | } | |
63 | }; | |
64 | ||
937ba572 | 65 | /** Undo information for a CBlock */ |
66 | class CBlockUndo | |
67 | { | |
68 | public: | |
69 | std::vector<CTxUndo> vtxundo; // for all but the coinbase | |
1f8be05b | 70 | uint256 old_sprout_tree_root; |
937ba572 | 71 | |
72 | ADD_SERIALIZE_METHODS; | |
73 | ||
74 | template <typename Stream, typename Operation> | |
242f1421 | 75 | inline void SerializationOp(Stream& s, Operation ser_action) { |
937ba572 | 76 | READWRITE(vtxundo); |
1f8be05b | 77 | READWRITE(old_sprout_tree_root); |
937ba572 | 78 | } |
79 | }; | |
80 | ||
84738627 | 81 | #endif // BITCOIN_UNDO_H |