Bitcoin ABC  0.24.7
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 // Copyright (c) 2017-2019 The Bitcoin 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 BITCOIN_UNDO_H
8 #define BITCOIN_UNDO_H
9 
10 #include <coins.h>
11 #include <compressor.h>
12 #include <consensus/consensus.h>
13 #include <disconnectresult.h>
14 #include <serialize.h>
15 #include <version.h>
16 
17 class CBlock;
18 class CBlockIndex;
19 class CCoinsViewCache;
21 
31  template <typename Stream> void Ser(Stream &s, const Coin &txout) {
33  s, VARINT(txout.GetHeight() * 2 + (txout.IsCoinBase() ? 1 : 0)));
34  if (txout.GetHeight() > 0) {
35  // Required to maintain compatibility with older undo format.
36  ::Serialize(s, uint8_t(0));
37  }
38  ::Serialize(s, Using<TxOutCompression>(txout.GetTxOut()));
39  }
40 
41  template <typename Stream> void Unser(Stream &s, Coin &txout) {
42  uint32_t nCode = 0;
43  ::Unserialize(s, VARINT(nCode));
44  uint32_t nHeight = nCode / 2;
45  bool fCoinBase = nCode & 1;
46  if (nHeight > 0) {
47  // Old versions stored the version number for the last spend of a
48  // transaction's outputs. Non-final spends were indicated with
49  // height = 0.
50  unsigned int nVersionDummy = 0;
51  ::Unserialize(s, VARINT(nVersionDummy));
52  }
53 
54  CTxOut out;
55  ::Unserialize(s, Using<TxOutCompression>(out));
56 
57  txout = Coin(std::move(out), nHeight, fCoinBase);
58  }
59 };
60 
62 class CTxUndo {
63 public:
64  // Undo information for all txins
65  std::vector<Coin> vprevout;
66 
69  }
70 };
71 
73 class CBlockUndo {
74 public:
75  // For all but the coinbase
76  std::vector<CTxUndo> vtxundo;
77 
78  SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }
79 };
80 
89  const COutPoint &out);
90 
96  const CBlock &block, const CBlockIndex *pindex,
97  CCoinsViewCache &coins);
98 
99 #endif // BITCOIN_UNDO_H
UndoCoinSpend
DisconnectResult UndoCoinSpend(const Coin &undo, CCoinsViewCache &view, const COutPoint &out)
Restore the UTXO in a Coin at a given COutPoint.
Definition: validation.cpp:1321
CTxUndo::SERIALIZE_METHODS
SERIALIZE_METHODS(CTxUndo, obj)
Definition: undo.h:67
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:13
BlockValidationState
Definition: validation.h:138
CTxUndo
Restore the UTXO in a Coin at a given COutPoint.
Definition: undo.h:62
TxInUndoFormatter::Ser
void Ser(Stream &s, const Coin &txout)
Definition: undo.h:31
VectorFormatter
Formatter to serialize/deserialize vector elements using another formatter.
Definition: serialize.h:718
ApplyBlockUndo
DisconnectResult ApplyBlockUndo(const CBlockUndo &blockUndo, const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &coins)
Undo a block from the block and the undoblock data.
Definition: validation.cpp:1374
DisconnectResult
DisconnectResult
Definition: disconnectresult.h:8
version.h
CBlockUndo::vtxundo
std::vector< CTxUndo > vtxundo
Definition: undo.h:76
compressor.h
Unserialize
void Unserialize(Stream &s, char &a)
Definition: serialize.h:293
TxInUndoFormatter::Unser
void Unser(Stream &s, Coin &txout)
Definition: undo.h:41
CTxOut
An output of a transaction.
Definition: transaction.h:130
Coin
A UTXO entry.
Definition: coins.h:27
VARINT
#define VARINT(obj)
Definition: serialize.h:596
consensus.h
Using
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:591
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
TxInUndoFormatter
Formatter for undo information for a CTxIn.
Definition: undo.h:30
coins.h
CBlock
Definition: block.h:55
CTxUndo::vprevout
std::vector< Coin > vprevout
Definition: undo.h:65
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:231
Coin::GetHeight
uint32_t GetHeight() const
Definition: coins.h:44
disconnectresult.h
serialize.h
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
Coin::GetTxOut
CTxOut & GetTxOut()
Definition: coins.h:48
Serialize
void Serialize(Stream &s, char a)
Definition: serialize.h:241
CBlockUndo
Undo information for a CBlock.
Definition: undo.h:73
Coin::IsCoinBase
bool IsCoinBase() const
Definition: coins.h:45
CBlockUndo::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlockUndo, obj)
Definition: undo.h:78