Bitcoin Core  0.19.99
P2P Digital Currency
undo.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 <coins.h>
10 #include <compressor.h>
11 #include <consensus/consensus.h>
12 #include <primitives/transaction.h>
13 #include <serialize.h>
14 #include <version.h>
15 
24 {
25  template<typename Stream>
26  void Ser(Stream &s, const Coin& txout) {
27  ::Serialize(s, VARINT(txout.nHeight * 2 + (txout.fCoinBase ? 1u : 0u)));
28  if (txout.nHeight > 0) {
29  // Required to maintain compatibility with older undo format.
30  ::Serialize(s, (unsigned char)0);
31  }
32  ::Serialize(s, Using<TxOutCompression>(txout.out));
33  }
34 
35  template<typename Stream>
36  void Unser(Stream &s, Coin& txout) {
37  unsigned int nCode = 0;
38  ::Unserialize(s, VARINT(nCode));
39  txout.nHeight = nCode / 2;
40  txout.fCoinBase = nCode & 1;
41  if (txout.nHeight > 0) {
42  // Old versions stored the version number for the last spend of
43  // a transaction's outputs. Non-final spends were indicated with
44  // height = 0.
45  unsigned int nVersionDummy;
46  ::Unserialize(s, VARINT(nVersionDummy));
47  }
48  ::Unserialize(s, Using<TxOutCompression>(txout.out));
49  }
50 };
51 
53 class CTxUndo
54 {
55 public:
56  // undo information for all txins
57  std::vector<Coin> vprevout;
58 
60 };
61 
64 {
65 public:
66  std::vector<CTxUndo> vtxundo; // for all but the coinbase
67 
68  SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }
69 };
70 
71 #endif // BITCOIN_UNDO_H
#define VARINT(obj)
Definition: serialize.h:497
std::vector< Coin > vprevout
Definition: undo.h:57
A UTXO entry.
Definition: coins.h:30
CTxOut out
unspent transaction output
Definition: coins.h:34
unsigned int fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:37
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class...
Definition: serialize.h:494
void Serialize(Stream &s, char a)
Definition: serialize.h:252
void Ser(Stream &s, const Coin &txout)
Definition: undo.h:26
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Definition: coins.h:40
void Unser(Stream &s, Coin &txout)
Definition: undo.h:36
SERIALIZE_METHODS(CTxUndo, obj)
Definition: undo.h:59
Undo information for a CBlock.
Definition: undo.h:63
Undo information for a CTransaction.
Definition: undo.h:53
void Unserialize(Stream &s, char &a)
Definition: serialize.h:270
Formatter for undo information for a CTxIn.
Definition: undo.h:23
SERIALIZE_METHODS(CBlockUndo, obj)
Definition: undo.h:68
Formatter to serialize/deserialize vector elements using another formatter.
Definition: serialize.h:614
#define READWRITE(...)
Definition: serialize.h:186
std::vector< CTxUndo > vtxundo
Definition: undo.h:66