Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
undo.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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
22
struct
TxInUndoFormatter
23
{
24
template
<
typename
Stream>
25
void
Ser
(Stream &s,
const
Coin
& txout) {
26
::Serialize
(s,
VARINT
(txout.
nHeight
* uint32_t{2} + txout.
fCoinBase
));
27
if
(txout.
nHeight
> 0) {
28
// Required to maintain compatibility with older undo format.
29
::Serialize
(s, (
unsigned
char
)0);
30
}
31
::Serialize
(s,
Using<TxOutCompression>
(txout.
out
));
32
}
33
34
template
<
typename
Stream>
35
void
Unser
(Stream &s,
Coin
& txout) {
36
uint32_t nCode = 0;
37
::Unserialize
(s,
VARINT
(nCode));
38
txout.
nHeight
= nCode >> 1;
39
txout.
fCoinBase
= nCode & 1;
40
if
(txout.
nHeight
> 0) {
41
// Old versions stored the version number for the last spend of
42
// a transaction's outputs. Non-final spends were indicated with
43
// height = 0.
44
unsigned
int
nVersionDummy;
45
::Unserialize
(s,
VARINT
(nVersionDummy));
46
}
47
::Unserialize
(s,
Using<TxOutCompression>
(txout.
out
));
48
}
49
};
50
52
class
CTxUndo
53
{
54
public
:
55
// undo information for all txins
56
std::vector<Coin>
vprevout
;
57
58
SERIALIZE_METHODS
(
CTxUndo
, obj) {
READWRITE
(
Using
<
VectorFormatter<TxInUndoFormatter>
>(obj.vprevout)); }
59
};
60
62
class
CBlockUndo
63
{
64
public
:
65
std::vector<CTxUndo>
vtxundo
;
// for all but the coinbase
66
67
SERIALIZE_METHODS
(
CBlockUndo
, obj) {
READWRITE
(obj.vtxundo); }
68
};
69
70
#endif
// BITCOIN_UNDO_H
CBlockUndo
Undo information for a CBlock.
Definition
undo.h:63
CBlockUndo::vtxundo
std::vector< CTxUndo > vtxundo
Definition
undo.h:65
CBlockUndo::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlockUndo, obj)
Definition
undo.h:67
CTxUndo
Undo information for a CTransaction.
Definition
undo.h:53
CTxUndo::vprevout
std::vector< Coin > vprevout
Definition
undo.h:56
CTxUndo::SERIALIZE_METHODS
SERIALIZE_METHODS(CTxUndo, obj)
Definition
undo.h:58
Coin
A UTXO entry.
Definition
coins.h:35
Coin::out
CTxOut out
unspent transaction output
Definition
coins.h:38
Coin::nHeight
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition
coins.h:44
Coin::fCoinBase
unsigned int fCoinBase
whether containing transaction was a coinbase
Definition
coins.h:41
coins.h
compressor.h
consensus.h
transaction.h
serialize.h
Serialize
void Serialize(Stream &, V)=delete
VARINT
#define VARINT(obj)
Definition
serialize.h:491
Unserialize
void Unserialize(Stream &, V)=delete
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:488
READWRITE
#define READWRITE(...)
Definition
serialize.h:145
TxInUndoFormatter
Formatter for undo information for a CTxIn.
Definition
undo.h:23
TxInUndoFormatter::Unser
void Unser(Stream &s, Coin &txout)
Definition
undo.h:35
TxInUndoFormatter::Ser
void Ser(Stream &s, const Coin &txout)
Definition
undo.h:25
VectorFormatter
Formatter to serialize/deserialize vector elements using another formatter.
Definition
serialize.h:650
Generated on
for Bitcoin Core by
1.17.0