Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

undo.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 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 <consensus/consensus.h>
11 #include <primitives/transaction.h>
12 #include <serialize.h>
13 
22 {
23  const Coin* txout;
24 
25 public:
26  template<typename Stream>
27  void Serialize(Stream &s) const {
28  ::Serialize(s, VARINT(txout->nHeight * 2 + (txout->fCoinBase ? 1 : 0)));
29  if (txout->nHeight > 0) {
30  // Required to maintain compatibility with older undo format.
31  ::Serialize(s, (unsigned char)0);
32  }
34  }
35 
36  explicit TxInUndoSerializer(const Coin* coin) : txout(coin) {}
37 };
38 
40 {
42 
43 public:
44  template<typename Stream>
45  void Unserialize(Stream &s) {
46  unsigned int nCode = 0;
47  ::Unserialize(s, VARINT(nCode));
48  txout->nHeight = nCode / 2;
49  txout->fCoinBase = nCode & 1;
50  if (txout->nHeight > 0) {
51  // Old versions stored the version number for the last spend of
52  // a transaction's outputs. Non-final spends were indicated with
53  // height = 0.
54  int nVersionDummy;
55  ::Unserialize(s, VARINT(nVersionDummy));
56  }
58  }
59 
60  explicit TxInUndoDeserializer(Coin* coin) : txout(coin) {}
61 };
62 
64 
66 class CTxUndo
67 {
68 public:
69  // undo information for all txins
70  std::vector<Coin> vprevout;
71 
72  template <typename Stream>
73  void Serialize(Stream& s) const {
74  // TODO: avoid reimplementing vector serializer
75  uint64_t count = vprevout.size();
77  for (const auto& prevout : vprevout) {
78  ::Serialize(s, REF(TxInUndoSerializer(&prevout)));
79  }
80  }
81 
82  template <typename Stream>
83  void Unserialize(Stream& s) {
84  // TODO: avoid reimplementing vector deserializer
85  uint64_t count = 0;
88  throw std::ios_base::failure("Too many input undo records");
89  }
90  vprevout.resize(count);
91  for (auto& prevout : vprevout) {
92  ::Unserialize(s, REF(TxInUndoDeserializer(&prevout)));
93  }
94  }
95 };
96 
99 {
100 public:
101  std::vector<CTxUndo> vtxundo; // for all but the coinbase
102 
104 
105  template <typename Stream, typename Operation>
106  inline void SerializationOp(Stream& s, Operation ser_action) {
108  }
109 };
110 
111 #endif // BITCOIN_UNDO_H
#define VARINT(obj)
Definition: serialize.h:375
std::vector< Coin > vprevout
Definition: undo.h:70
const Coin * txout
Definition: undo.h:23
#define READWRITE(obj)
Definition: serialize.h:165
A UTXO entry.
Definition: coins.h:29
unsigned int MaxBlockSize(bool fDIP0001Active)
Definition: consensus.h:12
wrapper for CTxOut that provides a more compact serialization
Definition: compressor.h:93
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
Definition: serialize.h:1295
#define COMPACTSIZE(obj)
Definition: serialize.h:376
CTxOut out
unspent transaction output
Definition: coins.h:33
unsigned int fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:36
void Unserialize(Stream &s)
Definition: undo.h:83
void Unserialize(Stream &s)
Definition: undo.h:45
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Definition: coins.h:39
Undo information for a CTxIn.
Definition: undo.h:21
An input of a transaction.
Definition: transaction.h:70
void SerializationOp(Stream &s, Operation ser_action)
Definition: undo.h:106
TxInUndoSerializer(const Coin *coin)
Definition: undo.h:36
static const size_t MAX_INPUTS_PER_BLOCK
Definition: undo.h:63
void Serialize(Stream &s) const
Definition: undo.h:27
Coin * txout
Definition: undo.h:41
Undo information for a CBlock.
Definition: undo.h:98
TxInUndoDeserializer(Coin *coin)
Definition: undo.h:60
Undo information for a CTransaction.
Definition: undo.h:66
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
void Serialize(Stream &s) const
Definition: undo.h:73
ADD_SERIALIZE_METHODS
Definition: undo.h:103
static int count
Definition: tests.c:45
std::vector< CTxUndo > vtxundo
Definition: undo.h:101
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:50
Released under the MIT license