Coverage Report

Created: 2025-09-08 17:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/primitives/transaction.h
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2022 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
#include <uint256.h>
15
16
#include <cstddef>
17
#include <cstdint>
18
#include <ios>
19
#include <limits>
20
#include <memory>
21
#include <numeric>
22
#include <string>
23
#include <tuple>
24
#include <utility>
25
#include <vector>
26
27
/** An outpoint - a combination of a transaction hash and an index n into its vout */
28
class COutPoint
29
{
30
public:
31
    Txid hash;
32
    uint32_t n;
33
34
    static constexpr uint32_t NULL_INDEX = std::numeric_limits<uint32_t>::max();
35
36
39.8M
    COutPoint(): n(NULL_INDEX) { }
37
50.5M
    COutPoint(const Txid& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }
38
39
6.64G
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR12SizeComputer20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
6.57G
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
3.30M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
419k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
569k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
53.6k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR12VectorWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
10.5k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
2.69k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10SpanReader20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
4.42k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI10HashWriterKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
15.0M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR14BufferedWriterI8AutoFileE20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
124k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
754k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
Unexecuted instantiation: _ZN9COutPoint16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR12BufferedFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
44.2k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10HashWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
49.7M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
40
41
127k
    void SetNull() { hash.SetNull(); n = NULL_INDEX; }
42
16.7M
    bool IsNull() const { return (hash.IsNull() && n == NULL_INDEX); }
43
44
    friend bool operator<(const COutPoint& a, const COutPoint& b)
45
427M
    {
46
427M
        return std::tie(a.hash, a.n) < std::tie(b.hash, b.n);
47
427M
    }
48
49
    friend bool operator==(const COutPoint& a, const COutPoint& b)
50
181M
    {
51
181M
        return (a.hash == b.hash && a.n == b.n);
52
181M
    }
53
54
    friend bool operator!=(const COutPoint& a, const COutPoint& b)
55
0
    {
56
0
        return !(a == b);
57
0
    }
58
59
    std::string ToString() const;
60
};
61
62
/** An input of a transaction.  It contains the location of the previous
63
 * transaction's output that it claims and a signature that matches the
64
 * output's public key.
65
 */
66
class CTxIn
67
{
68
public:
69
    COutPoint prevout;
70
    CScript scriptSig;
71
    uint32_t nSequence;
72
    CScriptWitness scriptWitness; //!< Only serialized through CTransaction
73
74
    /**
75
     * Setting nSequence to this value for every input in a transaction
76
     * disables nLockTime/IsFinalTx().
77
     * It fails OP_CHECKLOCKTIMEVERIFY/CheckLockTime() for any input that has
78
     * it set (BIP 65).
79
     * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
80
     */
81
    static const uint32_t SEQUENCE_FINAL = 0xffffffff;
82
    /**
83
     * This is the maximum sequence number that enables both nLockTime and
84
     * OP_CHECKLOCKTIMEVERIFY (BIP 65).
85
     * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
86
     */
87
    static const uint32_t MAX_SEQUENCE_NONFINAL{SEQUENCE_FINAL - 1};
88
89
    // Below flags apply in the context of BIP 68. BIP 68 requires the tx
90
    // version to be set to 2, or higher.
91
    /**
92
     * If this flag is set, CTxIn::nSequence is NOT interpreted as a
93
     * relative lock-time.
94
     * It skips SequenceLocks() for any input that has it set (BIP 68).
95
     * It fails OP_CHECKSEQUENCEVERIFY/CheckSequence() for any input that has
96
     * it set (BIP 112).
97
     */
98
    static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1U << 31);
99
100
    /**
101
     * If CTxIn::nSequence encodes a relative lock-time and this flag
102
     * is set, the relative lock-time has units of 512 seconds,
103
     * otherwise it specifies blocks with a granularity of 1. */
104
    static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
105
106
    /**
107
     * If CTxIn::nSequence encodes a relative lock-time, this mask is
108
     * applied to extract that lock-time from the sequence field. */
109
    static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
110
111
    /**
112
     * In order to use the same number of bits to encode roughly the
113
     * same wall-clock duration, and because blocks are naturally
114
     * limited to occur every 600s on average, the minimum granularity
115
     * for time-based relative lock-time is fixed at 512 seconds.
116
     * Converting from CTxIn::nSequence to seconds is performed by
117
     * multiplying by 512 = 2^9, or equivalently shifting up by
118
     * 9 bits. */
119
    static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
120
121
    CTxIn()
122
18.2M
    {
123
18.2M
        nSequence = SEQUENCE_FINAL;
124
18.2M
    }
125
126
    explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
127
    CTxIn(Txid hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
128
129
6.63G
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR12SizeComputer20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
6.57G
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
3.30M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
569k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
331k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
58
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR12VectorWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
10.5k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
2.69k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10SpanReader20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
4.42k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR14BufferedWriterI8AutoFileE20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
124k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
754k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
Unexecuted instantiation: _ZN5CTxIn16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR12BufferedFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
44.2k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10HashWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
49.7M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
130
131
    friend bool operator==(const CTxIn& a, const CTxIn& b)
132
3.25M
    {
133
3.25M
        return (a.prevout   == b.prevout &&
134
3.25M
                a.scriptSig == b.scriptSig &&
135
3.25M
                a.nSequence == b.nSequence);
136
3.25M
    }
137
138
    friend bool operator!=(const CTxIn& a, const CTxIn& b)
139
0
    {
140
0
        return !(a == b);
141
0
    }
142
143
    std::string ToString() const;
144
};
145
146
/** An output of a transaction.  It contains the public key that the next input
147
 * must be able to sign with to claim it.
148
 */
149
class CTxOut
150
{
151
public:
152
    CAmount nValue;
153
    CScript scriptPubKey;
154
155
    CTxOut()
156
38.8M
    {
157
38.8M
        SetNull();
158
38.8M
    }
159
160
    CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);
161
162
1.69G
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR12SizeComputer20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
969M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
6.25M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
2.52M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
922k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12SizeComputerKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
26.9M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
3.86k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR12VectorWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
10.7k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
2.69k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10SpanReader20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
4.74k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: _ZN6CTxOut16SerializationOpsI10SpanReaderS_17ActionUnserializeEEvRT0_RT_T1_
_ZN6CTxOut16SerializationOpsI10HashWriterKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
3.54M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR14BufferedWriterI8AutoFileE20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
236k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
912k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: _ZN6CTxOut16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR12BufferedFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
12.5k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10HashWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
687M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
163
164
    void SetNull()
165
39.1M
    {
166
39.1M
        nValue = -1;
167
39.1M
        scriptPubKey.clear();
168
39.1M
    }
169
170
    bool IsNull() const
171
46.4M
    {
172
46.4M
        return (nValue == -1);
173
46.4M
    }
174
175
    friend bool operator==(const CTxOut& a, const CTxOut& b)
176
229k
    {
177
229k
        return (a.nValue       == b.nValue &&
178
229k
                a.scriptPubKey == b.scriptPubKey);
179
229k
    }
180
181
    friend bool operator!=(const CTxOut& a, const CTxOut& b)
182
367
    {
183
367
        return !(a == b);
184
367
    }
185
186
    std::string ToString() const;
187
};
188
189
struct CMutableTransaction;
190
191
struct TransactionSerParams {
192
    const bool allow_witness;
193
    SER_PARAMS_OPFUNC
194
};
195
static constexpr TransactionSerParams TX_WITH_WITNESS{.allow_witness = true};
196
static constexpr TransactionSerParams TX_NO_WITNESS{.allow_witness = false};
197
198
/**
199
 * Basic transaction serialization format:
200
 * - uint32_t version
201
 * - std::vector<CTxIn> vin
202
 * - std::vector<CTxOut> vout
203
 * - uint32_t nLockTime
204
 *
205
 * Extended transaction serialization format:
206
 * - uint32_t version
207
 * - unsigned char dummy = 0x00
208
 * - unsigned char flags (!= 0)
209
 * - std::vector<CTxIn> vin
210
 * - std::vector<CTxOut> vout
211
 * - if (flags & 1):
212
 *   - CScriptWitness scriptWitness; (deserialized into CTxIn)
213
 * - uint32_t nLockTime
214
 */
215
template<typename Stream, typename TxType>
216
void UnserializeTransaction(TxType& tx, Stream& s, const TransactionSerParams& params)
217
4.42M
{
218
4.42M
    const bool fAllowWitness = params.allow_witness;
219
220
4.42M
    s >> tx.version;
221
4.42M
    unsigned char flags = 0;
222
4.42M
    tx.vin.clear();
223
4.42M
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
4.42M
    s >> tx.vin;
226
4.42M
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
2.84M
        s >> flags;
229
2.84M
        if (flags != 0) {
230
64.0k
            s >> tx.vin;
231
64.0k
            s >> tx.vout;
232
64.0k
        }
233
2.84M
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
1.58M
        s >> tx.vout;
236
1.58M
    }
237
4.42M
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
60.8k
        flags ^= 1;
240
966k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
905k
            s >> tx.vin[i].scriptWitness.stack;
242
905k
        }
243
60.8k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
1.22k
            throw std::ios_base::failure("Superfluous witness record");
246
1.22k
        }
247
60.8k
    }
248
4.42M
    if (flags) {
249
        /* Unknown flag in the serialization */
250
770
        throw std::ios_base::failure("Unknown transaction optional data");
251
770
    }
252
4.42M
    s >> tx.nLockTime;
253
4.42M
}
_Z22UnserializeTransactionI12ParamsStreamIR10DataStream20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
3.98M
{
218
3.98M
    const bool fAllowWitness = params.allow_witness;
219
220
3.98M
    s >> tx.version;
221
3.98M
    unsigned char flags = 0;
222
3.98M
    tx.vin.clear();
223
3.98M
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
3.98M
    s >> tx.vin;
226
3.98M
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
2.72M
        s >> flags;
229
2.72M
        if (flags != 0) {
230
53.3k
            s >> tx.vin;
231
53.3k
            s >> tx.vout;
232
53.3k
        }
233
2.72M
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
1.26M
        s >> tx.vout;
236
1.26M
    }
237
3.98M
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
52.6k
        flags ^= 1;
240
688k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
635k
            s >> tx.vin[i].scriptWitness.stack;
242
635k
        }
243
52.6k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
250
            throw std::ios_base::failure("Superfluous witness record");
246
250
        }
247
52.6k
    }
248
3.98M
    if (flags) {
249
        /* Unknown flag in the serialization */
250
202
        throw std::ios_base::failure("Unknown transaction optional data");
251
202
    }
252
3.98M
    s >> tx.nLockTime;
253
3.98M
}
_Z22UnserializeTransactionI12ParamsStreamIR10SpanReader20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
4.42k
{
218
4.42k
    const bool fAllowWitness = params.allow_witness;
219
220
4.42k
    s >> tx.version;
221
4.42k
    unsigned char flags = 0;
222
4.42k
    tx.vin.clear();
223
4.42k
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
4.42k
    s >> tx.vin;
226
4.42k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
312
        s >> flags;
229
312
        if (flags != 0) {
230
312
            s >> tx.vin;
231
312
            s >> tx.vout;
232
312
        }
233
4.11k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
4.11k
        s >> tx.vout;
236
4.11k
    }
237
4.42k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
312
        flags ^= 1;
240
624
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
312
            s >> tx.vin[i].scriptWitness.stack;
242
312
        }
243
312
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
0
            throw std::ios_base::failure("Superfluous witness record");
246
0
        }
247
312
    }
248
4.42k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
0
        throw std::ios_base::failure("Unknown transaction optional data");
251
0
    }
252
4.42k
    s >> tx.nLockTime;
253
4.42k
}
_Z22UnserializeTransactionI10DataStream19CMutableTransactionEvRT0_RT_RK20TransactionSerParams
Line
Count
Source
217
2.95k
{
218
2.95k
    const bool fAllowWitness = params.allow_witness;
219
220
2.95k
    s >> tx.version;
221
2.95k
    unsigned char flags = 0;
222
2.95k
    tx.vin.clear();
223
2.95k
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
2.95k
    s >> tx.vin;
226
2.95k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
1.00k
        s >> flags;
229
1.00k
        if (flags != 0) {
230
999
            s >> tx.vin;
231
999
            s >> tx.vout;
232
999
        }
233
1.94k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
1.94k
        s >> tx.vout;
236
1.94k
    }
237
2.95k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
992
        flags ^= 1;
240
226k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
225k
            s >> tx.vin[i].scriptWitness.stack;
242
225k
        }
243
992
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
5
            throw std::ios_base::failure("Superfluous witness record");
246
5
        }
247
992
    }
248
2.94k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
4
        throw std::ios_base::failure("Unknown transaction optional data");
251
4
    }
252
2.94k
    s >> tx.nLockTime;
253
2.94k
}
_Z22UnserializeTransactionI12ParamsStreamIR8AutoFile20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
362k
{
218
362k
    const bool fAllowWitness = params.allow_witness;
219
220
362k
    s >> tx.version;
221
362k
    unsigned char flags = 0;
222
362k
    tx.vin.clear();
223
362k
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
362k
    s >> tx.vin;
226
362k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
59.3k
        s >> flags;
229
59.3k
        if (flags != 0) {
230
2.83k
            s >> tx.vin;
231
2.83k
            s >> tx.vout;
232
2.83k
        }
233
302k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
302k
        s >> tx.vout;
236
302k
    }
237
362k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
2.76k
        flags ^= 1;
240
29.0k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
26.2k
            s >> tx.vin[i].scriptWitness.stack;
242
26.2k
        }
243
2.76k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
12
            throw std::ios_base::failure("Superfluous witness record");
246
12
        }
247
2.76k
    }
248
362k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
39
        throw std::ios_base::failure("Unknown transaction optional data");
251
39
    }
252
361k
    s >> tx.nLockTime;
253
361k
}
_Z22UnserializeTransactionI12ParamsStreamIR12BufferedFile20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
65.2k
{
218
65.2k
    const bool fAllowWitness = params.allow_witness;
219
220
65.2k
    s >> tx.version;
221
65.2k
    unsigned char flags = 0;
222
65.2k
    tx.vin.clear();
223
65.2k
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
65.2k
    s >> tx.vin;
226
65.2k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
52.9k
        s >> flags;
229
52.9k
        if (flags != 0) {
230
6.56k
            s >> tx.vin;
231
6.56k
            s >> tx.vout;
232
6.56k
        }
233
52.9k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
12.2k
        s >> tx.vout;
236
12.2k
    }
237
65.2k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
4.14k
        flags ^= 1;
240
21.7k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
17.6k
            s >> tx.vin[i].scriptWitness.stack;
242
17.6k
        }
243
4.14k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
957
            throw std::ios_base::failure("Superfluous witness record");
246
957
        }
247
4.14k
    }
248
64.2k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
525
        throw std::ios_base::failure("Unknown transaction optional data");
251
525
    }
252
63.7k
    s >> tx.nLockTime;
253
63.7k
}
254
255
template<typename Stream, typename TxType>
256
void SerializeTransaction(const TxType& tx, Stream& s, const TransactionSerParams& params)
257
60.0M
{
258
60.0M
    const bool fAllowWitness = params.allow_witness;
259
260
60.0M
    s << tx.version;
261
60.0M
    unsigned char flags = 0;
262
    // Consistency check
263
60.0M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
24.0M
        if (tx.HasWitness()) {
266
5.97M
            flags |= 1;
267
5.97M
        }
268
24.0M
    }
269
60.0M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
5.97M
        std::vector<CTxIn> vinDummy;
272
5.97M
        s << vinDummy;
273
5.97M
        s << flags;
274
5.97M
    }
275
60.0M
    s << tx.vin;
276
60.0M
    s << tx.vout;
277
60.0M
    if (flags & 1) {
278
45.9M
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
40.0M
            s << tx.vin[i].scriptWitness.stack;
280
40.0M
        }
281
5.97M
    }
282
60.0M
    s << tx.nLockTime;
283
60.0M
}
_Z20SerializeTransactionI12ParamsStreamIR12SizeComputer20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
46.6M
{
258
46.6M
    const bool fAllowWitness = params.allow_witness;
259
260
46.6M
    s << tx.version;
261
46.6M
    unsigned char flags = 0;
262
    // Consistency check
263
46.6M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
21.2M
        if (tx.HasWitness()) {
266
3.41M
            flags |= 1;
267
3.41M
        }
268
21.2M
    }
269
46.6M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
3.41M
        std::vector<CTxIn> vinDummy;
272
3.41M
        s << vinDummy;
273
3.41M
        s << flags;
274
3.41M
    }
275
46.6M
    s << tx.vin;
276
46.6M
    s << tx.vout;
277
46.6M
    if (flags & 1) {
278
25.6M
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
22.2M
            s << tx.vin[i].scriptWitness.stack;
280
22.2M
        }
281
3.41M
    }
282
46.6M
    s << tx.nLockTime;
283
46.6M
}
_Z20SerializeTransactionI12ParamsStreamIR10DataStream20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
188k
{
258
188k
    const bool fAllowWitness = params.allow_witness;
259
260
188k
    s << tx.version;
261
188k
    unsigned char flags = 0;
262
    // Consistency check
263
188k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
187k
        if (tx.HasWitness()) {
266
3.66k
            flags |= 1;
267
3.66k
        }
268
187k
    }
269
188k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
3.66k
        std::vector<CTxIn> vinDummy;
272
3.66k
        s << vinDummy;
273
3.66k
        s << flags;
274
3.66k
    }
275
188k
    s << tx.vin;
276
188k
    s << tx.vout;
277
188k
    if (flags & 1) {
278
286k
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
282k
            s << tx.vin[i].scriptWitness.stack;
280
282k
        }
281
3.66k
    }
282
188k
    s << tx.nLockTime;
283
188k
}
_Z20SerializeTransactionI12ParamsStreamIR12SizeComputer20TransactionSerParamsE19CMutableTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
33.2k
{
258
33.2k
    const bool fAllowWitness = params.allow_witness;
259
260
33.2k
    s << tx.version;
261
33.2k
    unsigned char flags = 0;
262
    // Consistency check
263
33.2k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
0
        if (tx.HasWitness()) {
266
0
            flags |= 1;
267
0
        }
268
0
    }
269
33.2k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
0
        std::vector<CTxIn> vinDummy;
272
0
        s << vinDummy;
273
0
        s << flags;
274
0
    }
275
33.2k
    s << tx.vin;
276
33.2k
    s << tx.vout;
277
33.2k
    if (flags & 1) {
278
0
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
0
            s << tx.vin[i].scriptWitness.stack;
280
0
        }
281
0
    }
282
33.2k
    s << tx.nLockTime;
283
33.2k
}
_Z20SerializeTransactionI12ParamsStreamIR10DataStream20TransactionSerParamsE19CMutableTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
36.8k
{
258
36.8k
    const bool fAllowWitness = params.allow_witness;
259
260
36.8k
    s << tx.version;
261
36.8k
    unsigned char flags = 0;
262
    // Consistency check
263
36.8k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
1.41k
        if (tx.HasWitness()) {
266
335
            flags |= 1;
267
335
        }
268
1.41k
    }
269
36.8k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
335
        std::vector<CTxIn> vinDummy;
272
335
        s << vinDummy;
273
335
        s << flags;
274
335
    }
275
36.8k
    s << tx.vin;
276
36.8k
    s << tx.vout;
277
36.8k
    if (flags & 1) {
278
6.43k
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
6.10k
            s << tx.vin[i].scriptWitness.stack;
280
6.10k
        }
281
335
    }
282
36.8k
    s << tx.nLockTime;
283
36.8k
}
_Z20SerializeTransactionI12ParamsStreamIR12VectorWriter20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
10.5k
{
258
10.5k
    const bool fAllowWitness = params.allow_witness;
259
260
10.5k
    s << tx.version;
261
10.5k
    unsigned char flags = 0;
262
    // Consistency check
263
10.5k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
8.01k
        if (tx.HasWitness()) {
266
127
            flags |= 1;
267
127
        }
268
8.01k
    }
269
10.5k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
127
        std::vector<CTxIn> vinDummy;
272
127
        s << vinDummy;
273
127
        s << flags;
274
127
    }
275
10.5k
    s << tx.vin;
276
10.5k
    s << tx.vout;
277
10.5k
    if (flags & 1) {
278
254
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
127
            s << tx.vin[i].scriptWitness.stack;
280
127
        }
281
127
    }
282
10.5k
    s << tx.nLockTime;
283
10.5k
}
_Z20SerializeTransactionI12ParamsStreamIRS0_IR12VectorWriter20TransactionSerParamsES3_E12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
2.69k
{
258
2.69k
    const bool fAllowWitness = params.allow_witness;
259
260
2.69k
    s << tx.version;
261
2.69k
    unsigned char flags = 0;
262
    // Consistency check
263
2.69k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
2.69k
        if (tx.HasWitness()) {
266
0
            flags |= 1;
267
0
        }
268
2.69k
    }
269
2.69k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
0
        std::vector<CTxIn> vinDummy;
272
0
        s << vinDummy;
273
0
        s << flags;
274
0
    }
275
2.69k
    s << tx.vin;
276
2.69k
    s << tx.vout;
277
2.69k
    if (flags & 1) {
278
0
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
0
            s << tx.vin[i].scriptWitness.stack;
280
0
        }
281
0
    }
282
2.69k
    s << tx.nLockTime;
283
2.69k
}
_Z20SerializeTransactionI12ParamsStreamIR14BufferedWriterI8AutoFileE20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS5_
Line
Count
Source
257
122k
{
258
122k
    const bool fAllowWitness = params.allow_witness;
259
260
122k
    s << tx.version;
261
122k
    unsigned char flags = 0;
262
    // Consistency check
263
122k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
122k
        if (tx.HasWitness()) {
266
112k
            flags |= 1;
267
112k
        }
268
122k
    }
269
122k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
112k
        std::vector<CTxIn> vinDummy;
272
112k
        s << vinDummy;
273
112k
        s << flags;
274
112k
    }
275
122k
    s << tx.vin;
276
122k
    s << tx.vout;
277
122k
    if (flags & 1) {
278
224k
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
112k
            s << tx.vin[i].scriptWitness.stack;
280
112k
        }
281
112k
    }
282
122k
    s << tx.nLockTime;
283
122k
}
Unexecuted instantiation: _Z20SerializeTransactionI12ParamsStreamIR8AutoFile20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
_Z20SerializeTransactionI12ParamsStreamIR10HashWriter20TransactionSerParamsE19CMutableTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
1.19M
{
258
1.19M
    const bool fAllowWitness = params.allow_witness;
259
260
1.19M
    s << tx.version;
261
1.19M
    unsigned char flags = 0;
262
    // Consistency check
263
1.19M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
0
        if (tx.HasWitness()) {
266
0
            flags |= 1;
267
0
        }
268
0
    }
269
1.19M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
0
        std::vector<CTxIn> vinDummy;
272
0
        s << vinDummy;
273
0
        s << flags;
274
0
    }
275
1.19M
    s << tx.vin;
276
1.19M
    s << tx.vout;
277
1.19M
    if (flags & 1) {
278
0
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
0
            s << tx.vin[i].scriptWitness.stack;
280
0
        }
281
0
    }
282
1.19M
    s << tx.nLockTime;
283
1.19M
}
_Z20SerializeTransactionI12ParamsStreamIR10HashWriter20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
11.9M
{
258
11.9M
    const bool fAllowWitness = params.allow_witness;
259
260
11.9M
    s << tx.version;
261
11.9M
    unsigned char flags = 0;
262
    // Consistency check
263
11.9M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
2.45M
        if (tx.HasWitness()) {
266
2.45M
            flags |= 1;
267
2.45M
        }
268
2.45M
    }
269
11.9M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
2.45M
        std::vector<CTxIn> vinDummy;
272
2.45M
        s << vinDummy;
273
2.45M
        s << flags;
274
2.45M
    }
275
11.9M
    s << tx.vin;
276
11.9M
    s << tx.vout;
277
11.9M
    if (flags & 1) {
278
19.7M
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
17.3M
            s << tx.vin[i].scriptWitness.stack;
280
17.3M
        }
281
2.45M
    }
282
11.9M
    s << tx.nLockTime;
283
11.9M
}
284
285
template<typename TxType>
286
inline CAmount CalculateOutputValue(const TxType& tx)
287
0
{
288
0
    return std::accumulate(tx.vout.cbegin(), tx.vout.cend(), CAmount{0}, [](CAmount sum, const auto& txout) { return sum + txout.nValue; });
289
0
}
290
291
292
/** The basic transaction that is broadcasted on the network and contained in
293
 * blocks.  A transaction can contain multiple inputs and outputs.
294
 */
295
class CTransaction
296
{
297
public:
298
    // Default transaction version.
299
    static const uint32_t CURRENT_VERSION{2};
300
301
    // The local variables are made const to prevent unintended modification
302
    // without updating the cached hash value. However, CTransaction is not
303
    // actually immutable; deserialization and assignment are implemented,
304
    // and bypass the constness. This is safe, as they update the entire
305
    // structure, including the hash.
306
    const std::vector<CTxIn> vin;
307
    const std::vector<CTxOut> vout;
308
    const uint32_t version;
309
    const uint32_t nLockTime;
310
311
private:
312
    /** Memory only. */
313
    const bool m_has_witness;
314
    const Txid hash;
315
    const Wtxid m_witness_hash;
316
317
    Txid ComputeHash() const;
318
    Wtxid ComputeWitnessHash() const;
319
320
    bool ComputeHasWitness() const;
321
322
public:
323
    /** Convert a CMutableTransaction into a CTransaction. */
324
    explicit CTransaction(const CMutableTransaction& tx);
325
    explicit CTransaction(CMutableTransaction&& tx);
326
327
    template <typename Stream>
328
58.8M
    inline void Serialize(Stream& s) const {
329
58.8M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
58.8M
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR12SizeComputer20TransactionSerParamsEEEvRT_
Line
Count
Source
328
46.6M
    inline void Serialize(Stream& s) const {
329
46.6M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
46.6M
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_
Line
Count
Source
328
188k
    inline void Serialize(Stream& s) const {
329
188k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
188k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR12VectorWriter20TransactionSerParamsEEEvRT_
Line
Count
Source
328
10.5k
    inline void Serialize(Stream& s) const {
329
10.5k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
10.5k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EEEvRT_
Line
Count
Source
328
2.69k
    inline void Serialize(Stream& s) const {
329
2.69k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
2.69k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR14BufferedWriterI8AutoFileE20TransactionSerParamsEEEvRT_
Line
Count
Source
328
122k
    inline void Serialize(Stream& s) const {
329
122k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
122k
    }
Unexecuted instantiation: _ZNK12CTransaction9SerializeI12ParamsStreamIR8AutoFile20TransactionSerParamsEEEvRT_
_ZNK12CTransaction9SerializeI12ParamsStreamIR10HashWriter20TransactionSerParamsEEEvRT_
Line
Count
Source
328
11.9M
    inline void Serialize(Stream& s) const {
329
11.9M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
11.9M
    }
331
332
    /** This deserializing constructor is provided instead of an Unserialize method.
333
     *  Unserialize is not possible, since it would require overwriting const fields. */
334
    template <typename Stream>
335
2.95k
    CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {}
336
    template <typename Stream>
337
3.95M
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR10DataStream20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
3.52M
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR10SpanReader20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
4.42k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR8AutoFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
362k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR12BufferedFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
65.2k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
338
339
1.34k
    bool IsNull() const {
340
1.34k
        return vin.empty() && vout.empty();
341
1.34k
    }
342
343
2.97G
    const Txid& GetHash() const LIFETIMEBOUND { return hash; }
344
325M
    const Wtxid& GetWitnessHash() const LIFETIMEBOUND { return m_witness_hash; };
345
346
    // Return sum of txouts.
347
    CAmount GetValueOut() const;
348
349
    /**
350
     * Get the total transaction size in bytes, including witness data.
351
     * "Total Size" defined in BIP141 and BIP144.
352
     * @return Total transaction size in bytes
353
     */
354
    unsigned int GetTotalSize() const;
355
356
    bool IsCoinBase() const
357
9.24M
    {
358
9.24M
        return (vin.size() == 1 && vin[0].prevout.IsNull());
359
9.24M
    }
360
361
    friend bool operator==(const CTransaction& a, const CTransaction& b)
362
390
    {
363
390
        return a.GetWitnessHash() == b.GetWitnessHash();
364
390
    }
365
366
    friend bool operator!=(const CTransaction& a, const CTransaction& b)
367
195
    {
368
195
        return !operator==(a, b);
369
195
    }
370
371
    std::string ToString() const;
372
373
35.4M
    bool HasWitness() const { return m_has_witness; }
374
};
375
376
/** A mutable version of CTransaction. */
377
struct CMutableTransaction
378
{
379
    std::vector<CTxIn> vin;
380
    std::vector<CTxOut> vout;
381
    uint32_t version;
382
    uint32_t nLockTime;
383
384
    explicit CMutableTransaction();
385
    explicit CMutableTransaction(const CTransaction& tx);
386
387
    template <typename Stream>
388
1.26M
    inline void Serialize(Stream& s) const {
389
1.26M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
1.26M
    }
_ZNK19CMutableTransaction9SerializeI12ParamsStreamIR12SizeComputer20TransactionSerParamsEEEvRT_
Line
Count
Source
388
33.2k
    inline void Serialize(Stream& s) const {
389
33.2k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
33.2k
    }
_ZNK19CMutableTransaction9SerializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_
Line
Count
Source
388
36.8k
    inline void Serialize(Stream& s) const {
389
36.8k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
36.8k
    }
_ZNK19CMutableTransaction9SerializeI12ParamsStreamIR10HashWriter20TransactionSerParamsEEEvRT_
Line
Count
Source
388
1.19M
    inline void Serialize(Stream& s) const {
389
1.19M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
1.19M
    }
391
392
    template <typename Stream>
393
4.42M
    inline void Unserialize(Stream& s) {
394
4.42M
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
4.42M
    }
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_
Line
Count
Source
393
3.98M
    inline void Unserialize(Stream& s) {
394
3.98M
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
3.98M
    }
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR10SpanReader20TransactionSerParamsEEEvRT_
Line
Count
Source
393
4.42k
    inline void Unserialize(Stream& s) {
394
4.42k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
4.42k
    }
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR8AutoFile20TransactionSerParamsEEEvRT_
Line
Count
Source
393
362k
    inline void Unserialize(Stream& s) {
394
362k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
362k
    }
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR12BufferedFile20TransactionSerParamsEEEvRT_
Line
Count
Source
393
65.2k
    inline void Unserialize(Stream& s) {
394
65.2k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
65.2k
    }
396
397
    template <typename Stream>
398
2.95k
    CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) {
399
2.95k
        UnserializeTransaction(*this, s, params);
400
2.95k
    }
401
402
    template <typename Stream>
403
3.95M
    CMutableTransaction(deserialize_type, Stream& s) {
404
3.95M
        Unserialize(s);
405
3.95M
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR10DataStream20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
3.52M
    CMutableTransaction(deserialize_type, Stream& s) {
404
3.52M
        Unserialize(s);
405
3.52M
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR10SpanReader20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
4.42k
    CMutableTransaction(deserialize_type, Stream& s) {
404
4.42k
        Unserialize(s);
405
4.42k
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR8AutoFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
362k
    CMutableTransaction(deserialize_type, Stream& s) {
404
362k
        Unserialize(s);
405
362k
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR12BufferedFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
65.2k
    CMutableTransaction(deserialize_type, Stream& s) {
404
65.2k
        Unserialize(s);
405
65.2k
    }
406
407
    /** Compute the hash of this CMutableTransaction. This is computed on the
408
     * fly, as opposed to GetHash() in CTransaction, which uses a cached result.
409
     */
410
    Txid GetHash() const;
411
412
    bool HasWitness() const
413
60.9k
    {
414
266k
        for (size_t i = 0; i < vin.size(); i++) {
415
264k
            if (!vin[i].scriptWitness.IsNull()) {
416
58.3k
                return true;
417
58.3k
            }
418
264k
        }
419
2.54k
        return false;
420
60.9k
    }
421
};
422
423
typedef std::shared_ptr<const CTransaction> CTransactionRef;
424
5.26M
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mini_miner.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
155k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
p2p_headers_presync.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
10.5k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
package_eval.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
651k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txdownloadman.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
1.88M
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
tx_pool.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
77.5k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
tx_pool.cpp:_ZL18MakeTransactionRefIRK19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
168k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txorphan.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
33.5k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
txorphan.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
11.9k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
utxo_total_supply.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
91.6k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
spend.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
94.2k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mempool.cpp:_ZL18MakeTransactionRefIRK12CTransactionESt10shared_ptrIS1_EOT_
Line
Count
Source
424
1.57M
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
chainparams.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
5.07k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
Unexecuted instantiation: wallet.cpp:_ZL18MakeTransactionRefIRK12CTransactionESt10shared_ptrIS1_EOT_
Unexecuted instantiation: feebumper.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Unexecuted instantiation: backup.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Unexecuted instantiation: mining.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Unexecuted instantiation: setup_common.cpp:_ZL18MakeTransactionRefIRK19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Unexecuted instantiation: setup_common.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Unexecuted instantiation: txmempool.cpp:_ZL18MakeTransactionRefIRK19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
miner.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
66.4k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
miner.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
127k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
mempool.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
1.27k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
validation.cpp:_ZL18MakeTransactionRefI19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
319k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
425
426
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H