]> Git Repo - VerusCoin.git/blame_incremental - src/undo.h
Add `PushSaplingAnchor`
[VerusCoin.git] / src / undo.h
... / ...
CommitLineData
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2013 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.
5
6#ifndef BITCOIN_UNDO_H
7#define BITCOIN_UNDO_H
8
9#include "compressor.h"
10#include "primitives/transaction.h"
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 */
19class CTxInUndo
20{
21public:
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
30 template<typename Stream>
31 void Serialize(Stream &s) const {
32 ::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)));
33 if (nHeight > 0)
34 ::Serialize(s, VARINT(this->nVersion));
35 ::Serialize(s, CTxOutCompressor(REF(txout)));
36 }
37
38 template<typename Stream>
39 void Unserialize(Stream &s) {
40 unsigned int nCode = 0;
41 ::Unserialize(s, VARINT(nCode));
42 nHeight = nCode / 2;
43 fCoinBase = nCode & 1;
44 if (nHeight > 0)
45 ::Unserialize(s, VARINT(this->nVersion));
46 ::Unserialize(s, REF(CTxOutCompressor(REF(txout))));
47 }
48};
49
50/** Undo information for a CTransaction */
51class CTxUndo
52{
53public:
54 // undo information for all txins
55 std::vector<CTxInUndo> vprevout;
56
57 ADD_SERIALIZE_METHODS;
58
59 template <typename Stream, typename Operation>
60 inline void SerializationOp(Stream& s, Operation ser_action) {
61 READWRITE(vprevout);
62 }
63};
64
65/** Undo information for a CBlock */
66class CBlockUndo
67{
68public:
69 std::vector<CTxUndo> vtxundo; // for all but the coinbase
70 uint256 old_tree_root;
71
72 ADD_SERIALIZE_METHODS;
73
74 template <typename Stream, typename Operation>
75 inline void SerializationOp(Stream& s, Operation ser_action) {
76 READWRITE(vtxundo);
77 READWRITE(old_tree_root);
78 }
79};
80
81#endif // BITCOIN_UNDO_H
This page took 0.02045 seconds and 4 git commands to generate.