PIVX Core  5.6.99
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 developers
3 // Copyright (c) 2016-2021 The PIVX Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef PIVX_UNDO_H
8 #define PIVX_UNDO_H
9 
10 #include "chain.h"
11 #include "compressor.h"
12 #include "consensus/consensus.h"
13 #include "primitives/transaction.h"
14 #include "serialize.h"
15 #include "version.h"
16 
25 {
26  template<typename Stream>
27  void Ser(Stream &s, const Coin& txout) {
28  ::Serialize(s, VARINT(txout.nHeight * 4 + (txout.fCoinBase ? 2u : 0u) + (txout.fCoinStake ? 1u : 0u)));
29  if (txout.nHeight > 0) {
30  // Required to maintain compatibility with older undo format.
31  ::Serialize(s, (unsigned char)0);
32  }
33  ::Serialize(s, Using<TxOutCompression>(txout.out));
34  }
35 
36  template<typename Stream>
37  void Unser(Stream &s, Coin& txout) {
38  unsigned int nCode = 0;
39  ::Unserialize(s, VARINT(nCode));
40  txout.nHeight = nCode >> 2;
41  txout.fCoinBase = nCode & 2;
42  txout.fCoinStake = nCode & 1;
43  if (txout.nHeight > 0) {
44  // Old versions stored the version number for the last spend of
45  // a transaction's outputs. Non-final spends were indicated with
46  // height = 0.
47  unsigned int nVersionDummy;
48  ::Unserialize(s, VARINT(nVersionDummy));
49  }
50  ::Unserialize(s, Using<TxOutCompression>(txout.out));
51  }
52 };
53 
55 class CTxUndo
56 {
57 public:
58  // undo information for all txins
59  std::vector<Coin> vprevout;
60 
62 };
63 
66 {
67 public:
68  std::vector<CTxUndo> vtxundo; // for all but the coinbase
69 
70  SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }
71 };
72 
73 #endif // PIVX_UNDO_H
Undo information for a CBlock.
Definition: undo.h:66
std::vector< CTxUndo > vtxundo
Definition: undo.h:68
SERIALIZE_METHODS(CBlockUndo, obj)
Definition: undo.h:70
Undo information for a CTransaction.
Definition: undo.h:56
std::vector< Coin > vprevout
Definition: undo.h:59
SERIALIZE_METHODS(CTxUndo, obj)
Definition: undo.h:61
A UTXO entry.
Definition: coins.h:32
bool fCoinStake
whether the containing transaction was a coinstake
Definition: coins.h:38
CTxOut out
unspent transaction output
Definition: coins.h:41
bool fCoinBase
whether the containing transaction was a coinbase
Definition: coins.h:35
uint32_t nHeight
at which height the containing transaction was included in the active block chain
Definition: coins.h:44
#define VARINT(obj)
Definition: serialize.h:513
void Serialize(Stream &s, char a)
Definition: serialize.h:237
void Unserialize(Stream &s, char &a)
Definition: serialize.h:253
#define READWRITE(...)
Definition: serialize.h:183
Formatter for undo information for a CTxIn.
Definition: undo.h:25
void Unser(Stream &s, Coin &txout)
Definition: undo.h:37
void Ser(Stream &s, const Coin &txout)
Definition: undo.h:27
Formatter to serialize/deserialize vector elements using another formatter.
Definition: serialize.h:763