Dash Core  0.12.2.1
P2P Digital Currency
undo.h
Go to the documentation of this file.
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 
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  unsigned int GetSerializeSize(int nType, int nVersion) const {
32  (nHeight > 0 ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
34  }
35 
36  template<typename Stream>
37  void Serialize(Stream &s, int nType, int nVersion) const {
38  ::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion);
39  if (nHeight > 0)
40  ::Serialize(s, VARINT(this->nVersion), nType, nVersion);
42  }
43 
44  template<typename Stream>
45  void Unserialize(Stream &s, int nType, int nVersion) {
46  unsigned int nCode = 0;
47  ::Unserialize(s, VARINT(nCode), nType, nVersion);
48  nHeight = nCode / 2;
49  fCoinBase = nCode & 1;
50  if (nHeight > 0)
51  ::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
53  }
54 };
55 
57 class CTxUndo
58 {
59 public:
60  // undo information for all txins
61  std::vector<CTxInUndo> vprevout;
62 
64 
65  template <typename Stream, typename Operation>
66  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
68  }
69 };
70 
73 {
74 public:
75  std::vector<CTxUndo> vtxundo; // for all but the coinbase
76 
78 
79  template <typename Stream, typename Operation>
80  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
82  }
83 };
84 
85 #endif // BITCOIN_UNDO_H
CTxInUndo()
Definition: undo.h:27
#define VARINT(obj)
Definition: serialize.h:388
Definition: undo.h:19
void Serialize(Stream &s, int nType, int nVersion) const
Definition: undo.h:37
#define READWRITE(obj)
Definition: serialize.h:175
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: undo.h:80
std::vector< CTxInUndo > vprevout
Definition: undo.h:61
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: undo.h:66
CTxOut txout
Definition: undo.h:22
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:202
std::vector< CTxUndo > vtxundo
Definition: undo.h:75
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn=false, unsigned int nHeightIn=0, int nVersionIn=0)
Definition: undo.h:28
bool fCoinBase
Definition: undo.h:23
ADD_SERIALIZE_METHODS
Definition: undo.h:77
ADD_SERIALIZE_METHODS
Definition: undo.h:63
void Unserialize(Stream &s, int nType, int nVersion)
Definition: undo.h:45
unsigned int nHeight
Definition: undo.h:24
Definition: undo.h:57
unsigned int GetSerializeSize(int nType, int nVersion) const
Definition: undo.h:30
T & REF(const T &val)
Definition: serialize.h:33
int nVersion
Definition: undo.h:25