Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
17class CBlock;
18class CBlockIndex;
19class 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 }
39 }
40
41 template <typename Stream> void Unser(Stream &s, Coin &txout) {
42 uint32_t nCode = 0;
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;
52 }
53
54 CTxOut out;
56
57 txout = Coin(std::move(out), nHeight, fCoinBase);
58 }
59};
60
62class CTxUndo {
63public:
64 // Undo information for all txins
65 std::vector<Coin> vprevout;
66
70};
71
74public:
75 // For all but the coinbase
76 std::vector<CTxUndo> vtxundo;
77
79};
80
89 const COutPoint &out);
90
96 const CBlockIndex *pindex,
97 CCoinsViewCache &coins);
98
99#endif // BITCOIN_UNDO_H
Definition block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition blockindex.h:25
Undo information for a CBlock.
Definition undo.h:73
std::vector< CTxUndo > vtxundo
Definition undo.h:76
SERIALIZE_METHODS(CBlockUndo, obj)
Definition undo.h:78
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition coins.h:221
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:20
An output of a transaction.
Restore the UTXO in a Coin at a given COutPoint.
Definition undo.h:62
std::vector< Coin > vprevout
Definition undo.h:65
SERIALIZE_METHODS(CTxUndo, obj)
Definition undo.h:67
A UTXO entry.
Definition coins.h:28
uint32_t GetHeight() const
Definition coins.h:45
bool IsCoinBase() const
Definition coins.h:46
CTxOut & GetTxOut()
Definition coins.h:49
DisconnectResult
unsigned int nHeight
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
#define VARINT(obj)
Definition serialize.h:579
void Unserialize(Stream &, char)=delete
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition serialize.h:574
#define READWRITE(...)
Definition serialize.h:166
void Serialize(Stream &, char)=delete
Formatter for undo information for a CTxIn.
Definition undo.h:30
void Unser(Stream &s, Coin &txout)
Definition undo.h:41
void Ser(Stream &s, const Coin &txout)
Definition undo.h:31
Formatter to serialize/deserialize vector elements using another formatter.
Definition serialize.h:718
DisconnectResult UndoCoinSpend(Coin &&undo, CCoinsViewCache &view, const COutPoint &out)
Restore the UTXO in a Coin at a given COutPoint.
DisconnectResult ApplyBlockUndo(CBlockUndo &&blockUndo, const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &coins)
Undo a block from the block and the undoblock data.