Coverage Report

Created: 2026-10-19 15:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/primitives/transaction.h
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_PRIMITIVES_TRANSACTION_H
7
#define BITCOIN_PRIMITIVES_TRANSACTION_H
8
9
#include <attributes.h>
10
#include <consensus/amount.h>
11
#include <primitives/transaction_identifier.h> // IWYU pragma: export
12
#include <script/script.h>
13
#include <serialize.h>
14
15
#include <algorithm>
16
#include <compare>
17
#include <cstddef>
18
#include <cstdint>
19
#include <ios>
20
#include <limits>
21
#include <memory>
22
#include <numeric>
23
#include <string>
24
#include <tuple>
25
#include <utility>
26
#include <vector>
27
28
/** An outpoint - a combination of a transaction hash and an index n into its vout */
29
class COutPoint
30
{
31
public:
32
    Txid hash;
33
    uint32_t n;
34
35
    static constexpr uint32_t NULL_INDEX = std::numeric_limits<uint32_t>::max();
36
37
9.57M
    COutPoint(): n(NULL_INDEX) { }
38
40.1M
    COutPoint(const Txid& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }
39
40
28.9M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<SizeComputer&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<SizeComputer&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
40
4.47M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<DataStream&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
40
137k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<DataStream&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
40
125k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<DataStream, COutPoint, ActionUnserialize>(COutPoint&, DataStream&, ActionUnserialize)
Line
Count
Source
40
4.79k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<SpanReader, COutPoint, ActionUnserialize>(COutPoint&, SpanReader&, ActionUnserialize)
Line
Count
Source
40
1
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<VectorWriter&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<VectorWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
40
69.5k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<HashWriter&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<HashWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
40
2.10M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<SpanReader&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<SpanReader&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
40
332k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
40
517
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<HashWriter, COutPoint const, ActionSerialize>(COutPoint const&, HashWriter&, ActionSerialize)
Line
Count
Source
40
21.5M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<DataStream, COutPoint const, ActionSerialize>(COutPoint const&, DataStream&, ActionSerialize)
Line
Count
Source
40
6.20k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
40
185k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
40
2.38k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<BufferedFile&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<BufferedFile&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
40
2.01k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<SpanWriter, COutPoint const, ActionSerialize>(COutPoint const&, SpanWriter&, ActionSerialize)
Line
Count
Source
40
59
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
41
42
45.4k
    void SetNull() { hash.SetNull(); n = NULL_INDEX; }
43
25.8M
    bool IsNull() const { return (hash.IsNull() && n == NULL_INDEX); }
44
45
    friend bool operator<(const COutPoint& a, const COutPoint& b)
46
437M
    {
47
437M
        return std::tie(a.hash, a.n) < std::tie(b.hash, b.n);
48
437M
    }
49
50
    friend bool operator==(const COutPoint& a, const COutPoint& b)
51
94.9M
    {
52
94.9M
        return (a.hash == b.hash && a.n == b.n);
53
94.9M
    }
54
55
    std::string ToString() const;
56
};
57
58
/** An input of a transaction.  It contains the location of the previous
59
 * transaction's output that it claims and a signature that matches the
60
 * output's public key.
61
 */
62
class CTxIn
63
{
64
public:
65
    COutPoint prevout;
66
    CScript scriptSig;
67
    uint32_t nSequence;
68
    CScriptWitness scriptWitness; //!< Only serialized through CTransaction
69
70
    /**
71
     * Setting nSequence to this value for every input in a transaction
72
     * disables nLockTime/IsFinalTx().
73
     * It fails OP_CHECKLOCKTIMEVERIFY/CheckLockTime() for any input that has
74
     * it set (BIP 65).
75
     * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
76
     */
77
    static constexpr uint32_t SEQUENCE_FINAL{0xffffffff};
78
    /**
79
     * This is the maximum sequence number that enables both nLockTime and
80
     * OP_CHECKLOCKTIMEVERIFY (BIP 65).
81
     * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
82
     */
83
    static constexpr uint32_t MAX_SEQUENCE_NONFINAL{SEQUENCE_FINAL - 1};
84
85
    // Below flags apply in the context of BIP 68. BIP 68 requires the tx
86
    // version to be set to 2, or higher.
87
    /**
88
     * If this flag is set, CTxIn::nSequence is NOT interpreted as a
89
     * relative lock-time.
90
     * It skips SequenceLocks() for any input that has it set (BIP 68).
91
     * It fails OP_CHECKSEQUENCEVERIFY/CheckSequence() for any input that has
92
     * it set (BIP 112).
93
     */
94
    static constexpr uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG{1U << 31};
95
96
    /**
97
     * If CTxIn::nSequence encodes a relative lock-time and this flag
98
     * is set, the relative lock-time has units of 512 seconds,
99
     * otherwise it specifies blocks with a granularity of 1. */
100
    static constexpr uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG{1 << 22};
101
102
    /**
103
     * If CTxIn::nSequence encodes a relative lock-time, this mask is
104
     * applied to extract that lock-time from the sequence field. */
105
    static constexpr uint32_t SEQUENCE_LOCKTIME_MASK{0x0000ffff};
106
107
    /**
108
     * In order to use the same number of bits to encode roughly the
109
     * same wall-clock duration, and because blocks are naturally
110
     * limited to occur every 600s on average, the minimum granularity
111
     * for time-based relative lock-time is fixed at 512 seconds.
112
     * Converting from CTxIn::nSequence to seconds is performed by
113
     * multiplying by 512 = 2^9, or equivalently shifting up by
114
     * 9 bits. */
115
    static constexpr int SEQUENCE_LOCKTIME_GRANULARITY{9};
116
117
    CTxIn()
118
8.35M
    {
119
8.35M
        nSequence = SEQUENCE_FINAL;
120
8.35M
    }
121
122
    explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
123
    CTxIn(Txid hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
124
125
7.43M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<SizeComputer&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<SizeComputer&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
125
4.47M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<DataStream&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
125
137k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<DataStream&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
125
125k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<DataStream, CTxIn, ActionUnserialize>(CTxIn&, DataStream&, ActionUnserialize)
Line
Count
Source
125
4.79k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<SpanReader, CTxIn, ActionUnserialize>(CTxIn&, SpanReader&, ActionUnserialize)
Line
Count
Source
125
1
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<VectorWriter&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<VectorWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
125
69.5k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<HashWriter&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<HashWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
125
2.10M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<SpanReader&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<SpanReader&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
125
332k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
125
517
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
125
185k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
125
2.38k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<BufferedFile&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<BufferedFile&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
125
2.01k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
126
127
    friend bool operator==(const CTxIn& a, const CTxIn& b)
128
48
    {
129
48
        return (a.prevout   == b.prevout &&
130
48
                a.scriptSig == b.scriptSig &&
131
48
                a.nSequence == b.nSequence);
132
48
    }
133
134
    std::string ToString() const;
135
};
136
137
/** An output of a transaction.  It contains the public key that the next input
138
 * must be able to sign with to claim it.
139
 */
140
class CTxOut
141
{
142
public:
143
    CAmount nValue;
144
    CScript scriptPubKey;
145
146
    CTxOut()
147
66.6M
    {
148
66.6M
        SetNull();
149
66.6M
    }
150
151
    CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);
152
153
27.5M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<SizeComputer&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<SizeComputer&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
153
7.16M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<DataStream&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
153
289k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<DataStream&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
153
267k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<DataStream, CTxOut, ActionUnserialize>(CTxOut&, DataStream&, ActionUnserialize)
Line
Count
Source
153
4.78k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<SpanReader, CTxOut, ActionUnserialize>(CTxOut&, SpanReader&, ActionUnserialize)
Line
Count
Source
153
4.78k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<VectorWriter&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<VectorWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
153
170k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<HashWriter&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<HashWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
153
3.83M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<SpanReader&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<SpanReader&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
153
521k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<SizeComputer, CTxOut const, ActionSerialize>(CTxOut const&, SizeComputer&, ActionSerialize)
Line
Count
Source
153
402k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<DataStream, CTxOut const, ActionSerialize>(CTxOut const&, DataStream&, ActionSerialize)
Line
Count
Source
153
7.45k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
153
832
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<HashWriter, CTxOut const, ActionSerialize>(CTxOut const&, HashWriter&, ActionSerialize)
Line
Count
Source
153
14.4M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
153
381k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
153
1.87k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<BufferedFile&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<BufferedFile&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
153
3.96k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
154
155
    void SetNull()
156
78.3M
    {
157
78.3M
        nValue = -1;
158
78.3M
        scriptPubKey.clear();
159
78.3M
    }
160
161
    bool IsNull() const
162
113M
    {
163
113M
        return (nValue == -1);
164
113M
    }
165
166
    friend bool operator==(const CTxOut& a, const CTxOut& b)
167
5.93M
    {
168
5.93M
        return (a.nValue       == b.nValue &&
169
5.93M
                a.scriptPubKey == b.scriptPubKey);
170
5.93M
    }
171
172
    std::string ToString() const;
173
};
174
175
struct CMutableTransaction;
176
177
struct TransactionSerParams {
178
    const bool allow_witness;
179
    SER_PARAMS_OPFUNC
180
};
181
inline constexpr TransactionSerParams TX_WITH_WITNESS{.allow_witness = true};
182
inline constexpr TransactionSerParams TX_NO_WITNESS{.allow_witness = false};
183
184
/**
185
 * Basic transaction serialization format:
186
 * - uint32_t version
187
 * - std::vector<CTxIn> vin
188
 * - std::vector<CTxOut> vout
189
 * - uint32_t nLockTime
190
 *
191
 * Extended transaction serialization format:
192
 * - uint32_t version
193
 * - unsigned char dummy = 0x00
194
 * - unsigned char flags (!= 0)
195
 * - std::vector<CTxIn> vin
196
 * - std::vector<CTxOut> vout
197
 * - if (flags & 1):
198
 *   - CScriptWitness scriptWitness; (deserialized into CTxIn)
199
 * - uint32_t nLockTime
200
 */
201
template<typename Stream, typename TxType>
202
void UnserializeTransaction(TxType& tx, Stream& s, const TransactionSerParams& params)
203
357k
{
204
357k
    const bool fAllowWitness = params.allow_witness;
205
206
357k
    s >> tx.version;
207
357k
    unsigned char flags = 0;
208
357k
    tx.vin.clear();
209
357k
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
357k
    s >> tx.vin;
212
357k
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
292k
        s >> flags;
215
292k
        if (flags != 0) {
216
292k
            s >> tx.vin;
217
292k
            s >> tx.vout;
218
292k
        }
219
292k
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
65.8k
        s >> tx.vout;
222
65.8k
    }
223
357k
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
291k
        flags ^= 1;
226
687k
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
395k
            s >> tx.vin[i].scriptWitness.stack;
228
395k
        }
229
291k
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
10
            throw std::ios_base::failure("Superfluous witness record");
232
10
        }
233
291k
    }
234
357k
    if (flags) {
235
        /* Unknown flag in the serialization */
236
2
        throw std::ios_base::failure("Unknown transaction optional data");
237
2
    }
238
357k
    s >> tx.nLockTime;
239
357k
}
void UnserializeTransaction<ParamsStream<DataStream&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<DataStream&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
203
115k
{
204
115k
    const bool fAllowWitness = params.allow_witness;
205
206
115k
    s >> tx.version;
207
115k
    unsigned char flags = 0;
208
115k
    tx.vin.clear();
209
115k
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
115k
    s >> tx.vin;
212
115k
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
79.8k
        s >> flags;
215
79.8k
        if (flags != 0) {
216
79.8k
            s >> tx.vin;
217
79.8k
            s >> tx.vout;
218
79.8k
        }
219
79.8k
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
35.1k
        s >> tx.vout;
222
35.1k
    }
223
115k
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
79.8k
        flags ^= 1;
226
174k
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
94.2k
            s >> tx.vin[i].scriptWitness.stack;
228
94.2k
        }
229
79.8k
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
1
            throw std::ios_base::failure("Superfluous witness record");
232
1
        }
233
79.8k
    }
234
115k
    if (flags) {
235
        /* Unknown flag in the serialization */
236
1
        throw std::ios_base::failure("Unknown transaction optional data");
237
1
    }
238
115k
    s >> tx.nLockTime;
239
115k
}
void UnserializeTransaction<DataStream, CMutableTransaction>(CMutableTransaction&, DataStream&, TransactionSerParams const&)
Line
Count
Source
203
220
{
204
220
    const bool fAllowWitness = params.allow_witness;
205
206
220
    s >> tx.version;
207
220
    unsigned char flags = 0;
208
220
    tx.vin.clear();
209
220
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
220
    s >> tx.vin;
212
220
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
44
        s >> flags;
215
44
        if (flags != 0) {
216
44
            s >> tx.vin;
217
44
            s >> tx.vout;
218
44
        }
219
176
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
176
        s >> tx.vout;
222
176
    }
223
220
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
44
        flags ^= 1;
226
4.64k
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
4.59k
            s >> tx.vin[i].scriptWitness.stack;
228
4.59k
        }
229
44
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
0
            throw std::ios_base::failure("Superfluous witness record");
232
0
        }
233
44
    }
234
220
    if (flags) {
235
        /* Unknown flag in the serialization */
236
0
        throw std::ios_base::failure("Unknown transaction optional data");
237
0
    }
238
220
    s >> tx.nLockTime;
239
220
}
void UnserializeTransaction<SpanReader, CMutableTransaction>(CMutableTransaction&, SpanReader&, TransactionSerParams const&)
Line
Count
Source
203
1
{
204
1
    const bool fAllowWitness = params.allow_witness;
205
206
1
    s >> tx.version;
207
1
    unsigned char flags = 0;
208
1
    tx.vin.clear();
209
1
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
1
    s >> tx.vin;
212
1
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
0
        s >> flags;
215
0
        if (flags != 0) {
216
0
            s >> tx.vin;
217
0
            s >> tx.vout;
218
0
        }
219
1
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
1
        s >> tx.vout;
222
1
    }
223
1
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
0
        flags ^= 1;
226
0
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
0
            s >> tx.vin[i].scriptWitness.stack;
228
0
        }
229
0
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
0
            throw std::ios_base::failure("Superfluous witness record");
232
0
        }
233
0
    }
234
1
    if (flags) {
235
        /* Unknown flag in the serialization */
236
0
        throw std::ios_base::failure("Unknown transaction optional data");
237
0
    }
238
1
    s >> tx.nLockTime;
239
1
}
void UnserializeTransaction<ParamsStream<SpanReader&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<SpanReader&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
203
240k
{
204
240k
    const bool fAllowWitness = params.allow_witness;
205
206
240k
    s >> tx.version;
207
240k
    unsigned char flags = 0;
208
240k
    tx.vin.clear();
209
240k
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
240k
    s >> tx.vin;
212
240k
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
209k
        s >> flags;
215
209k
        if (flags != 0) {
216
209k
            s >> tx.vin;
217
209k
            s >> tx.vout;
218
209k
        }
219
209k
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
30.4k
        s >> tx.vout;
222
30.4k
    }
223
240k
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
209k
        flags ^= 1;
226
503k
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
294k
            s >> tx.vin[i].scriptWitness.stack;
228
294k
        }
229
209k
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
9
            throw std::ios_base::failure("Superfluous witness record");
232
9
        }
233
209k
    }
234
240k
    if (flags) {
235
        /* Unknown flag in the serialization */
236
1
        throw std::ios_base::failure("Unknown transaction optional data");
237
1
    }
238
240k
    s >> tx.nLockTime;
239
240k
}
void UnserializeTransaction<ParamsStream<AutoFile&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<AutoFile&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
203
500
{
204
500
    const bool fAllowWitness = params.allow_witness;
205
206
500
    s >> tx.version;
207
500
    unsigned char flags = 0;
208
500
    tx.vin.clear();
209
500
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
500
    s >> tx.vin;
212
500
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
472
        s >> flags;
215
472
        if (flags != 0) {
216
472
            s >> tx.vin;
217
472
            s >> tx.vout;
218
472
        }
219
472
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
28
        s >> tx.vout;
222
28
    }
223
500
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
472
        flags ^= 1;
226
961
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
489
            s >> tx.vin[i].scriptWitness.stack;
228
489
        }
229
472
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
0
            throw std::ios_base::failure("Superfluous witness record");
232
0
        }
233
472
    }
234
500
    if (flags) {
235
        /* Unknown flag in the serialization */
236
0
        throw std::ios_base::failure("Unknown transaction optional data");
237
0
    }
238
500
    s >> tx.nLockTime;
239
500
}
void UnserializeTransaction<ParamsStream<BufferedFile&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<BufferedFile&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
203
2.01k
{
204
2.01k
    const bool fAllowWitness = params.allow_witness;
205
206
2.01k
    s >> tx.version;
207
2.01k
    unsigned char flags = 0;
208
2.01k
    tx.vin.clear();
209
2.01k
    tx.vout.clear();
210
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
211
2.01k
    s >> tx.vin;
212
2.01k
    if (tx.vin.size() == 0 && fAllowWitness) {
213
        /* We read a dummy or an empty vin. */
214
1.97k
        s >> flags;
215
1.97k
        if (flags != 0) {
216
1.97k
            s >> tx.vin;
217
1.97k
            s >> tx.vout;
218
1.97k
        }
219
1.97k
    } else {
220
        /* We read a non-empty vin. Assume a normal vout follows. */
221
35
        s >> tx.vout;
222
35
    }
223
2.01k
    if ((flags & 1) && fAllowWitness) {
224
        /* The witness flag is present, and we support witnesses. */
225
1.97k
        flags ^= 1;
226
3.95k
        for (size_t i = 0; i < tx.vin.size(); i++) {
227
1.97k
            s >> tx.vin[i].scriptWitness.stack;
228
1.97k
        }
229
1.97k
        if (!tx.HasWitness()) {
230
            /* It's illegal to encode witnesses when all witness stacks are empty. */
231
0
            throw std::ios_base::failure("Superfluous witness record");
232
0
        }
233
1.97k
    }
234
2.01k
    if (flags) {
235
        /* Unknown flag in the serialization */
236
0
        throw std::ios_base::failure("Unknown transaction optional data");
237
0
    }
238
2.01k
    s >> tx.nLockTime;
239
2.01k
}
240
241
template<typename Stream, typename TxType>
242
void SerializeTransaction(const TxType& tx, Stream& s, const TransactionSerParams& params)
243
6.44M
{
244
6.44M
    const bool fAllowWitness = params.allow_witness;
245
246
6.44M
    s << tx.version;
247
6.44M
    unsigned char flags = 0;
248
    // Consistency check
249
6.44M
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
2.34M
        if (tx.HasWitness()) {
252
1.38M
            flags |= 1;
253
1.38M
        }
254
2.34M
    }
255
6.44M
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
1.38M
        std::vector<CTxIn> vinDummy;
258
1.38M
        s << vinDummy;
259
1.38M
        s << flags;
260
1.38M
    }
261
6.44M
    s << tx.vin;
262
6.44M
    s << tx.vout;
263
6.44M
    if (flags & 1) {
264
3.19M
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
1.81M
            s << tx.vin[i].scriptWitness.stack;
266
1.81M
        }
267
1.38M
    }
268
6.44M
    s << tx.nLockTime;
269
6.44M
}
void SerializeTransaction<ParamsStream<SizeComputer&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<SizeComputer&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
3.71M
{
244
3.71M
    const bool fAllowWitness = params.allow_witness;
245
246
3.71M
    s << tx.version;
247
3.71M
    unsigned char flags = 0;
248
    // Consistency check
249
3.71M
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
1.65M
        if (tx.HasWitness()) {
252
734k
            flags |= 1;
253
734k
        }
254
1.65M
    }
255
3.71M
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
734k
        std::vector<CTxIn> vinDummy;
258
734k
        s << vinDummy;
259
734k
        s << flags;
260
734k
    }
261
3.71M
    s << tx.vin;
262
3.71M
    s << tx.vout;
263
3.71M
    if (flags & 1) {
264
1.68M
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
954k
            s << tx.vin[i].scriptWitness.stack;
266
954k
        }
267
734k
    }
268
3.71M
    s << tx.nLockTime;
269
3.71M
}
void SerializeTransaction<ParamsStream<DataStream&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<DataStream&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
100k
{
244
100k
    const bool fAllowWitness = params.allow_witness;
245
246
100k
    s << tx.version;
247
100k
    unsigned char flags = 0;
248
    // Consistency check
249
100k
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
100k
        if (tx.HasWitness()) {
252
95.0k
            flags |= 1;
253
95.0k
        }
254
100k
    }
255
100k
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
95.0k
        std::vector<CTxIn> vinDummy;
258
95.0k
        s << vinDummy;
259
95.0k
        s << flags;
260
95.0k
    }
261
100k
    s << tx.vin;
262
100k
    s << tx.vout;
263
100k
    if (flags & 1) {
264
206k
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
111k
            s << tx.vin[i].scriptWitness.stack;
266
111k
        }
267
95.0k
    }
268
100k
    s << tx.nLockTime;
269
100k
}
void SerializeTransaction<ParamsStream<VectorWriter&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<VectorWriter&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
59.3k
{
244
59.3k
    const bool fAllowWitness = params.allow_witness;
245
246
59.3k
    s << tx.version;
247
59.3k
    unsigned char flags = 0;
248
    // Consistency check
249
59.3k
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
34.8k
        if (tx.HasWitness()) {
252
32.9k
            flags |= 1;
253
32.9k
        }
254
34.8k
    }
255
59.3k
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
32.9k
        std::vector<CTxIn> vinDummy;
258
32.9k
        s << vinDummy;
259
32.9k
        s << flags;
260
32.9k
    }
261
59.3k
    s << tx.vin;
262
59.3k
    s << tx.vout;
263
59.3k
    if (flags & 1) {
264
74.9k
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
42.0k
            s << tx.vin[i].scriptWitness.stack;
266
42.0k
        }
267
32.9k
    }
268
59.3k
    s << tx.nLockTime;
269
59.3k
}
void SerializeTransaction<ParamsStream<HashWriter&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction const&, ParamsStream<HashWriter&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
711k
{
244
711k
    const bool fAllowWitness = params.allow_witness;
245
246
711k
    s << tx.version;
247
711k
    unsigned char flags = 0;
248
    // Consistency check
249
711k
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
1
        if (tx.HasWitness()) {
252
0
            flags |= 1;
253
0
        }
254
1
    }
255
711k
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
0
        std::vector<CTxIn> vinDummy;
258
0
        s << vinDummy;
259
0
        s << flags;
260
0
    }
261
711k
    s << tx.vin;
262
711k
    s << tx.vout;
263
711k
    if (flags & 1) {
264
0
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
0
            s << tx.vin[i].scriptWitness.stack;
266
0
        }
267
0
    }
268
711k
    s << tx.nLockTime;
269
711k
}
void SerializeTransaction<ParamsStream<SizeComputer&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction const&, ParamsStream<SizeComputer&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
61
{
244
61
    const bool fAllowWitness = params.allow_witness;
245
246
61
    s << tx.version;
247
61
    unsigned char flags = 0;
248
    // Consistency check
249
61
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
1
        if (tx.HasWitness()) {
252
0
            flags |= 1;
253
0
        }
254
1
    }
255
61
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
0
        std::vector<CTxIn> vinDummy;
258
0
        s << vinDummy;
259
0
        s << flags;
260
0
    }
261
61
    s << tx.vin;
262
61
    s << tx.vout;
263
61
    if (flags & 1) {
264
0
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
0
            s << tx.vin[i].scriptWitness.stack;
266
0
        }
267
0
    }
268
61
    s << tx.nLockTime;
269
61
}
void SerializeTransaction<ParamsStream<DataStream&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction const&, ParamsStream<DataStream&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
361
{
244
361
    const bool fAllowWitness = params.allow_witness;
245
246
361
    s << tx.version;
247
361
    unsigned char flags = 0;
248
    // Consistency check
249
361
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
302
        if (tx.HasWitness()) {
252
254
            flags |= 1;
253
254
        }
254
302
    }
255
361
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
254
        std::vector<CTxIn> vinDummy;
258
254
        s << vinDummy;
259
254
        s << flags;
260
254
    }
261
361
    s << tx.vin;
262
361
    s << tx.vout;
263
361
    if (flags & 1) {
264
5.12k
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
4.86k
            s << tx.vin[i].scriptWitness.stack;
266
4.86k
        }
267
254
    }
268
361
    s << tx.nLockTime;
269
361
}
void SerializeTransaction<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
153k
{
244
153k
    const bool fAllowWitness = params.allow_witness;
245
246
153k
    s << tx.version;
247
153k
    unsigned char flags = 0;
248
    // Consistency check
249
153k
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
153k
        if (tx.HasWitness()) {
252
117k
            flags |= 1;
253
117k
        }
254
153k
    }
255
153k
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
117k
        std::vector<CTxIn> vinDummy;
258
117k
        s << vinDummy;
259
117k
        s << flags;
260
117k
    }
261
153k
    s << tx.vin;
262
153k
    s << tx.vout;
263
153k
    if (flags & 1) {
264
258k
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
141k
            s << tx.vin[i].scriptWitness.stack;
266
141k
        }
267
117k
    }
268
153k
    s << tx.nLockTime;
269
153k
}
void SerializeTransaction<ParamsStream<AutoFile&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<AutoFile&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
1.21k
{
244
1.21k
    const bool fAllowWitness = params.allow_witness;
245
246
1.21k
    s << tx.version;
247
1.21k
    unsigned char flags = 0;
248
    // Consistency check
249
1.21k
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
1.21k
        if (tx.HasWitness()) {
252
1.14k
            flags |= 1;
253
1.14k
        }
254
1.21k
    }
255
1.21k
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
1.14k
        std::vector<CTxIn> vinDummy;
258
1.14k
        s << vinDummy;
259
1.14k
        s << flags;
260
1.14k
    }
261
1.21k
    s << tx.vin;
262
1.21k
    s << tx.vout;
263
1.21k
    if (flags & 1) {
264
3.40k
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
2.26k
            s << tx.vin[i].scriptWitness.stack;
266
2.26k
        }
267
1.14k
    }
268
1.21k
    s << tx.nLockTime;
269
1.21k
}
void SerializeTransaction<ParamsStream<HashWriter&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<HashWriter&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
243
1.70M
{
244
1.70M
    const bool fAllowWitness = params.allow_witness;
245
246
1.70M
    s << tx.version;
247
1.70M
    unsigned char flags = 0;
248
    // Consistency check
249
1.70M
    if (fAllowWitness) {
250
        /* Check whether witnesses need to be serialized. */
251
404k
        if (tx.HasWitness()) {
252
404k
            flags |= 1;
253
404k
        }
254
404k
    }
255
1.70M
    if (flags) {
256
        /* Use extended format in case witnesses are to be serialized. */
257
404k
        std::vector<CTxIn> vinDummy;
258
404k
        s << vinDummy;
259
404k
        s << flags;
260
404k
    }
261
1.70M
    s << tx.vin;
262
1.70M
    s << tx.vout;
263
1.70M
    if (flags & 1) {
264
961k
        for (size_t i = 0; i < tx.vin.size(); i++) {
265
556k
            s << tx.vin[i].scriptWitness.stack;
266
556k
        }
267
404k
    }
268
1.70M
    s << tx.nLockTime;
269
1.70M
}
270
271
template<typename TxType>
272
inline CAmount CalculateOutputValue(const TxType& tx)
273
5.66k
{
274
79.2k
    return std::accumulate(tx.vout.cbegin(), tx.vout.cend(), CAmount{0}, [](CAmount sum, const auto& txout) { return sum + txout.nValue; });
275
5.66k
}
276
277
struct EqualsOptions {
278
    bool include_script_sig{true};
279
    bool include_witness_data{true};
280
};
281
282
283
/** The basic transaction that is broadcasted on the network and contained in
284
 * blocks.  A transaction can contain multiple inputs and outputs.
285
 */
286
class CTransaction
287
{
288
public:
289
    // Default transaction version.
290
    static constexpr uint32_t CURRENT_VERSION{2};
291
292
    // The local variables are made const to prevent unintended modification
293
    // without updating the cached hash value. However, CTransaction is not
294
    // actually immutable; deserialization and assignment are implemented,
295
    // and bypass the constness. This is safe, as they update the entire
296
    // structure, including the hash.
297
    const std::vector<CTxIn> vin;
298
    const std::vector<CTxOut> vout;
299
    const uint32_t version;
300
    const uint32_t nLockTime;
301
302
private:
303
    /** Memory only. */
304
    const bool m_has_witness;
305
    const Txid hash;
306
    const Wtxid m_witness_hash;
307
308
    Txid ComputeHash() const;
309
    Wtxid ComputeWitnessHash() const;
310
311
    bool ComputeHasWitness() const;
312
313
public:
314
    /** Convert a CMutableTransaction into a CTransaction. */
315
    explicit CTransaction(const CMutableTransaction& tx);
316
    explicit CTransaction(CMutableTransaction&& tx);
317
318
    template <typename Stream>
319
5.73M
    inline void Serialize(Stream& s) const {
320
5.73M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
5.73M
    }
void CTransaction::Serialize<ParamsStream<SizeComputer&, TransactionSerParams>>(ParamsStream<SizeComputer&, TransactionSerParams>&) const
Line
Count
Source
319
3.71M
    inline void Serialize(Stream& s) const {
320
3.71M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
3.71M
    }
void CTransaction::Serialize<ParamsStream<DataStream&, TransactionSerParams>>(ParamsStream<DataStream&, TransactionSerParams>&) const
Line
Count
Source
319
100k
    inline void Serialize(Stream& s) const {
320
100k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
100k
    }
void CTransaction::Serialize<ParamsStream<VectorWriter&, TransactionSerParams>>(ParamsStream<VectorWriter&, TransactionSerParams>&) const
Line
Count
Source
319
59.3k
    inline void Serialize(Stream& s) const {
320
59.3k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
59.3k
    }
void CTransaction::Serialize<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>>(ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&) const
Line
Count
Source
319
153k
    inline void Serialize(Stream& s) const {
320
153k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
153k
    }
void CTransaction::Serialize<ParamsStream<AutoFile&, TransactionSerParams>>(ParamsStream<AutoFile&, TransactionSerParams>&) const
Line
Count
Source
319
1.21k
    inline void Serialize(Stream& s) const {
320
1.21k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
1.21k
    }
void CTransaction::Serialize<ParamsStream<HashWriter&, TransactionSerParams>>(ParamsStream<HashWriter&, TransactionSerParams>&) const
Line
Count
Source
319
1.70M
    inline void Serialize(Stream& s) const {
320
1.70M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
321
1.70M
    }
322
323
    /** This deserializing constructor is provided instead of an Unserialize method.
324
     *  Unserialize is not possible, since it would require overwriting const fields. */
325
    template <typename Stream>
326
221
    CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {}
CTransaction::CTransaction<DataStream>(deserialize_type, TransactionSerParams const&, DataStream&)
Line
Count
Source
326
220
    CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {}
CTransaction::CTransaction<SpanReader>(deserialize_type, TransactionSerParams const&, SpanReader&)
Line
Count
Source
326
1
    CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {}
327
    template <typename Stream>
328
311k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
CTransaction::CTransaction<ParamsStream<DataStream&, TransactionSerParams>>(deserialize_type, ParamsStream<DataStream&, TransactionSerParams>&)
Line
Count
Source
328
115k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
CTransaction::CTransaction<ParamsStream<SpanReader&, TransactionSerParams>>(deserialize_type, ParamsStream<SpanReader&, TransactionSerParams>&)
Line
Count
Source
328
193k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
CTransaction::CTransaction<ParamsStream<AutoFile&, TransactionSerParams>>(deserialize_type, ParamsStream<AutoFile&, TransactionSerParams>&)
Line
Count
Source
328
500
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
CTransaction::CTransaction<ParamsStream<BufferedFile&, TransactionSerParams>>(deserialize_type, ParamsStream<BufferedFile&, TransactionSerParams>&)
Line
Count
Source
328
2.01k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
329
330
17.8k
    bool IsNull() const {
331
17.8k
        return vin.empty() && vout.empty();
332
17.8k
    }
333
334
195M
    const Txid& GetHash() const LIFETIMEBOUND { return hash; }
335
3.38M
    const Wtxid& GetWitnessHash() const LIFETIMEBOUND { return m_witness_hash; };
336
337
    // Return sum of txouts.
338
    CAmount GetValueOut() const;
339
340
    /**
341
     * Calculate the total transaction size in bytes, including witness data.
342
     * "Total Size" defined in BIP141 and BIP144.
343
     * @return Total transaction size in bytes
344
     */
345
    unsigned int ComputeTotalSize() const;
346
347
    bool IsCoinBase() const
348
32.3M
    {
349
32.3M
        return (vin.size() == 1 && vin[0].prevout.IsNull());
350
32.3M
    }
351
352
    bool Equals(const CTransaction& other, const EqualsOptions opts = {}) const
353
75
    {
354
75
        return nLockTime == other.nLockTime &&
355
75
            version == other.version &&
356
75
            vout == other.vout &&
357
75
            std::ranges::equal(vin, other.vin, [&opts](const CTxIn& self, const CTxIn& other) {
358
42
                return self.prevout == other.prevout &&
359
42
                    self.nSequence == other.nSequence &&
360
42
                    (opts.include_script_sig ? self.scriptSig == other.scriptSig : true) &&
361
42
                    (opts.include_witness_data ? self.scriptWitness.stack == other.scriptWitness.stack : true);
362
42
            });
363
75
    }
364
365
    std::string ToString() const;
366
367
4.00M
    bool HasWitness() const { return m_has_witness; }
368
};
369
370
/** A mutable version of CTransaction. */
371
struct CMutableTransaction
372
{
373
    std::vector<CTxIn> vin;
374
    std::vector<CTxOut> vout;
375
    uint32_t version;
376
    uint32_t nLockTime;
377
378
    explicit CMutableTransaction();
379
    explicit CMutableTransaction(const CTransaction& tx);
380
381
    template <typename Stream>
382
712k
    inline void Serialize(Stream& s) const {
383
712k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
384
712k
    }
void CMutableTransaction::Serialize<ParamsStream<HashWriter&, TransactionSerParams>>(ParamsStream<HashWriter&, TransactionSerParams>&) const
Line
Count
Source
382
711k
    inline void Serialize(Stream& s) const {
383
711k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
384
711k
    }
void CMutableTransaction::Serialize<ParamsStream<SizeComputer&, TransactionSerParams>>(ParamsStream<SizeComputer&, TransactionSerParams>&) const
Line
Count
Source
382
61
    inline void Serialize(Stream& s) const {
383
61
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
384
61
    }
void CMutableTransaction::Serialize<ParamsStream<DataStream&, TransactionSerParams>>(ParamsStream<DataStream&, TransactionSerParams>&) const
Line
Count
Source
382
361
    inline void Serialize(Stream& s) const {
383
361
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
384
361
    }
385
386
    template <typename Stream>
387
357k
    inline void Unserialize(Stream& s) {
388
357k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
389
357k
    }
void CMutableTransaction::Unserialize<ParamsStream<DataStream&, TransactionSerParams>>(ParamsStream<DataStream&, TransactionSerParams>&)
Line
Count
Source
387
115k
    inline void Unserialize(Stream& s) {
388
115k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
389
115k
    }
void CMutableTransaction::Unserialize<ParamsStream<SpanReader&, TransactionSerParams>>(ParamsStream<SpanReader&, TransactionSerParams>&)
Line
Count
Source
387
240k
    inline void Unserialize(Stream& s) {
388
240k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
389
240k
    }
void CMutableTransaction::Unserialize<ParamsStream<AutoFile&, TransactionSerParams>>(ParamsStream<AutoFile&, TransactionSerParams>&)
Line
Count
Source
387
500
    inline void Unserialize(Stream& s) {
388
500
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
389
500
    }
void CMutableTransaction::Unserialize<ParamsStream<BufferedFile&, TransactionSerParams>>(ParamsStream<BufferedFile&, TransactionSerParams>&)
Line
Count
Source
387
2.01k
    inline void Unserialize(Stream& s) {
388
2.01k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
389
2.01k
    }
390
391
    template <typename Stream>
392
221
    CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) {
393
221
        UnserializeTransaction(*this, s, params);
394
221
    }
CMutableTransaction::CMutableTransaction<DataStream>(deserialize_type, TransactionSerParams const&, DataStream&)
Line
Count
Source
392
220
    CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) {
393
220
        UnserializeTransaction(*this, s, params);
394
220
    }
CMutableTransaction::CMutableTransaction<SpanReader>(deserialize_type, TransactionSerParams const&, SpanReader&)
Line
Count
Source
392
1
    CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) {
393
1
        UnserializeTransaction(*this, s, params);
394
1
    }
395
396
    template <typename Stream>
397
311k
    CMutableTransaction(deserialize_type, Stream& s) {
398
311k
        Unserialize(s);
399
311k
    }
CMutableTransaction::CMutableTransaction<ParamsStream<DataStream&, TransactionSerParams>>(deserialize_type, ParamsStream<DataStream&, TransactionSerParams>&)
Line
Count
Source
397
115k
    CMutableTransaction(deserialize_type, Stream& s) {
398
115k
        Unserialize(s);
399
115k
    }
CMutableTransaction::CMutableTransaction<ParamsStream<SpanReader&, TransactionSerParams>>(deserialize_type, ParamsStream<SpanReader&, TransactionSerParams>&)
Line
Count
Source
397
193k
    CMutableTransaction(deserialize_type, Stream& s) {
398
193k
        Unserialize(s);
399
193k
    }
CMutableTransaction::CMutableTransaction<ParamsStream<AutoFile&, TransactionSerParams>>(deserialize_type, ParamsStream<AutoFile&, TransactionSerParams>&)
Line
Count
Source
397
500
    CMutableTransaction(deserialize_type, Stream& s) {
398
500
        Unserialize(s);
399
500
    }
CMutableTransaction::CMutableTransaction<ParamsStream<BufferedFile&, TransactionSerParams>>(deserialize_type, ParamsStream<BufferedFile&, TransactionSerParams>&)
Line
Count
Source
397
2.01k
    CMutableTransaction(deserialize_type, Stream& s) {
398
2.01k
        Unserialize(s);
399
2.01k
    }
400
401
    /** Compute the hash of this CMutableTransaction. This is computed on the
402
     * fly, as opposed to GetHash() in CTransaction, which uses a cached result.
403
     */
404
    Txid GetHash() const;
405
406
    bool HasWitness() const
407
292k
    {
408
293k
        for (size_t i = 0; i < vin.size(); i++) {
409
292k
            if (!vin[i].scriptWitness.IsNull()) {
410
292k
                return true;
411
292k
            }
412
292k
        }
413
60
        return false;
414
292k
    }
415
};
416
417
typedef std::shared_ptr<const CTransaction> CTransactionRef;
418
735k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
blockencodings_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
12
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
blockencodings_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
3
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
blockfilter_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
2
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
blockpolicyestimator_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
49.1k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
coinsviewoverlay_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
801
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
denialofservice_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
7
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mempool_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
15
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mempool_fee_estimator_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
186k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
merkle_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
105k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
miner_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
222
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
miner_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
100
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
miniminer_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
588
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
orphanage_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
276
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
pmt_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
6.48k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
private_broadcast_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
10.0k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
rbf_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
1.25k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
script_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
134
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
serialize_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
1
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txdownload_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
65
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txdownload_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
2
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txindex_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
1
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txpackage_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
78
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txpackage_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CTransaction&>(CTransaction&)
Line
Count
Source
418
3
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txpackage_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
35
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txvalidation_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
34
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txvalidationcache_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction const&>(CMutableTransaction const&)
Line
Count
Source
418
3
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
validation_block_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
982
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
validation_block_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
97
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
validation_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
18
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
validation_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
1
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
coinselector_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
116k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
group_outputs_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
124
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
wallet_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
6
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
wallet_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction const&>(CMutableTransaction const&)
Line
Count
Source
418
2
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
wallet_transaction_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
2
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
ipc_tests.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
1
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mining.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
155
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
setup_common.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction const&>(CMutableTransaction const&)
Line
Count
Source
418
29
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
setup_common.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
2
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txmempool.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction const&>(CMutableTransaction const&)
Line
Count
Source
418
24.7k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txmempool.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
3
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
miner.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
8.61k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
miner.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
43.9k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mempool.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
38.6k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
validation.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
98.1k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
spend.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
4.03k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
wallet.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CTransaction const&>(CTransaction const&)
Line
Count
Source
418
25.5k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
feebumper.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
104
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
backup.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Line
Count
Source
418
4
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
chainparams.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
418
13.1k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
419
420
namespace std {
421
/** Disable default std::hash for CTransactionRef to prevent accidentally
422
 *  comparing by pointer. Use CTransactionRefHash or provide a custom
423
 *  hasher. */
424
template <>
425
struct hash<CTransactionRef> {
426
    hash() = delete;
427
    // Belt-and-suspenders, already implied by the above.
428
    size_t operator()(const CTransactionRef&) const = delete;
429
};
430
} // namespace std
431
432
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H