Dogecoin Core  1.14.2
P2P Digital Currency
undo.h
Go to the documentation of this file.
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.
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 
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 
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));
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));
47  }
48 };
49 
51 class CTxUndo
52 {
53 public:
54  // undo information for all txins
55  std::vector<CTxInUndo> vprevout;
56 
58 
59  template <typename Stream, typename Operation>
60  inline void SerializationOp(Stream& s, Operation ser_action) {
62  }
63 };
64 
67 {
68 public:
69  std::vector<CTxUndo> vtxundo; // for all but the coinbase
70 
72 
73  template <typename Stream, typename Operation>
74  inline void SerializationOp(Stream& s, Operation ser_action) {
76  }
77 };
78 
79 #endif // BITCOIN_UNDO_H
Undo information for a CBlock.
Definition: undo.h:67
void SerializationOp(Stream &s, Operation ser_action)
Definition: undo.h:74
ADD_SERIALIZE_METHODS
Definition: undo.h:71
std::vector< CTxUndo > vtxundo
Definition: undo.h:69
Undo information for a CTxIn.
Definition: undo.h:20
void Serialize(Stream &s) const
Definition: undo.h:31
CTxOut txout
Definition: undo.h:22
int nVersion
Definition: undo.h:25
bool fCoinBase
Definition: undo.h:23
void Unserialize(Stream &s)
Definition: undo.h:39
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn=false, unsigned int nHeightIn=0, int nVersionIn=0)
Definition: undo.h:28
CTxInUndo()
Definition: undo.h:27
unsigned int nHeight
Definition: undo.h:24
wrapper for CTxOut that provides a more compact serialization
Definition: compressor.h:94
An output of a transaction.
Definition: transaction.h:133
Undo information for a CTransaction.
Definition: undo.h:52
std::vector< CTxInUndo > vprevout
Definition: undo.h:55
ADD_SERIALIZE_METHODS
Definition: undo.h:57
void SerializationOp(Stream &s, Operation ser_action)
Definition: undo.h:60
#define VARINT(obj)
Definition: serialize.h:348
#define READWRITE(obj)
Definition: serialize.h:151
T & REF(const T &val)
Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers s...
Definition: serialize.h:47