Coverage Report

Created: 2025-03-27 15:33

/root/bitcoin/src/primitives/transaction.h
Line
Count
Source (jump to first uncovered line)
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 <script/script.h>
12
#include <serialize.h>
13
#include <uint256.h>
14
#include <util/transaction_identifier.h> // IWYU pragma: export
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
35.7M
    COutPoint(): n(NULL_INDEX) { }
37
55.8M
    COutPoint(const Txid& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }
38
39
958M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR12SizeComputer20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
894M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
3.23M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
371k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
835k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
61.6k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR12VectorWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
10.7k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
3.13k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
Unexecuted instantiation: _ZN9COutPoint16SerializationOpsI12ParamsStreamIR10SpanReader20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
_ZN9COutPoint16SerializationOpsI10HashWriterKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
18.0M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
782k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
74.2k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR12BufferedFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
39
61.0k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
_ZN9COutPoint16SerializationOpsI12ParamsStreamIR10HashWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
39
40.0M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
40
41
79.5k
    void SetNull() { hash.SetNull(); n = NULL_INDEX; }
42
17.4M
    bool IsNull() const { return (hash.IsNull() && n == NULL_INDEX); }
43
44
    friend bool operator<(const COutPoint& a, const COutPoint& b)
45
1.07G
    {
46
1.07G
        return std::tie(a.hash, a.n) < std::tie(b.hash, b.n);
47
1.07G
    }
48
49
    friend bool operator==(const COutPoint& a, const COutPoint& b)
50
112M
    {
51
112M
        return (a.hash == b.hash && a.n == b.n);
52
112M
    }
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.9M
    {
123
18.9M
        nSequence = SEQUENCE_FINAL;
124
18.9M
    }
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
940M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR12SizeComputer20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
894M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
3.23M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
835k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
295k
    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.7k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
3.13k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
Unexecuted instantiation: _ZN5CTxIn16SerializationOpsI12ParamsStreamIR10SpanReader20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
782k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
74.2k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR12BufferedFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
129
61.0k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
_ZN5CTxIn16SerializationOpsI12ParamsStreamIR10HashWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
129
40.0M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
130
131
    friend bool operator==(const CTxIn& a, const CTxIn& b)
132
3.83M
    {
133
3.83M
        return (a.prevout   == b.prevout &&
134
3.83M
                a.scriptSig == b.scriptSig &&
135
3.83M
                a.nSequence == b.nSequence);
136
3.83M
    }
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
33.6M
    {
157
33.6M
        SetNull();
158
33.6M
    }
159
160
    CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);
161
162
711M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR12SizeComputer20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
274M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
5.89M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10DataStream20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
2.80M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI10DataStreamS_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
858k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12SizeComputerKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
20.4M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI10DataStreamKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
3.69k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR12VectorWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
11.1k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
3.13k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: _ZN6CTxOut16SerializationOpsI12ParamsStreamIR10SpanReader20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Unexecuted instantiation: _ZN6CTxOut16SerializationOpsI10SpanReaderS_17ActionUnserializeEEvRT0_RT_T1_
_ZN6CTxOut16SerializationOpsI10HashWriterKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
2.63M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
807k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR8AutoFile20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
136k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR12BufferedFile20TransactionSerParamsES_17ActionUnserializeEEvRT0_RT_T1_
Line
Count
Source
162
16.5k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
_ZN6CTxOut16SerializationOpsI12ParamsStreamIR10HashWriter20TransactionSerParamsEKS_15ActionSerializeEEvRT0_RT_T1_
Line
Count
Source
162
403M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
163
164
    void SetNull()
165
34.1M
    {
166
34.1M
        nValue = -1;
167
34.1M
        scriptPubKey.clear();
168
34.1M
    }
169
170
    bool IsNull() const
171
37.9M
    {
172
37.9M
        return (nValue == -1);
173
37.9M
    }
174
175
    friend bool operator==(const CTxOut& a, const CTxOut& b)
176
200k
    {
177
200k
        return (a.nValue       == b.nValue &&
178
200k
                a.scriptPubKey == b.scriptPubKey);
179
200k
    }
180
181
    friend bool operator!=(const CTxOut& a, const CTxOut& b)
182
368
    {
183
368
        return !(a == b);
184
368
    }
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
3.36M
{
218
3.36M
    const bool fAllowWitness = params.allow_witness;
219
220
3.36M
    s >> tx.version;
221
3.36M
    unsigned char flags = 0;
222
3.36M
    tx.vin.clear();
223
3.36M
    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.36M
    s >> tx.vin;
226
3.36M
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
2.61M
        s >> flags;
229
2.61M
        if (flags != 0) {
230
68.7k
            s >> tx.vin;
231
68.7k
            s >> tx.vout;
232
68.7k
        }
233
2.61M
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
753k
        s >> tx.vout;
236
753k
    }
237
3.36M
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
64.4k
        flags ^= 1;
240
872k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
807k
            s >> tx.vin[i].scriptWitness.stack;
242
807k
        }
243
64.4k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
1.53k
            throw std::ios_base::failure("Superfluous witness record");
246
1.53k
        }
247
64.4k
    }
248
3.36M
    if (flags) {
249
        /* Unknown flag in the serialization */
250
1.13k
        throw std::ios_base::failure("Unknown transaction optional data");
251
1.13k
    }
252
3.36M
    s >> tx.nLockTime;
253
3.36M
}
_Z22UnserializeTransactionI12ParamsStreamIR10DataStream20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
2.90M
{
218
2.90M
    const bool fAllowWitness = params.allow_witness;
219
220
2.90M
    s >> tx.version;
221
2.90M
    unsigned char flags = 0;
222
2.90M
    tx.vin.clear();
223
2.90M
    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.90M
    s >> tx.vin;
226
2.90M
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
2.47M
        s >> flags;
229
2.47M
        if (flags != 0) {
230
54.0k
            s >> tx.vin;
231
54.0k
            s >> tx.vout;
232
54.0k
        }
233
2.47M
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
435k
        s >> tx.vout;
236
435k
    }
237
2.90M
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
53.4k
        flags ^= 1;
240
633k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
579k
            s >> tx.vin[i].scriptWitness.stack;
242
579k
        }
243
53.4k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
238
            throw std::ios_base::failure("Superfluous witness record");
246
238
        }
247
53.4k
    }
248
2.90M
    if (flags) {
249
        /* Unknown flag in the serialization */
250
191
        throw std::ios_base::failure("Unknown transaction optional data");
251
191
    }
252
2.90M
    s >> tx.nLockTime;
253
2.90M
}
Unexecuted instantiation: _Z22UnserializeTransactionI12ParamsStreamIR10SpanReader20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
_Z22UnserializeTransactionI10DataStream19CMutableTransactionEvRT0_RT_RK20TransactionSerParams
Line
Count
Source
217
3.04k
{
218
3.04k
    const bool fAllowWitness = params.allow_witness;
219
220
3.04k
    s >> tx.version;
221
3.04k
    unsigned char flags = 0;
222
3.04k
    tx.vin.clear();
223
3.04k
    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.04k
    s >> tx.vin;
226
3.04k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
1.01k
        s >> flags;
229
1.01k
        if (flags != 0) {
230
1.01k
            s >> tx.vin;
231
1.01k
            s >> tx.vout;
232
1.01k
        }
233
2.02k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
2.02k
        s >> tx.vout;
236
2.02k
    }
237
3.04k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
1.00k
        flags ^= 1;
240
185k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
184k
            s >> tx.vin[i].scriptWitness.stack;
242
184k
        }
243
1.00k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
4
            throw std::ios_base::failure("Superfluous witness record");
246
4
        }
247
1.00k
    }
248
3.03k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
5
        throw std::ios_base::failure("Unknown transaction optional data");
251
5
    }
252
3.03k
    s >> tx.nLockTime;
253
3.03k
}
_Z22UnserializeTransactionI12ParamsStreamIR8AutoFile20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
371k
{
218
371k
    const bool fAllowWitness = params.allow_witness;
219
220
371k
    s >> tx.version;
221
371k
    unsigned char flags = 0;
222
371k
    tx.vin.clear();
223
371k
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
371k
    s >> tx.vin;
226
371k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
70.3k
        s >> flags;
229
70.3k
        if (flags != 0) {
230
4.63k
            s >> tx.vin;
231
4.63k
            s >> tx.vout;
232
4.63k
        }
233
301k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
301k
        s >> tx.vout;
236
301k
    }
237
371k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
4.56k
        flags ^= 1;
240
24.9k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
20.3k
            s >> tx.vin[i].scriptWitness.stack;
242
20.3k
        }
243
4.56k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
10
            throw std::ios_base::failure("Superfluous witness record");
246
10
        }
247
4.56k
    }
248
371k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
47
        throw std::ios_base::failure("Unknown transaction optional data");
251
47
    }
252
371k
    s >> tx.nLockTime;
253
371k
}
_Z22UnserializeTransactionI12ParamsStreamIR12BufferedFile20TransactionSerParamsE19CMutableTransactionEvRT0_RT_RKS3_
Line
Count
Source
217
82.3k
{
218
82.3k
    const bool fAllowWitness = params.allow_witness;
219
220
82.3k
    s >> tx.version;
221
82.3k
    unsigned char flags = 0;
222
82.3k
    tx.vin.clear();
223
82.3k
    tx.vout.clear();
224
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
225
82.3k
    s >> tx.vin;
226
82.3k
    if (tx.vin.size() == 0 && fAllowWitness) {
227
        /* We read a dummy or an empty vin. */
228
68.2k
        s >> flags;
229
68.2k
        if (flags != 0) {
230
8.98k
            s >> tx.vin;
231
8.98k
            s >> tx.vout;
232
8.98k
        }
233
68.2k
    } else {
234
        /* We read a non-empty vin. Assume a normal vout follows. */
235
14.1k
        s >> tx.vout;
236
14.1k
    }
237
82.3k
    if ((flags & 1) && fAllowWitness) {
238
        /* The witness flag is present, and we support witnesses. */
239
5.45k
        flags ^= 1;
240
28.6k
        for (size_t i = 0; i < tx.vin.size(); i++) {
241
23.1k
            s >> tx.vin[i].scriptWitness.stack;
242
23.1k
        }
243
5.45k
        if (!tx.HasWitness()) {
244
            /* It's illegal to encode witnesses when all witness stacks are empty. */
245
1.28k
            throw std::ios_base::failure("Superfluous witness record");
246
1.28k
        }
247
5.45k
    }
248
81.1k
    if (flags) {
249
        /* Unknown flag in the serialization */
250
892
        throw std::ios_base::failure("Unknown transaction optional data");
251
892
    }
252
80.2k
    s >> tx.nLockTime;
253
80.2k
}
254
255
template<typename Stream, typename TxType>
256
void SerializeTransaction(const TxType& tx, Stream& s, const TransactionSerParams& params)
257
29.5M
{
258
29.5M
    const bool fAllowWitness = params.allow_witness;
259
260
29.5M
    s << tx.version;
261
29.5M
    unsigned char flags = 0;
262
    // Consistency check
263
29.5M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
9.89M
        if (tx.HasWitness()) {
266
4.00M
            flags |= 1;
267
4.00M
        }
268
9.89M
    }
269
29.5M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
4.00M
        std::vector<CTxIn> vinDummy;
272
4.00M
        s << vinDummy;
273
4.00M
        s << flags;
274
4.00M
    }
275
29.5M
    s << tx.vin;
276
29.5M
    s << tx.vout;
277
29.5M
    if (flags & 1) {
278
37.1M
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
33.1M
            s << tx.vin[i].scriptWitness.stack;
280
33.1M
        }
281
4.00M
    }
282
29.5M
    s << tx.nLockTime;
283
29.5M
}
_Z20SerializeTransactionI12ParamsStreamIR12SizeComputer20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
19.5M
{
258
19.5M
    const bool fAllowWitness = params.allow_witness;
259
260
19.5M
    s << tx.version;
261
19.5M
    unsigned char flags = 0;
262
    // Consistency check
263
19.5M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
7.71M
        if (tx.HasWitness()) {
266
2.10M
            flags |= 1;
267
2.10M
        }
268
7.71M
    }
269
19.5M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
2.10M
        std::vector<CTxIn> vinDummy;
272
2.10M
        s << vinDummy;
273
2.10M
        s << flags;
274
2.10M
    }
275
19.5M
    s << tx.vin;
276
19.5M
    s << tx.vout;
277
19.5M
    if (flags & 1) {
278
19.7M
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
17.6M
            s << tx.vin[i].scriptWitness.stack;
280
17.6M
        }
281
2.10M
    }
282
19.5M
    s << tx.nLockTime;
283
19.5M
}
_Z20SerializeTransactionI12ParamsStreamIR10DataStream20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
266k
{
258
266k
    const bool fAllowWitness = params.allow_witness;
259
260
266k
    s << tx.version;
261
266k
    unsigned char flags = 0;
262
    // Consistency check
263
266k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
266k
        if (tx.HasWitness()) {
266
3.81k
            flags |= 1;
267
3.81k
        }
268
266k
    }
269
266k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
3.81k
        std::vector<CTxIn> vinDummy;
272
3.81k
        s << vinDummy;
273
3.81k
        s << flags;
274
3.81k
    }
275
266k
    s << tx.vin;
276
266k
    s << tx.vout;
277
266k
    if (flags & 1) {
278
230k
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
226k
            s << tx.vin[i].scriptWitness.stack;
280
226k
        }
281
3.81k
    }
282
266k
    s << tx.nLockTime;
283
266k
}
_Z20SerializeTransactionI12ParamsStreamIR12SizeComputer20TransactionSerParamsE19CMutableTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
34.0k
{
258
34.0k
    const bool fAllowWitness = params.allow_witness;
259
260
34.0k
    s << tx.version;
261
34.0k
    unsigned char flags = 0;
262
    // Consistency check
263
34.0k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
0
        if (tx.HasWitness()) {
266
0
            flags |= 1;
267
0
        }
268
0
    }
269
34.0k
    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
34.0k
    s << tx.vin;
276
34.0k
    s << tx.vout;
277
34.0k
    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
34.0k
    s << tx.nLockTime;
283
34.0k
}
_Z20SerializeTransactionI12ParamsStreamIR10DataStream20TransactionSerParamsE19CMutableTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
37.8k
{
258
37.8k
    const bool fAllowWitness = params.allow_witness;
259
260
37.8k
    s << tx.version;
261
37.8k
    unsigned char flags = 0;
262
    // Consistency check
263
37.8k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
1.49k
        if (tx.HasWitness()) {
266
317
            flags |= 1;
267
317
        }
268
1.49k
    }
269
37.8k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
317
        std::vector<CTxIn> vinDummy;
272
317
        s << vinDummy;
273
317
        s << flags;
274
317
    }
275
37.8k
    s << tx.vin;
276
37.8k
    s << tx.vout;
277
37.8k
    if (flags & 1) {
278
5.76k
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
5.44k
            s << tx.vin[i].scriptWitness.stack;
280
5.44k
        }
281
317
    }
282
37.8k
    s << tx.nLockTime;
283
37.8k
}
_Z20SerializeTransactionI12ParamsStreamIR12VectorWriter20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
10.7k
{
258
10.7k
    const bool fAllowWitness = params.allow_witness;
259
260
10.7k
    s << tx.version;
261
10.7k
    unsigned char flags = 0;
262
    // Consistency check
263
10.7k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
8.18k
        if (tx.HasWitness()) {
266
261
            flags |= 1;
267
261
        }
268
8.18k
    }
269
10.7k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
261
        std::vector<CTxIn> vinDummy;
272
261
        s << vinDummy;
273
261
        s << flags;
274
261
    }
275
10.7k
    s << tx.vin;
276
10.7k
    s << tx.vout;
277
10.7k
    if (flags & 1) {
278
522
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
261
            s << tx.vin[i].scriptWitness.stack;
280
261
        }
281
261
    }
282
10.7k
    s << tx.nLockTime;
283
10.7k
}
_Z20SerializeTransactionI12ParamsStreamIRS0_IR12VectorWriter20TransactionSerParamsES3_E12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
3.13k
{
258
3.13k
    const bool fAllowWitness = params.allow_witness;
259
260
3.13k
    s << tx.version;
261
3.13k
    unsigned char flags = 0;
262
    // Consistency check
263
3.13k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
3.13k
        if (tx.HasWitness()) {
266
0
            flags |= 1;
267
0
        }
268
3.13k
    }
269
3.13k
    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
3.13k
    s << tx.vin;
276
3.13k
    s << tx.vout;
277
3.13k
    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
3.13k
    s << tx.nLockTime;
283
3.13k
}
_Z20SerializeTransactionI12ParamsStreamIR8AutoFile20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
72.4k
{
258
72.4k
    const bool fAllowWitness = params.allow_witness;
259
260
72.4k
    s << tx.version;
261
72.4k
    unsigned char flags = 0;
262
    // Consistency check
263
72.4k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
72.4k
        if (tx.HasWitness()) {
266
62.2k
            flags |= 1;
267
62.2k
        }
268
72.4k
    }
269
72.4k
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
62.2k
        std::vector<CTxIn> vinDummy;
272
62.2k
        s << vinDummy;
273
62.2k
        s << flags;
274
62.2k
    }
275
72.4k
    s << tx.vin;
276
72.4k
    s << tx.vout;
277
72.4k
    if (flags & 1) {
278
124k
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
62.2k
            s << tx.vin[i].scriptWitness.stack;
280
62.2k
        }
281
62.2k
    }
282
72.4k
    s << tx.nLockTime;
283
72.4k
}
_Z20SerializeTransactionI12ParamsStreamIR10HashWriter20TransactionSerParamsE19CMutableTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
734k
{
258
734k
    const bool fAllowWitness = params.allow_witness;
259
260
734k
    s << tx.version;
261
734k
    unsigned char flags = 0;
262
    // Consistency check
263
734k
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
0
        if (tx.HasWitness()) {
266
0
            flags |= 1;
267
0
        }
268
0
    }
269
734k
    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
734k
    s << tx.vin;
276
734k
    s << tx.vout;
277
734k
    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
734k
    s << tx.nLockTime;
283
734k
}
_Z20SerializeTransactionI12ParamsStreamIR10HashWriter20TransactionSerParamsE12CTransactionEvRKT0_RT_RKS3_
Line
Count
Source
257
8.90M
{
258
8.90M
    const bool fAllowWitness = params.allow_witness;
259
260
8.90M
    s << tx.version;
261
8.90M
    unsigned char flags = 0;
262
    // Consistency check
263
8.90M
    if (fAllowWitness) {
264
        /* Check whether witnesses need to be serialized. */
265
1.83M
        if (tx.HasWitness()) {
266
1.83M
            flags |= 1;
267
1.83M
        }
268
1.83M
    }
269
8.90M
    if (flags) {
270
        /* Use extended format in case witnesses are to be serialized. */
271
1.83M
        std::vector<CTxIn> vinDummy;
272
1.83M
        s << vinDummy;
273
1.83M
        s << flags;
274
1.83M
    }
275
8.90M
    s << tx.vin;
276
8.90M
    s << tx.vout;
277
8.90M
    if (flags & 1) {
278
16.9M
        for (size_t i = 0; i < tx.vin.size(); i++) {
279
15.1M
            s << tx.vin[i].scriptWitness.stack;
280
15.1M
        }
281
1.83M
    }
282
8.90M
    s << tx.nLockTime;
283
8.90M
}
284
285
template<typename TxType>
286
inline CAmount CalculateOutputValue(const TxType& tx)
287
71.1k
{
288
296k
    return std::accumulate(tx.vout.cbegin(), tx.vout.cend(), CAmount{0}, [](CAmount sum, const auto& txout) { return sum + txout.nValue; });
289
71.1k
}
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
28.7M
    inline void Serialize(Stream& s) const {
329
28.7M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
28.7M
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR12SizeComputer20TransactionSerParamsEEEvRT_
Line
Count
Source
328
19.5M
    inline void Serialize(Stream& s) const {
329
19.5M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
19.5M
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_
Line
Count
Source
328
266k
    inline void Serialize(Stream& s) const {
329
266k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
266k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR12VectorWriter20TransactionSerParamsEEEvRT_
Line
Count
Source
328
10.7k
    inline void Serialize(Stream& s) const {
329
10.7k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
10.7k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIRS1_IR12VectorWriter20TransactionSerParamsES4_EEEvRT_
Line
Count
Source
328
3.13k
    inline void Serialize(Stream& s) const {
329
3.13k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
3.13k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR8AutoFile20TransactionSerParamsEEEvRT_
Line
Count
Source
328
72.4k
    inline void Serialize(Stream& s) const {
329
72.4k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
72.4k
    }
_ZNK12CTransaction9SerializeI12ParamsStreamIR10HashWriter20TransactionSerParamsEEEvRT_
Line
Count
Source
328
8.90M
    inline void Serialize(Stream& s) const {
329
8.90M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
330
8.90M
    }
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
3.04k
    CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {}
336
    template <typename Stream>
337
2.95M
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR10DataStream20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
2.50M
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR8AutoFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
371k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
_ZN12CTransactionC2I12ParamsStreamIR12BufferedFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
337
82.3k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
338
339
1.32k
    bool IsNull() const {
340
1.32k
        return vin.empty() && vout.empty();
341
1.32k
    }
342
343
2.94G
    const Txid& GetHash() const LIFETIMEBOUND { return hash; }
344
87.7M
    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
13.0M
    {
358
13.0M
        return (vin.size() == 1 && vin[0].prevout.IsNull());
359
13.0M
    }
360
361
    friend bool operator==(const CTransaction& a, const CTransaction& b)
362
190
    {
363
190
        return a.hash == b.hash;
364
190
    }
365
366
    friend bool operator!=(const CTransaction& a, const CTransaction& b)
367
190
    {
368
190
        return a.hash != b.hash;
369
190
    }
370
371
    std::string ToString() const;
372
373
18.1M
    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
806k
    inline void Serialize(Stream& s) const {
389
806k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
806k
    }
_ZNK19CMutableTransaction9SerializeI12ParamsStreamIR12SizeComputer20TransactionSerParamsEEEvRT_
Line
Count
Source
388
34.0k
    inline void Serialize(Stream& s) const {
389
34.0k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
34.0k
    }
_ZNK19CMutableTransaction9SerializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_
Line
Count
Source
388
37.8k
    inline void Serialize(Stream& s) const {
389
37.8k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
37.8k
    }
_ZNK19CMutableTransaction9SerializeI12ParamsStreamIR10HashWriter20TransactionSerParamsEEEvRT_
Line
Count
Source
388
734k
    inline void Serialize(Stream& s) const {
389
734k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
390
734k
    }
391
392
    template <typename Stream>
393
3.36M
    inline void Unserialize(Stream& s) {
394
3.36M
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
3.36M
    }
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR10DataStream20TransactionSerParamsEEEvRT_
Line
Count
Source
393
2.90M
    inline void Unserialize(Stream& s) {
394
2.90M
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
2.90M
    }
Unexecuted instantiation: _ZN19CMutableTransaction11UnserializeI12ParamsStreamIR10SpanReader20TransactionSerParamsEEEvRT_
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR8AutoFile20TransactionSerParamsEEEvRT_
Line
Count
Source
393
371k
    inline void Unserialize(Stream& s) {
394
371k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
371k
    }
_ZN19CMutableTransaction11UnserializeI12ParamsStreamIR12BufferedFile20TransactionSerParamsEEEvRT_
Line
Count
Source
393
82.3k
    inline void Unserialize(Stream& s) {
394
82.3k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
395
82.3k
    }
396
397
    template <typename Stream>
398
3.04k
    CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) {
399
3.04k
        UnserializeTransaction(*this, s, params);
400
3.04k
    }
401
402
    template <typename Stream>
403
2.95M
    CMutableTransaction(deserialize_type, Stream& s) {
404
2.95M
        Unserialize(s);
405
2.95M
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR10DataStream20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
2.50M
    CMutableTransaction(deserialize_type, Stream& s) {
404
2.50M
        Unserialize(s);
405
2.50M
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR8AutoFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
371k
    CMutableTransaction(deserialize_type, Stream& s) {
404
371k
        Unserialize(s);
405
371k
    }
_ZN19CMutableTransactionC2I12ParamsStreamIR12BufferedFile20TransactionSerParamsEEE16deserialize_typeRT_
Line
Count
Source
403
82.3k
    CMutableTransaction(deserialize_type, Stream& s) {
404
82.3k
        Unserialize(s);
405
82.3k
    }
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
64.5k
    {
414
251k
        for (size_t i = 0; i < vin.size(); i++) {
415
248k
            if (!vin[i].scriptWitness.IsNull()) {
416
61.6k
                return true;
417
61.6k
            }
418
248k
        }
419
2.95k
        return false;
420
64.5k
    }
421
};
422
423
typedef std::shared_ptr<const CTransaction> CTransactionRef;
424
3.88M
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
144k
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
11.0k
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
664k
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
911k
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
78.2k
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
156k
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
9.68k
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
97.3k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
notifications.cpp:_ZL18MakeTransactionRefIR19CMutableTransactionESt10shared_ptrIK12CTransactionEOT_
Line
Count
Source
424
57.3k
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
96.0k
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.18M
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.44k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
wallet.cpp:_ZL18MakeTransactionRefIRK12CTransactionESt10shared_ptrIS1_EOT_
Line
Count
Source
424
84.3k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
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
72.6k
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
79.5k
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.28k
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
230k
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
425
426
/** A generic txid reference (txid or wtxid). */
427
class GenTxid
428
{
429
    bool m_is_wtxid;
430
    uint256 m_hash;
431
9.87M
    GenTxid(bool is_wtxid, const uint256& hash) : m_is_wtxid(is_wtxid), m_hash(hash) {}
432
433
public:
434
8.27M
    static GenTxid Txid(const uint256& hash) { return GenTxid{false, hash}; }
435
1.59M
    static GenTxid Wtxid(const uint256& hash) { return GenTxid{true, hash}; }
436
12.5M
    bool IsWtxid() const { return m_is_wtxid; }
437
13.2M
    const uint256& GetHash() const LIFETIMEBOUND { return m_hash; }
438
44.0k
    friend bool operator==(const GenTxid& a, const GenTxid& b) { return a.m_is_wtxid == b.m_is_wtxid && a.m_hash == b.m_hash; }
439
39.7k
    friend bool operator<(const GenTxid& a, const GenTxid& b) { return std::tie(a.m_is_wtxid, a.m_hash) < std::tie(b.m_is_wtxid, b.m_hash); }
440
};
441
442
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H