Line | Count | Source |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2020 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 | 36.1k | void Ser(Stream &s, const Coin& txout) { |
26 | 36.1k | ::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase )); |
27 | 36.1k | if (txout.nHeight > 0) { Branch (27:13): [True: 12.0k, False: 0]
Branch (27:13): [True: 12.0k, False: 0]
Branch (27:13): [True: 12.0k, False: 0]
|
28 | | // Required to maintain compatibility with older undo format. |
29 | 36.1k | ::Serialize(s, (unsigned char)0); |
30 | 36.1k | } |
31 | 36.1k | ::Serialize(s, Using<TxOutCompression>(txout.out)); |
32 | 36.1k | } void TxInUndoFormatter::Ser<SizeComputer>(SizeComputer&, Coin const&) Line | Count | Source | 25 | 12.0k | void Ser(Stream &s, const Coin& txout) { | 26 | 12.0k | ::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase )); | 27 | 12.0k | if (txout.nHeight > 0) { Branch (27:13): [True: 12.0k, False: 0]
| 28 | | // Required to maintain compatibility with older undo format. | 29 | 12.0k | ::Serialize(s, (unsigned char)0); | 30 | 12.0k | } | 31 | 12.0k | ::Serialize(s, Using<TxOutCompression>(txout.out)); | 32 | 12.0k | } |
void TxInUndoFormatter::Ser<HashWriter>(HashWriter&, Coin const&) Line | Count | Source | 25 | 12.0k | void Ser(Stream &s, const Coin& txout) { | 26 | 12.0k | ::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase )); | 27 | 12.0k | if (txout.nHeight > 0) { Branch (27:13): [True: 12.0k, False: 0]
| 28 | | // Required to maintain compatibility with older undo format. | 29 | 12.0k | ::Serialize(s, (unsigned char)0); | 30 | 12.0k | } | 31 | 12.0k | ::Serialize(s, Using<TxOutCompression>(txout.out)); | 32 | 12.0k | } |
void TxInUndoFormatter::Ser<BufferedWriter<AutoFile> >(BufferedWriter<AutoFile>&, Coin const&) Line | Count | Source | 25 | 12.0k | void Ser(Stream &s, const Coin& txout) { | 26 | 12.0k | ::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase )); | 27 | 12.0k | if (txout.nHeight > 0) { Branch (27:13): [True: 12.0k, False: 0]
| 28 | | // Required to maintain compatibility with older undo format. | 29 | 12.0k | ::Serialize(s, (unsigned char)0); | 30 | 12.0k | } | 31 | 12.0k | ::Serialize(s, Using<TxOutCompression>(txout.out)); | 32 | 12.0k | } |
|
33 | | |
34 | | template<typename Stream> |
35 | 29.5k | void Unser(Stream &s, Coin& txout) { |
36 | 29.5k | uint32_t nCode = 0; |
37 | 29.5k | ::Unserialize(s, VARINT(nCode)); |
38 | 29.5k | txout.nHeight = nCode >> 1; |
39 | 29.5k | txout.fCoinBase = nCode & 1; |
40 | 29.5k | if (txout.nHeight > 0) { Branch (40:13): [True: 29.5k, False: 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 | 29.5k | unsigned int nVersionDummy; |
45 | 29.5k | ::Unserialize(s, VARINT(nVersionDummy)); |
46 | 29.5k | } |
47 | 29.5k | ::Unserialize(s, Using<TxOutCompression>(txout.out)); |
48 | 29.5k | } |
49 | | }; |
50 | | |
51 | | /** Undo information for a CTransaction */ |
52 | | class CTxUndo |
53 | | { |
54 | | public: |
55 | | // undo information for all txins |
56 | | std::vector<Coin> vprevout; |
57 | | |
58 | 62.0k | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); } void CTxUndo::SerializationOps<HashVerifier<BufferedReader<AutoFile> >, CTxUndo, ActionUnserialize>(CTxUndo&, HashVerifier<BufferedReader<AutoFile> >&, ActionUnserialize) Line | Count | Source | 58 | 27.9k | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); } |
void CTxUndo::SerializationOps<SizeComputer, CTxUndo const, ActionSerialize>(CTxUndo const&, SizeComputer&, ActionSerialize) Line | Count | Source | 58 | 11.3k | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); } |
void CTxUndo::SerializationOps<HashWriter, CTxUndo const, ActionSerialize>(CTxUndo const&, HashWriter&, ActionSerialize) Line | Count | Source | 58 | 11.3k | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); } |
void CTxUndo::SerializationOps<BufferedWriter<AutoFile>, CTxUndo const, ActionSerialize>(CTxUndo const&, BufferedWriter<AutoFile>&, ActionSerialize) Line | Count | Source | 58 | 11.3k | SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); } |
|
59 | | }; |
60 | | |
61 | | /** Undo information for a CBlock */ |
62 | | class CBlockUndo |
63 | | { |
64 | | public: |
65 | | std::vector<CTxUndo> vtxundo; // for all but the coinbase |
66 | | |
67 | 8.90M | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); } void CBlockUndo::SerializationOps<HashVerifier<BufferedReader<AutoFile> >, CBlockUndo, ActionUnserialize>(CBlockUndo&, HashVerifier<BufferedReader<AutoFile> >&, ActionUnserialize) Line | Count | Source | 67 | 2.22M | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); } |
void CBlockUndo::SerializationOps<SizeComputer, CBlockUndo const, ActionSerialize>(CBlockUndo const&, SizeComputer&, ActionSerialize) Line | Count | Source | 67 | 2.22M | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); } |
void CBlockUndo::SerializationOps<HashWriter, CBlockUndo const, ActionSerialize>(CBlockUndo const&, HashWriter&, ActionSerialize) Line | Count | Source | 67 | 2.22M | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); } |
void CBlockUndo::SerializationOps<BufferedWriter<AutoFile>, CBlockUndo const, ActionSerialize>(CBlockUndo const&, BufferedWriter<AutoFile>&, ActionSerialize) Line | Count | Source | 67 | 2.22M | SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); } |
|
68 | | }; |
69 | | |
70 | | #endif // BITCOIN_UNDO_H |