Line | Count | Source |
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 | | |
15 | | /** Formatter for undo information for a CTxIn |
16 | | * |
17 | | * Contains the prevout's CTxOut being spent, and its metadata as well |
18 | | * (coinbase or not, height). The serialization contains a dummy value of |
19 | | * zero. This is compatible with older versions which expect to see |
20 | | * the transaction version there. |
21 | | */ |
22 | | struct TxInUndoFormatter |
23 | | { |
24 | | template<typename Stream> |
25 | 741 | void Ser(Stream &s, const Coin& txout) { |
26 | 741 | uint32_t nCode{(uint32_t{txout.nHeight} << 1) | uint32_t{txout.fCoinBase}}; |
27 | 741 | ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 0 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 247 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 247 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 247 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
|
28 | 741 | if (txout.nHeight > 0) { |
29 | | // Required to maintain compatibility with older undo format. |
30 | 741 | ::Serialize(s, (unsigned char)0); |
31 | 741 | } |
32 | 741 | ::Serialize(s, Using<TxOutCompression>(txout.out)); |
33 | 741 | } Unexecuted instantiation: void TxInUndoFormatter::Ser<DataStream>(DataStream&, Coin const&) void TxInUndoFormatter::Ser<SizeComputer>(SizeComputer&, Coin const&) Line | Count | Source | 25 | 247 | void Ser(Stream &s, const Coin& txout) { | 26 | 247 | uint32_t nCode{(uint32_t{txout.nHeight} << 1) | uint32_t{txout.fCoinBase}}; | 27 | 247 | ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 247 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| 28 | 247 | if (txout.nHeight > 0) { | 29 | | // Required to maintain compatibility with older undo format. | 30 | 247 | ::Serialize(s, (unsigned char)0); | 31 | 247 | } | 32 | 247 | ::Serialize(s, Using<TxOutCompression>(txout.out)); | 33 | 247 | } |
void TxInUndoFormatter::Ser<HashWriter>(HashWriter&, Coin const&) Line | Count | Source | 25 | 247 | void Ser(Stream &s, const Coin& txout) { | 26 | 247 | uint32_t nCode{(uint32_t{txout.nHeight} << 1) | uint32_t{txout.fCoinBase}}; | 27 | 247 | ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 247 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| 28 | 247 | if (txout.nHeight > 0) { | 29 | | // Required to maintain compatibility with older undo format. | 30 | 247 | ::Serialize(s, (unsigned char)0); | 31 | 247 | } | 32 | 247 | ::Serialize(s, Using<TxOutCompression>(txout.out)); | 33 | 247 | } |
void TxInUndoFormatter::Ser<BufferedWriter<AutoFile>>(BufferedWriter<AutoFile>&, Coin const&) Line | Count | Source | 25 | 247 | void Ser(Stream &s, const Coin& txout) { | 26 | 247 | uint32_t nCode{(uint32_t{txout.nHeight} << 1) | uint32_t{txout.fCoinBase}}; | 27 | 247 | ::Serialize(s, VARINT(nCode)); Line | Count | Source | 493 | 247 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| 28 | 247 | if (txout.nHeight > 0) { | 29 | | // Required to maintain compatibility with older undo format. | 30 | 247 | ::Serialize(s, (unsigned char)0); | 31 | 247 | } | 32 | 247 | ::Serialize(s, Using<TxOutCompression>(txout.out)); | 33 | 247 | } |
|
34 | | |
35 | | template<typename Stream> |
36 | 0 | void Unser(Stream &s, Coin& txout) { |
37 | 0 | uint32_t nCode = 0; |
38 | 0 | ::Unserialize(s, VARINT(nCode)); Line | Count | Source | 493 | 0 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| ::Unserialize(s, VARINT(nCode)); Line | Count | Source | 493 | 0 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
|
39 | 0 | txout.nHeight = nCode >> 1; |
40 | 0 | txout.fCoinBase = nCode & 1; |
41 | 0 | 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 | 0 | unsigned int nVersionDummy; |
46 | 0 | ::Unserialize(s, VARINT(nVersionDummy)); Line | Count | Source | 493 | 0 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
| ::Unserialize(s, VARINT(nVersionDummy)); Line | Count | Source | 493 | 0 | #define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj) |
|
47 | 0 | } |
48 | 0 | ::Unserialize(s, Using<TxOutCompression>(txout.out)); |
49 | 0 | } Unexecuted instantiation: void TxInUndoFormatter::Unser<SpanReader>(SpanReader&, Coin&) Unexecuted instantiation: void TxInUndoFormatter::Unser<HashVerifier<BufferedReader<AutoFile>>>(HashVerifier<BufferedReader<AutoFile>>&, Coin&) |
50 | | }; |
51 | | |
52 | | /** Undo information for a CTransaction */ |
53 | | class CTxUndo |
54 | | { |
55 | | public: |
56 | | // undo information for all txins |
57 | | std::vector<Coin> vprevout; |
58 | | |
59 | 741 | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 0 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 0 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 0 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 247 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 247 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 247 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
Unexecuted instantiation: void CTxUndo::SerializationOps<SpanReader, CTxUndo, ActionUnserialize>(CTxUndo&, SpanReader&, ActionUnserialize) Unexecuted instantiation: void CTxUndo::SerializationOps<DataStream, CTxUndo const, ActionSerialize>(CTxUndo const&, DataStream&, ActionSerialize) Unexecuted instantiation: void CTxUndo::SerializationOps<HashVerifier<BufferedReader<AutoFile>>, CTxUndo, ActionUnserialize>(CTxUndo&, HashVerifier<BufferedReader<AutoFile>>&, ActionUnserialize) void CTxUndo::SerializationOps<SizeComputer, CTxUndo const, ActionSerialize>(CTxUndo const&, SizeComputer&, ActionSerialize) Line | Count | Source | 59 | 247 | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 247 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
|
void CTxUndo::SerializationOps<HashWriter, CTxUndo const, ActionSerialize>(CTxUndo const&, HashWriter&, ActionSerialize) Line | Count | Source | 59 | 247 | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 247 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
|
void CTxUndo::SerializationOps<BufferedWriter<AutoFile>, CTxUndo const, ActionSerialize>(CTxUndo const&, BufferedWriter<AutoFile>&, ActionSerialize) Line | Count | Source | 59 | 247 | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }Line | Count | Source | 147 | 247 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
|
|
60 | | }; |
61 | | |
62 | | /** Undo information for a CBlock */ |
63 | | class CBlockUndo |
64 | | { |
65 | | public: |
66 | | std::vector<CTxUndo> vtxundo; // for all but the coinbase |
67 | | |
68 | 557k | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 0 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 0 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 0 | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 185k | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 185k | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
| SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 185k | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
Unexecuted instantiation: void CBlockUndo::SerializationOps<SpanReader, CBlockUndo, ActionUnserialize>(CBlockUndo&, SpanReader&, ActionUnserialize) Unexecuted instantiation: void CBlockUndo::SerializationOps<DataStream, CBlockUndo const, ActionSerialize>(CBlockUndo const&, DataStream&, ActionSerialize) Unexecuted instantiation: void CBlockUndo::SerializationOps<HashVerifier<BufferedReader<AutoFile>>, CBlockUndo, ActionUnserialize>(CBlockUndo&, HashVerifier<BufferedReader<AutoFile>>&, ActionUnserialize) void CBlockUndo::SerializationOps<SizeComputer, CBlockUndo const, ActionSerialize>(CBlockUndo const&, SizeComputer&, ActionSerialize) Line | Count | Source | 68 | 185k | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 185k | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
|
void CBlockUndo::SerializationOps<HashWriter, CBlockUndo const, ActionSerialize>(CBlockUndo const&, HashWriter&, ActionSerialize) Line | Count | Source | 68 | 185k | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 185k | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
|
void CBlockUndo::SerializationOps<BufferedWriter<AutoFile>, CBlockUndo const, ActionSerialize>(CBlockUndo const&, BufferedWriter<AutoFile>&, ActionSerialize) Line | Count | Source | 68 | 185k | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }Line | Count | Source | 147 | 185k | #define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__)) |
|
|
69 | | }; |
70 | | |
71 | | #endif // BITCOIN_UNDO_H |