Coverage Report

Created: 2026-07-14 18:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/primitives/transaction.h
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_PRIMITIVES_TRANSACTION_H
7
#define BITCOIN_PRIMITIVES_TRANSACTION_H
8
9
#include <attributes.h>
10
#include <consensus/amount.h>
11
#include <primitives/transaction_identifier.h> // IWYU pragma: export
12
#include <script/script.h>
13
#include <serialize.h>
14
15
#include <compare>
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
8.10M
    COutPoint(): n(NULL_INDEX) { }
37
46.4M
    COutPoint(const Txid& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }
38
39
48.6M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<SizeComputer&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<SizeComputer&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
39
35.1M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
Unexecuted instantiation: void COutPoint::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionUnserialize)
void COutPoint::SerializationOps<HashWriter, COutPoint const, ActionSerialize>(COutPoint const&, HashWriter&, ActionSerialize)
Line
Count
Source
39
547k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<DataStream, COutPoint const, ActionSerialize>(COutPoint const&, DataStream&, ActionSerialize)
Line
Count
Source
39
39.4k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<VectorWriter&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<VectorWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
39
92.4k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<DataStream&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
39
3.68M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<SpanReader&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<SpanReader&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
39
432k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
39
576k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
void COutPoint::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
39
255k
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
Unexecuted instantiation: void COutPoint::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<DataStream&, TransactionSerParams>&, ActionSerialize)
Unexecuted instantiation: void COutPoint::SerializationOps<DataStream, COutPoint, ActionUnserialize>(COutPoint&, DataStream&, ActionUnserialize)
Unexecuted instantiation: void COutPoint::SerializationOps<ParamsStream<BufferedFile&, TransactionSerParams>, COutPoint, ActionUnserialize>(COutPoint&, ParamsStream<BufferedFile&, TransactionSerParams>&, ActionUnserialize)
void COutPoint::SerializationOps<ParamsStream<HashWriter&, TransactionSerParams>, COutPoint const, ActionSerialize>(COutPoint const&, ParamsStream<HashWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
39
7.92M
    SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
40
41
0
    void SetNull() { hash.SetNull(); n = NULL_INDEX; }
42
57.0M
    bool IsNull() const { return (hash.IsNull() && n == NULL_INDEX); }
  Branch (42:35): [True: 750k, False: 56.3M]
  Branch (42:52): [True: 738k, False: 11.3k]
43
44
    friend bool operator<(const COutPoint& a, const COutPoint& b)
45
231M
    {
46
231M
        return std::tie(a.hash, a.n) < std::tie(b.hash, b.n);
47
231M
    }
48
49
    friend bool operator==(const COutPoint& a, const COutPoint& b)
50
81.7M
    {
51
81.7M
        return (a.hash == b.hash && a.n == b.n);
  Branch (51:17): [True: 68.1M, False: 13.6M]
  Branch (51:37): [True: 67.8M, False: 249k]
52
81.7M
    }
53
54
    std::string ToString() const;
55
};
56
57
/** An input of a transaction.  It contains the location of the previous
58
 * transaction's output that it claims and a signature that matches the
59
 * output's public key.
60
 */
61
class CTxIn
62
{
63
public:
64
    COutPoint prevout;
65
    CScript scriptSig;
66
    uint32_t nSequence;
67
    CScriptWitness scriptWitness; //!< Only serialized through CTransaction
68
69
    /**
70
     * Setting nSequence to this value for every input in a transaction
71
     * disables nLockTime/IsFinalTx().
72
     * It fails OP_CHECKLOCKTIMEVERIFY/CheckLockTime() for any input that has
73
     * it set (BIP 65).
74
     * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
75
     */
76
    static const uint32_t SEQUENCE_FINAL = 0xffffffff;
77
    /**
78
     * This is the maximum sequence number that enables both nLockTime and
79
     * OP_CHECKLOCKTIMEVERIFY (BIP 65).
80
     * It has SEQUENCE_LOCKTIME_DISABLE_FLAG set (BIP 68/112).
81
     */
82
    static const uint32_t MAX_SEQUENCE_NONFINAL{SEQUENCE_FINAL - 1};
83
84
    // Below flags apply in the context of BIP 68. BIP 68 requires the tx
85
    // version to be set to 2, or higher.
86
    /**
87
     * If this flag is set, CTxIn::nSequence is NOT interpreted as a
88
     * relative lock-time.
89
     * It skips SequenceLocks() for any input that has it set (BIP 68).
90
     * It fails OP_CHECKSEQUENCEVERIFY/CheckSequence() for any input that has
91
     * it set (BIP 112).
92
     */
93
    static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1U << 31);
94
95
    /**
96
     * If CTxIn::nSequence encodes a relative lock-time and this flag
97
     * is set, the relative lock-time has units of 512 seconds,
98
     * otherwise it specifies blocks with a granularity of 1. */
99
    static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
100
101
    /**
102
     * If CTxIn::nSequence encodes a relative lock-time, this mask is
103
     * applied to extract that lock-time from the sequence field. */
104
    static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
105
106
    /**
107
     * In order to use the same number of bits to encode roughly the
108
     * same wall-clock duration, and because blocks are naturally
109
     * limited to occur every 600s on average, the minimum granularity
110
     * for time-based relative lock-time is fixed at 512 seconds.
111
     * Converting from CTxIn::nSequence to seconds is performed by
112
     * multiplying by 512 = 2^9, or equivalently shifting up by
113
     * 9 bits. */
114
    static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
115
116
    CTxIn()
117
4.11M
    {
118
4.11M
        nSequence = SEQUENCE_FINAL;
119
4.11M
    }
120
121
    explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
122
    CTxIn(Txid hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
123
124
48.0M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<SizeComputer&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<SizeComputer&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
124
35.1M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
Unexecuted instantiation: void CTxIn::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionUnserialize)
void CTxIn::SerializationOps<ParamsStream<VectorWriter&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<VectorWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
124
92.4k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<DataStream&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
124
3.68M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<SpanReader&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<SpanReader&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
124
432k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
124
576k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
void CTxIn::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
124
255k
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
Unexecuted instantiation: void CTxIn::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<DataStream&, TransactionSerParams>&, ActionSerialize)
Unexecuted instantiation: void CTxIn::SerializationOps<ParamsStream<BufferedFile&, TransactionSerParams>, CTxIn, ActionUnserialize>(CTxIn&, ParamsStream<BufferedFile&, TransactionSerParams>&, ActionUnserialize)
void CTxIn::SerializationOps<ParamsStream<HashWriter&, TransactionSerParams>, CTxIn const, ActionSerialize>(CTxIn const&, ParamsStream<HashWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
124
7.92M
    SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
125
126
    friend bool operator==(const CTxIn& a, const CTxIn& b)
127
0
    {
128
0
        return (a.prevout   == b.prevout &&
129
0
                a.scriptSig == b.scriptSig &&
130
0
                a.nSequence == b.nSequence);
131
0
    }
132
133
    std::string ToString() const;
134
};
135
136
/** An output of a transaction.  It contains the public key that the next input
137
 * must be able to sign with to claim it.
138
 */
139
class CTxOut
140
{
141
public:
142
    CAmount nValue;
143
    CScript scriptPubKey;
144
145
    CTxOut()
146
32.5M
    {
147
32.5M
        SetNull();
148
32.5M
    }
149
150
    CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);
151
152
54.8M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<SizeComputer&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<SizeComputer&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
152
35.7M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: void CTxOut::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionUnserialize)
void CTxOut::SerializationOps<HashWriter, CTxOut const, ActionSerialize>(CTxOut const&, HashWriter&, ActionSerialize)
Line
Count
Source
152
592k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: void CTxOut::SerializationOps<DataStream, CTxOut const, ActionSerialize>(CTxOut const&, DataStream&, ActionSerialize)
void CTxOut::SerializationOps<ParamsStream<VectorWriter&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<VectorWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
152
185k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<DataStream&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
152
4.31M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<SpanReader&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<SpanReader&, TransactionSerParams>&, ActionUnserialize)
Line
Count
Source
152
593k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
152
758k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
void CTxOut::SerializationOps<ParamsStream<AutoFile&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<AutoFile&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
152
275k
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: void CTxOut::SerializationOps<ParamsStream<DataStream&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<DataStream&, TransactionSerParams>&, ActionSerialize)
void CTxOut::SerializationOps<SizeComputer, CTxOut const, ActionSerialize>(CTxOut const&, SizeComputer&, ActionSerialize)
Line
Count
Source
152
2.89M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
Unexecuted instantiation: void CTxOut::SerializationOps<ParamsStream<BufferedFile&, TransactionSerParams>, CTxOut, ActionUnserialize>(CTxOut&, ParamsStream<BufferedFile&, TransactionSerParams>&, ActionUnserialize)
Unexecuted instantiation: void CTxOut::SerializationOps<SpanReader, CTxOut, ActionUnserialize>(CTxOut&, SpanReader&, ActionUnserialize)
void CTxOut::SerializationOps<ParamsStream<HashWriter&, TransactionSerParams>, CTxOut const, ActionSerialize>(CTxOut const&, ParamsStream<HashWriter&, TransactionSerParams>&, ActionSerialize)
Line
Count
Source
152
9.49M
    SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
153
154
    void SetNull()
155
34.6M
    {
156
34.6M
        nValue = -1;
157
34.6M
        scriptPubKey.clear();
158
34.6M
    }
159
160
    bool IsNull() const
161
157M
    {
162
157M
        return (nValue == -1);
163
157M
    }
164
165
    friend bool operator==(const CTxOut& a, const CTxOut& b)
166
537k
    {
167
537k
        return (a.nValue       == b.nValue &&
  Branch (167:17): [True: 537k, False: 0]
168
537k
                a.scriptPubKey == b.scriptPubKey);
  Branch (168:17): [True: 537k, False: 0]
169
537k
    }
170
171
    std::string ToString() const;
172
};
173
174
struct CMutableTransaction;
175
176
struct TransactionSerParams {
177
    const bool allow_witness;
178
    SER_PARAMS_OPFUNC
179
};
180
static constexpr TransactionSerParams TX_WITH_WITNESS{.allow_witness = true};
181
static constexpr TransactionSerParams TX_NO_WITNESS{.allow_witness = false};
182
183
/**
184
 * Basic transaction serialization format:
185
 * - uint32_t version
186
 * - std::vector<CTxIn> vin
187
 * - std::vector<CTxOut> vout
188
 * - uint32_t nLockTime
189
 *
190
 * Extended transaction serialization format:
191
 * - uint32_t version
192
 * - unsigned char dummy = 0x00
193
 * - unsigned char flags (!= 0)
194
 * - std::vector<CTxIn> vin
195
 * - std::vector<CTxOut> vout
196
 * - if (flags & 1):
197
 *   - CScriptWitness scriptWitness; (deserialized into CTxIn)
198
 * - uint32_t nLockTime
199
 */
200
template<typename Stream, typename TxType>
201
void UnserializeTransaction(TxType& tx, Stream& s, const TransactionSerParams& params)
202
3.74M
{
203
3.74M
    const bool fAllowWitness = params.allow_witness;
204
205
3.74M
    s >> tx.version;
206
3.74M
    unsigned char flags = 0;
207
3.74M
    tx.vin.clear();
208
3.74M
    tx.vout.clear();
209
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
210
3.74M
    s >> tx.vin;
211
3.74M
    if (tx.vin.size() == 0 && fAllowWitness) {
  Branch (211:9): [True: 0, False: 0]
  Branch (211:31): [True: 0, False: 0]
  Branch (211:9): [True: 3.07M, False: 265k]
  Branch (211:31): [True: 3.07M, False: 0]
  Branch (211:9): [True: 382k, False: 16.9k]
  Branch (211:31): [True: 382k, False: 0]
  Branch (211:9): [True: 0, False: 0]
  Branch (211:31): [True: 0, False: 0]
212
        /* We read a dummy or an empty vin. */
213
3.45M
        s >> flags;
214
3.45M
        if (flags != 0) {
  Branch (214:13): [True: 0, False: 0]
  Branch (214:13): [True: 3.07M, False: 70]
  Branch (214:13): [True: 382k, False: 0]
  Branch (214:13): [True: 0, False: 0]
215
3.45M
            s >> tx.vin;
216
3.45M
            s >> tx.vout;
217
3.45M
        }
218
3.45M
    } else {
219
        /* We read a non-empty vin. Assume a normal vout follows. */
220
282k
        s >> tx.vout;
221
282k
    }
222
3.74M
    if ((flags & 1) && fAllowWitness) {
  Branch (222:9): [True: 0, False: 0]
  Branch (222:24): [True: 0, False: 0]
  Branch (222:9): [True: 3.07M, False: 265k]
  Branch (222:24): [True: 3.07M, False: 0]
  Branch (222:9): [True: 382k, False: 16.9k]
  Branch (222:24): [True: 382k, False: 0]
  Branch (222:9): [True: 0, False: 0]
  Branch (222:24): [True: 0, False: 0]
223
        /* The witness flag is present, and we support witnesses. */
224
3.45M
        flags ^= 1;
225
7.27M
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (225:28): [True: 0, False: 0]
  Branch (225:28): [True: 3.40M, False: 3.07M]
  Branch (225:28): [True: 415k, False: 382k]
  Branch (225:28): [True: 0, False: 0]
226
3.81M
            s >> tx.vin[i].scriptWitness.stack;
227
3.81M
        }
228
3.45M
        if (!tx.HasWitness()) {
  Branch (228:13): [True: 0, False: 0]
  Branch (228:13): [True: 5.52k, False: 3.07M]
  Branch (228:13): [True: 0, False: 382k]
  Branch (228:13): [True: 0, False: 0]
229
            /* It's illegal to encode witnesses when all witness stacks are empty. */
230
5.52k
            throw std::ios_base::failure("Superfluous witness record");
231
5.52k
        }
232
3.45M
    }
233
3.73M
    if (flags) {
  Branch (233:9): [True: 0, False: 0]
  Branch (233:9): [True: 32, False: 3.33M]
  Branch (233:9): [True: 0, False: 399k]
  Branch (233:9): [True: 0, False: 0]
234
        /* Unknown flag in the serialization */
235
32
        throw std::ios_base::failure("Unknown transaction optional data");
236
32
    }
237
3.73M
    s >> tx.nLockTime;
238
3.73M
}
Unexecuted instantiation: void UnserializeTransaction<ParamsStream<AutoFile&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<AutoFile&, TransactionSerParams>&, TransactionSerParams const&)
void UnserializeTransaction<ParamsStream<DataStream&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<DataStream&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
202
3.34M
{
203
3.34M
    const bool fAllowWitness = params.allow_witness;
204
205
3.34M
    s >> tx.version;
206
3.34M
    unsigned char flags = 0;
207
3.34M
    tx.vin.clear();
208
3.34M
    tx.vout.clear();
209
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
210
3.34M
    s >> tx.vin;
211
3.34M
    if (tx.vin.size() == 0 && fAllowWitness) {
  Branch (211:9): [True: 3.07M, False: 265k]
  Branch (211:31): [True: 3.07M, False: 0]
212
        /* We read a dummy or an empty vin. */
213
3.07M
        s >> flags;
214
3.07M
        if (flags != 0) {
  Branch (214:13): [True: 3.07M, False: 70]
215
3.07M
            s >> tx.vin;
216
3.07M
            s >> tx.vout;
217
3.07M
        }
218
3.07M
    } else {
219
        /* We read a non-empty vin. Assume a normal vout follows. */
220
265k
        s >> tx.vout;
221
265k
    }
222
3.34M
    if ((flags & 1) && fAllowWitness) {
  Branch (222:9): [True: 3.07M, False: 265k]
  Branch (222:24): [True: 3.07M, False: 0]
223
        /* The witness flag is present, and we support witnesses. */
224
3.07M
        flags ^= 1;
225
6.47M
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (225:28): [True: 3.40M, False: 3.07M]
226
3.40M
            s >> tx.vin[i].scriptWitness.stack;
227
3.40M
        }
228
3.07M
        if (!tx.HasWitness()) {
  Branch (228:13): [True: 5.52k, False: 3.07M]
229
            /* It's illegal to encode witnesses when all witness stacks are empty. */
230
5.52k
            throw std::ios_base::failure("Superfluous witness record");
231
5.52k
        }
232
3.07M
    }
233
3.33M
    if (flags) {
  Branch (233:9): [True: 32, False: 3.33M]
234
        /* Unknown flag in the serialization */
235
32
        throw std::ios_base::failure("Unknown transaction optional data");
236
32
    }
237
3.33M
    s >> tx.nLockTime;
238
3.33M
}
void UnserializeTransaction<ParamsStream<SpanReader&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<SpanReader&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
202
399k
{
203
399k
    const bool fAllowWitness = params.allow_witness;
204
205
399k
    s >> tx.version;
206
399k
    unsigned char flags = 0;
207
399k
    tx.vin.clear();
208
399k
    tx.vout.clear();
209
    /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
210
399k
    s >> tx.vin;
211
399k
    if (tx.vin.size() == 0 && fAllowWitness) {
  Branch (211:9): [True: 382k, False: 16.9k]
  Branch (211:31): [True: 382k, False: 0]
212
        /* We read a dummy or an empty vin. */
213
382k
        s >> flags;
214
382k
        if (flags != 0) {
  Branch (214:13): [True: 382k, False: 0]
215
382k
            s >> tx.vin;
216
382k
            s >> tx.vout;
217
382k
        }
218
382k
    } else {
219
        /* We read a non-empty vin. Assume a normal vout follows. */
220
16.9k
        s >> tx.vout;
221
16.9k
    }
222
399k
    if ((flags & 1) && fAllowWitness) {
  Branch (222:9): [True: 382k, False: 16.9k]
  Branch (222:24): [True: 382k, False: 0]
223
        /* The witness flag is present, and we support witnesses. */
224
382k
        flags ^= 1;
225
797k
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (225:28): [True: 415k, False: 382k]
226
415k
            s >> tx.vin[i].scriptWitness.stack;
227
415k
        }
228
382k
        if (!tx.HasWitness()) {
  Branch (228:13): [True: 0, False: 382k]
229
            /* It's illegal to encode witnesses when all witness stacks are empty. */
230
0
            throw std::ios_base::failure("Superfluous witness record");
231
0
        }
232
382k
    }
233
399k
    if (flags) {
  Branch (233:9): [True: 0, False: 399k]
234
        /* Unknown flag in the serialization */
235
0
        throw std::ios_base::failure("Unknown transaction optional data");
236
0
    }
237
399k
    s >> tx.nLockTime;
238
399k
}
Unexecuted instantiation: void UnserializeTransaction<ParamsStream<BufferedFile&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction&, ParamsStream<BufferedFile&, TransactionSerParams>&, TransactionSerParams const&)
239
240
template<typename Stream, typename TxType>
241
void SerializeTransaction(const TxType& tx, Stream& s, const TransactionSerParams& params)
242
39.5M
{
243
39.5M
    const bool fAllowWitness = params.allow_witness;
244
245
39.5M
    s << tx.version;
246
39.5M
    unsigned char flags = 0;
247
    // Consistency check
248
39.5M
    if (fAllowWitness) {
  Branch (248:9): [True: 12.9M, False: 18.5M]
  Branch (248:9): [True: 80.9k, False: 5.15k]
  Branch (248:9): [True: 528k, False: 0]
  Branch (248:9): [True: 246k, False: 0]
  Branch (248:9): [True: 0, False: 0]
  Branch (248:9): [True: 0, False: 0]
  Branch (248:9): [True: 0, False: 0]
  Branch (248:9): [True: 0, False: 0]
  Branch (248:9): [True: 3.45M, False: 3.73M]
249
        /* Check whether witnesses need to be serialized. */
250
17.2M
        if (tx.HasWitness()) {
  Branch (250:13): [True: 11.6M, False: 1.28M]
  Branch (250:13): [True: 77.5k, False: 3.38k]
  Branch (250:13): [True: 501k, False: 27.0k]
  Branch (250:13): [True: 242k, False: 3.86k]
  Branch (250:13): [True: 0, False: 0]
  Branch (250:13): [True: 0, False: 0]
  Branch (250:13): [True: 0, False: 0]
  Branch (250:13): [True: 0, False: 0]
  Branch (250:13): [True: 3.45M, False: 0]
251
15.9M
            flags |= 1;
252
15.9M
        }
253
17.2M
    }
254
39.5M
    if (flags) {
  Branch (254:9): [True: 11.6M, False: 19.8M]
  Branch (254:9): [True: 77.5k, False: 8.53k]
  Branch (254:9): [True: 501k, False: 27.0k]
  Branch (254:9): [True: 242k, False: 3.86k]
  Branch (254:9): [True: 0, False: 0]
  Branch (254:9): [True: 0, False: 0]
  Branch (254:9): [True: 0, False: 0]
  Branch (254:9): [True: 0, False: 0]
  Branch (254:9): [True: 3.45M, False: 3.73M]
255
        /* Use extended format in case witnesses are to be serialized. */
256
15.9M
        std::vector<CTxIn> vinDummy;
257
15.9M
        s << vinDummy;
258
15.9M
        s << flags;
259
15.9M
    }
260
39.5M
    s << tx.vin;
261
39.5M
    s << tx.vout;
262
39.5M
    if (flags & 1) {
  Branch (262:9): [True: 11.6M, False: 19.8M]
  Branch (262:9): [True: 77.5k, False: 8.53k]
  Branch (262:9): [True: 501k, False: 27.0k]
  Branch (262:9): [True: 242k, False: 3.86k]
  Branch (262:9): [True: 0, False: 0]
  Branch (262:9): [True: 0, False: 0]
  Branch (262:9): [True: 0, False: 0]
  Branch (262:9): [True: 0, False: 0]
  Branch (262:9): [True: 3.45M, False: 3.73M]
263
33.7M
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (263:28): [True: 13.0M, False: 11.6M]
  Branch (263:28): [True: 83.7k, False: 77.5k]
  Branch (263:28): [True: 548k, False: 501k]
  Branch (263:28): [True: 251k, False: 242k]
  Branch (263:28): [True: 0, False: 0]
  Branch (263:28): [True: 0, False: 0]
  Branch (263:28): [True: 0, False: 0]
  Branch (263:28): [True: 0, False: 0]
  Branch (263:28): [True: 3.81M, False: 3.45M]
264
17.7M
            s << tx.vin[i].scriptWitness.stack;
265
17.7M
        }
266
15.9M
    }
267
39.5M
    s << tx.nLockTime;
268
39.5M
}
void SerializeTransaction<ParamsStream<SizeComputer&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<SizeComputer&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
242
31.4M
{
243
31.4M
    const bool fAllowWitness = params.allow_witness;
244
245
31.4M
    s << tx.version;
246
31.4M
    unsigned char flags = 0;
247
    // Consistency check
248
31.4M
    if (fAllowWitness) {
  Branch (248:9): [True: 12.9M, False: 18.5M]
249
        /* Check whether witnesses need to be serialized. */
250
12.9M
        if (tx.HasWitness()) {
  Branch (250:13): [True: 11.6M, False: 1.28M]
251
11.6M
            flags |= 1;
252
11.6M
        }
253
12.9M
    }
254
31.4M
    if (flags) {
  Branch (254:9): [True: 11.6M, False: 19.8M]
255
        /* Use extended format in case witnesses are to be serialized. */
256
11.6M
        std::vector<CTxIn> vinDummy;
257
11.6M
        s << vinDummy;
258
11.6M
        s << flags;
259
11.6M
    }
260
31.4M
    s << tx.vin;
261
31.4M
    s << tx.vout;
262
31.4M
    if (flags & 1) {
  Branch (262:9): [True: 11.6M, False: 19.8M]
263
24.7M
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (263:28): [True: 13.0M, False: 11.6M]
264
13.0M
            s << tx.vin[i].scriptWitness.stack;
265
13.0M
        }
266
11.6M
    }
267
31.4M
    s << tx.nLockTime;
268
31.4M
}
void SerializeTransaction<ParamsStream<VectorWriter&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<VectorWriter&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
242
86.0k
{
243
86.0k
    const bool fAllowWitness = params.allow_witness;
244
245
86.0k
    s << tx.version;
246
86.0k
    unsigned char flags = 0;
247
    // Consistency check
248
86.0k
    if (fAllowWitness) {
  Branch (248:9): [True: 80.9k, False: 5.15k]
249
        /* Check whether witnesses need to be serialized. */
250
80.9k
        if (tx.HasWitness()) {
  Branch (250:13): [True: 77.5k, False: 3.38k]
251
77.5k
            flags |= 1;
252
77.5k
        }
253
80.9k
    }
254
86.0k
    if (flags) {
  Branch (254:9): [True: 77.5k, False: 8.53k]
255
        /* Use extended format in case witnesses are to be serialized. */
256
77.5k
        std::vector<CTxIn> vinDummy;
257
77.5k
        s << vinDummy;
258
77.5k
        s << flags;
259
77.5k
    }
260
86.0k
    s << tx.vin;
261
86.0k
    s << tx.vout;
262
86.0k
    if (flags & 1) {
  Branch (262:9): [True: 77.5k, False: 8.53k]
263
161k
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (263:28): [True: 83.7k, False: 77.5k]
264
83.7k
            s << tx.vin[i].scriptWitness.stack;
265
83.7k
        }
266
77.5k
    }
267
86.0k
    s << tx.nLockTime;
268
86.0k
}
void SerializeTransaction<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
242
528k
{
243
528k
    const bool fAllowWitness = params.allow_witness;
244
245
528k
    s << tx.version;
246
528k
    unsigned char flags = 0;
247
    // Consistency check
248
528k
    if (fAllowWitness) {
  Branch (248:9): [True: 528k, False: 0]
249
        /* Check whether witnesses need to be serialized. */
250
528k
        if (tx.HasWitness()) {
  Branch (250:13): [True: 501k, False: 27.0k]
251
501k
            flags |= 1;
252
501k
        }
253
528k
    }
254
528k
    if (flags) {
  Branch (254:9): [True: 501k, False: 27.0k]
255
        /* Use extended format in case witnesses are to be serialized. */
256
501k
        std::vector<CTxIn> vinDummy;
257
501k
        s << vinDummy;
258
501k
        s << flags;
259
501k
    }
260
528k
    s << tx.vin;
261
528k
    s << tx.vout;
262
528k
    if (flags & 1) {
  Branch (262:9): [True: 501k, False: 27.0k]
263
1.05M
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (263:28): [True: 548k, False: 501k]
264
548k
            s << tx.vin[i].scriptWitness.stack;
265
548k
        }
266
501k
    }
267
528k
    s << tx.nLockTime;
268
528k
}
void SerializeTransaction<ParamsStream<AutoFile&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<AutoFile&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
242
246k
{
243
246k
    const bool fAllowWitness = params.allow_witness;
244
245
246k
    s << tx.version;
246
246k
    unsigned char flags = 0;
247
    // Consistency check
248
246k
    if (fAllowWitness) {
  Branch (248:9): [True: 246k, False: 0]
249
        /* Check whether witnesses need to be serialized. */
250
246k
        if (tx.HasWitness()) {
  Branch (250:13): [True: 242k, False: 3.86k]
251
242k
            flags |= 1;
252
242k
        }
253
246k
    }
254
246k
    if (flags) {
  Branch (254:9): [True: 242k, False: 3.86k]
255
        /* Use extended format in case witnesses are to be serialized. */
256
242k
        std::vector<CTxIn> vinDummy;
257
242k
        s << vinDummy;
258
242k
        s << flags;
259
242k
    }
260
246k
    s << tx.vin;
261
246k
    s << tx.vout;
262
246k
    if (flags & 1) {
  Branch (262:9): [True: 242k, False: 3.86k]
263
493k
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (263:28): [True: 251k, False: 242k]
264
251k
            s << tx.vin[i].scriptWitness.stack;
265
251k
        }
266
242k
    }
267
246k
    s << tx.nLockTime;
268
246k
}
Unexecuted instantiation: void SerializeTransaction<ParamsStream<DataStream&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<DataStream&, TransactionSerParams>&, TransactionSerParams const&)
Unexecuted instantiation: void SerializeTransaction<ParamsStream<SizeComputer&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction const&, ParamsStream<SizeComputer&, TransactionSerParams>&, TransactionSerParams const&)
Unexecuted instantiation: void SerializeTransaction<ParamsStream<DataStream&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction const&, ParamsStream<DataStream&, TransactionSerParams>&, TransactionSerParams const&)
Unexecuted instantiation: void SerializeTransaction<ParamsStream<HashWriter&, TransactionSerParams>, CMutableTransaction>(CMutableTransaction const&, ParamsStream<HashWriter&, TransactionSerParams>&, TransactionSerParams const&)
void SerializeTransaction<ParamsStream<HashWriter&, TransactionSerParams>, CTransaction>(CTransaction const&, ParamsStream<HashWriter&, TransactionSerParams>&, TransactionSerParams const&)
Line
Count
Source
242
7.18M
{
243
7.18M
    const bool fAllowWitness = params.allow_witness;
244
245
7.18M
    s << tx.version;
246
7.18M
    unsigned char flags = 0;
247
    // Consistency check
248
7.18M
    if (fAllowWitness) {
  Branch (248:9): [True: 3.45M, False: 3.73M]
249
        /* Check whether witnesses need to be serialized. */
250
3.45M
        if (tx.HasWitness()) {
  Branch (250:13): [True: 3.45M, False: 0]
251
3.45M
            flags |= 1;
252
3.45M
        }
253
3.45M
    }
254
7.18M
    if (flags) {
  Branch (254:9): [True: 3.45M, False: 3.73M]
255
        /* Use extended format in case witnesses are to be serialized. */
256
3.45M
        std::vector<CTxIn> vinDummy;
257
3.45M
        s << vinDummy;
258
3.45M
        s << flags;
259
3.45M
    }
260
7.18M
    s << tx.vin;
261
7.18M
    s << tx.vout;
262
7.18M
    if (flags & 1) {
  Branch (262:9): [True: 3.45M, False: 3.73M]
263
7.26M
        for (size_t i = 0; i < tx.vin.size(); i++) {
  Branch (263:28): [True: 3.81M, False: 3.45M]
264
3.81M
            s << tx.vin[i].scriptWitness.stack;
265
3.81M
        }
266
3.45M
    }
267
7.18M
    s << tx.nLockTime;
268
7.18M
}
269
270
template<typename TxType>
271
inline CAmount CalculateOutputValue(const TxType& tx)
272
0
{
273
0
    return std::accumulate(tx.vout.cbegin(), tx.vout.cend(), CAmount{0}, [](CAmount sum, const auto& txout) { return sum + txout.nValue; });
274
0
}
275
276
277
/** The basic transaction that is broadcasted on the network and contained in
278
 * blocks.  A transaction can contain multiple inputs and outputs.
279
 */
280
class CTransaction
281
{
282
public:
283
    // Default transaction version.
284
    static const uint32_t CURRENT_VERSION{2};
285
286
    // The local variables are made const to prevent unintended modification
287
    // without updating the cached hash value. However, CTransaction is not
288
    // actually immutable; deserialization and assignment are implemented,
289
    // and bypass the constness. This is safe, as they update the entire
290
    // structure, including the hash.
291
    const std::vector<CTxIn> vin;
292
    const std::vector<CTxOut> vout;
293
    const uint32_t version;
294
    const uint32_t nLockTime;
295
296
private:
297
    /** Memory only. */
298
    const bool m_has_witness;
299
    const Txid hash;
300
    const Wtxid m_witness_hash;
301
302
    Txid ComputeHash() const;
303
    Wtxid ComputeWitnessHash() const;
304
305
    bool ComputeHasWitness() const;
306
307
public:
308
    /** Convert a CMutableTransaction into a CTransaction. */
309
    explicit CTransaction(const CMutableTransaction& tx);
310
    explicit CTransaction(CMutableTransaction&& tx);
311
312
    template <typename Stream>
313
39.5M
    inline void Serialize(Stream& s) const {
314
39.5M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
315
39.5M
    }
void CTransaction::Serialize<ParamsStream<SizeComputer&, TransactionSerParams> >(ParamsStream<SizeComputer&, TransactionSerParams>&) const
Line
Count
Source
313
31.4M
    inline void Serialize(Stream& s) const {
314
31.4M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
315
31.4M
    }
void CTransaction::Serialize<ParamsStream<VectorWriter&, TransactionSerParams> >(ParamsStream<VectorWriter&, TransactionSerParams>&) const
Line
Count
Source
313
86.0k
    inline void Serialize(Stream& s) const {
314
86.0k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
315
86.0k
    }
void CTransaction::Serialize<ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams> >(ParamsStream<BufferedWriter<AutoFile>&, TransactionSerParams>&) const
Line
Count
Source
313
528k
    inline void Serialize(Stream& s) const {
314
528k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
315
528k
    }
void CTransaction::Serialize<ParamsStream<AutoFile&, TransactionSerParams> >(ParamsStream<AutoFile&, TransactionSerParams>&) const
Line
Count
Source
313
246k
    inline void Serialize(Stream& s) const {
314
246k
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
315
246k
    }
Unexecuted instantiation: void CTransaction::Serialize<ParamsStream<DataStream&, TransactionSerParams> >(ParamsStream<DataStream&, TransactionSerParams>&) const
void CTransaction::Serialize<ParamsStream<HashWriter&, TransactionSerParams> >(ParamsStream<HashWriter&, TransactionSerParams>&) const
Line
Count
Source
313
7.18M
    inline void Serialize(Stream& s) const {
314
7.18M
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
315
7.18M
    }
316
317
    /** This deserializing constructor is provided instead of an Unserialize method.
318
     *  Unserialize is not possible, since it would require overwriting const fields. */
319
    template <typename Stream>
320
    CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {}
321
    template <typename Stream>
322
3.74M
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
Unexecuted instantiation: CTransaction::CTransaction<ParamsStream<AutoFile&, TransactionSerParams> >(deserialize_type, ParamsStream<AutoFile&, TransactionSerParams>&)
CTransaction::CTransaction<ParamsStream<DataStream&, TransactionSerParams> >(deserialize_type, ParamsStream<DataStream&, TransactionSerParams>&)
Line
Count
Source
322
3.34M
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
CTransaction::CTransaction<ParamsStream<SpanReader&, TransactionSerParams> >(deserialize_type, ParamsStream<SpanReader&, TransactionSerParams>&)
Line
Count
Source
322
399k
    CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
Unexecuted instantiation: CTransaction::CTransaction<ParamsStream<BufferedFile&, TransactionSerParams> >(deserialize_type, ParamsStream<BufferedFile&, TransactionSerParams>&)
323
324
87.0k
    bool IsNull() const {
325
87.0k
        return vin.empty() && vout.empty();
  Branch (325:16): [True: 0, False: 87.0k]
  Branch (325:31): [True: 0, False: 0]
326
87.0k
    }
327
328
217M
    const Txid& GetHash() const LIFETIMEBOUND { return hash; }
329
181M
    const Wtxid& GetWitnessHash() const LIFETIMEBOUND { return m_witness_hash; };
330
331
    // Return sum of txouts.
332
    CAmount GetValueOut() const;
333
334
    /**
335
     * Calculate the total transaction size in bytes, including witness data.
336
     * "Total Size" defined in BIP141 and BIP144.
337
     * @return Total transaction size in bytes
338
     */
339
    unsigned int ComputeTotalSize() const;
340
341
    bool IsCoinBase() const
342
55.0M
    {
343
55.0M
        return (vin.size() == 1 && vin[0].prevout.IsNull());
  Branch (343:17): [True: 53.7M, False: 1.26M]
  Branch (343:36): [True: 738k, False: 53.0M]
344
55.0M
    }
345
346
    friend bool operator==(const CTransaction& a, const CTransaction& b)
347
0
    {
348
0
        return a.GetWitnessHash() == b.GetWitnessHash();
349
0
    }
350
351
    std::string ToString() const;
352
353
24.9M
    bool HasWitness() const { return m_has_witness; }
354
};
355
356
/** A mutable version of CTransaction. */
357
struct CMutableTransaction
358
{
359
    std::vector<CTxIn> vin;
360
    std::vector<CTxOut> vout;
361
    uint32_t version;
362
    uint32_t nLockTime;
363
364
    explicit CMutableTransaction();
365
    explicit CMutableTransaction(const CTransaction& tx);
366
367
    template <typename Stream>
368
0
    inline void Serialize(Stream& s) const {
369
0
        SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
370
0
    }
Unexecuted instantiation: void CMutableTransaction::Serialize<ParamsStream<SizeComputer&, TransactionSerParams> >(ParamsStream<SizeComputer&, TransactionSerParams>&) const
Unexecuted instantiation: void CMutableTransaction::Serialize<ParamsStream<DataStream&, TransactionSerParams> >(ParamsStream<DataStream&, TransactionSerParams>&) const
Unexecuted instantiation: void CMutableTransaction::Serialize<ParamsStream<HashWriter&, TransactionSerParams> >(ParamsStream<HashWriter&, TransactionSerParams>&) const
371
372
    template <typename Stream>
373
3.74M
    inline void Unserialize(Stream& s) {
374
3.74M
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
375
3.74M
    }
Unexecuted instantiation: void CMutableTransaction::Unserialize<ParamsStream<AutoFile&, TransactionSerParams> >(ParamsStream<AutoFile&, TransactionSerParams>&)
void CMutableTransaction::Unserialize<ParamsStream<DataStream&, TransactionSerParams> >(ParamsStream<DataStream&, TransactionSerParams>&)
Line
Count
Source
373
3.34M
    inline void Unserialize(Stream& s) {
374
3.34M
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
375
3.34M
    }
void CMutableTransaction::Unserialize<ParamsStream<SpanReader&, TransactionSerParams> >(ParamsStream<SpanReader&, TransactionSerParams>&)
Line
Count
Source
373
399k
    inline void Unserialize(Stream& s) {
374
399k
        UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>());
375
399k
    }
Unexecuted instantiation: void CMutableTransaction::Unserialize<ParamsStream<BufferedFile&, TransactionSerParams> >(ParamsStream<BufferedFile&, TransactionSerParams>&)
376
377
    template <typename Stream>
378
    CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) {
379
        UnserializeTransaction(*this, s, params);
380
    }
381
382
    template <typename Stream>
383
3.74M
    CMutableTransaction(deserialize_type, Stream& s) {
384
3.74M
        Unserialize(s);
385
3.74M
    }
Unexecuted instantiation: CMutableTransaction::CMutableTransaction<ParamsStream<AutoFile&, TransactionSerParams> >(deserialize_type, ParamsStream<AutoFile&, TransactionSerParams>&)
CMutableTransaction::CMutableTransaction<ParamsStream<DataStream&, TransactionSerParams> >(deserialize_type, ParamsStream<DataStream&, TransactionSerParams>&)
Line
Count
Source
383
3.34M
    CMutableTransaction(deserialize_type, Stream& s) {
384
3.34M
        Unserialize(s);
385
3.34M
    }
CMutableTransaction::CMutableTransaction<ParamsStream<SpanReader&, TransactionSerParams> >(deserialize_type, ParamsStream<SpanReader&, TransactionSerParams>&)
Line
Count
Source
383
399k
    CMutableTransaction(deserialize_type, Stream& s) {
384
399k
        Unserialize(s);
385
399k
    }
Unexecuted instantiation: CMutableTransaction::CMutableTransaction<ParamsStream<BufferedFile&, TransactionSerParams> >(deserialize_type, ParamsStream<BufferedFile&, TransactionSerParams>&)
386
387
    /** Compute the hash of this CMutableTransaction. This is computed on the
388
     * fly, as opposed to GetHash() in CTransaction, which uses a cached result.
389
     */
390
    Txid GetHash() const;
391
392
    bool HasWitness() const
393
3.45M
    {
394
3.51M
        for (size_t i = 0; i < vin.size(); i++) {
  Branch (394:28): [True: 3.50M, False: 5.31k]
395
3.50M
            if (!vin[i].scriptWitness.IsNull()) {
  Branch (395:17): [True: 3.45M, False: 54.2k]
396
3.45M
                return true;
397
3.45M
            }
398
3.50M
        }
399
5.31k
        return false;
400
3.45M
    }
401
};
402
403
typedef std::shared_ptr<const CTransaction> CTransactionRef;
404
162
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
Unexecuted instantiation: miner.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Unexecuted instantiation: miner.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Unexecuted instantiation: mempool.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Unexecuted instantiation: mining.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Unexecuted instantiation: validation.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Unexecuted instantiation: feebumper.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Unexecuted instantiation: spend.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Unexecuted instantiation: backup.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction&>(CMutableTransaction&)
Unexecuted instantiation: wallet.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CTransaction const&>(CTransaction const&)
chainparams.cpp:std::shared_ptr<CTransaction const> MakeTransactionRef<CMutableTransaction>(CMutableTransaction&&)
Line
Count
Source
404
162
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
405
406
namespace std {
407
/** Disable default std::hash for CTransactionRef to prevent accidentally
408
 *  comparing by pointer. Use CTransactionRefHash or provide a custom
409
 *  hasher. */
410
template <>
411
struct hash<CTransactionRef> {
412
    hash() = delete;
413
    // Belt-and-suspenders, already implied by the above.
414
    size_t operator()(const CTransactionRef&) const = delete;
415
};
416
} // namespace std
417
418
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H