Coverage Report

Created: 2026-10-07 20:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/rpc/rawtransaction_util.cpp
Line
Count
Source
1
// Copyright (c) 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
#include <rpc/rawtransaction_util.h>
7
8
#include <coins.h>
9
#include <consensus/amount.h>
10
#include <core_io.h>
11
#include <crypto/hex_base.h>
12
#include <key_io.h>
13
#include <policy/feerate.h>
14
#include <policy/policy.h>
15
#include <primitives/transaction.h>
16
#include <rpc/protocol.h>
17
#include <rpc/request.h>
18
#include <rpc/util.h>
19
#include <script/interpreter.h>
20
#include <script/script.h>
21
#include <script/sign.h>
22
#include <script/signingprovider.h>
23
#include <tinyformat.h>
24
#include <univalue.h>
25
#include <util/check.h>
26
#include <util/rbf.h>
27
#include <util/translation.h>
28
#include <util/vector.h>
29
30
#include <cstddef>
31
#include <set>
32
#include <span>
33
#include <variant>
34
35
void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, std::optional<bool> rbf)
36
0
{
37
0
    UniValue inputs;
38
0
    if (inputs_in.isNull()) {
  Branch (38:9): [True: 0, False: 0]
39
0
        inputs = UniValue::VARR;
40
0
    } else {
41
0
        inputs = inputs_in.get_array();
42
0
    }
43
44
0
    for (unsigned int idx = 0; idx < inputs.size(); idx++) {
  Branch (44:32): [True: 0, False: 0]
45
0
        const UniValue& input = inputs[idx];
46
0
        const UniValue& o = input.get_obj();
47
48
0
        Txid txid = Txid::FromUint256(ParseHashO(o, "txid"));
49
50
0
        const UniValue& vout_v = o.find_value("vout");
51
0
        if (!vout_v.isNum())
  Branch (51:13): [True: 0, False: 0]
52
0
            throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
53
0
        int nOutput = vout_v.getInt<int>();
54
0
        if (nOutput < 0)
  Branch (54:13): [True: 0, False: 0]
55
0
            throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
56
57
0
        uint32_t nSequence;
58
59
0
        if (rbf.value_or(true)) {
  Branch (59:13): [True: 0, False: 0]
60
0
            nSequence = MAX_BIP125_RBF_SEQUENCE; /* CTxIn::SEQUENCE_FINAL - 2 */
61
0
        } else if (rawTx.nLockTime) {
  Branch (61:20): [True: 0, False: 0]
62
0
            nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; /* CTxIn::SEQUENCE_FINAL - 1 */
63
0
        } else {
64
0
            nSequence = CTxIn::SEQUENCE_FINAL;
65
0
        }
66
67
        // set the sequence number if passed in the parameters object
68
0
        const UniValue& sequenceObj = o.find_value("sequence");
69
0
        if (sequenceObj.isNum()) {
  Branch (69:13): [True: 0, False: 0]
70
0
            int64_t seqNr64 = sequenceObj.getInt<int64_t>();
71
0
            if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) {
  Branch (71:17): [True: 0, False: 0]
  Branch (71:32): [True: 0, False: 0]
72
0
                throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
73
0
            } else {
74
0
                nSequence = (uint32_t)seqNr64;
75
0
            }
76
0
        }
77
78
0
        CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
79
80
0
        rawTx.vin.push_back(in);
81
0
    }
82
0
}
83
84
UniValue NormalizeOutputs(const UniValue& outputs_in)
85
0
{
86
0
    if (outputs_in.isNull()) {
  Branch (86:9): [True: 0, False: 0]
87
0
        throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, output argument must be non-null");
88
0
    }
89
90
0
    const bool outputs_is_obj = outputs_in.isObject();
91
0
    UniValue outputs = outputs_is_obj ? outputs_in.get_obj() : outputs_in.get_array();
  Branch (91:24): [True: 0, False: 0]
92
93
0
    if (!outputs_is_obj) {
  Branch (93:9): [True: 0, False: 0]
94
        // Translate array of key-value pairs into dict
95
0
        UniValue outputs_dict = UniValue(UniValue::VOBJ);
96
0
        for (size_t i = 0; i < outputs.size(); ++i) {
  Branch (96:28): [True: 0, False: 0]
97
0
            const UniValue& output = outputs[i];
98
0
            if (!output.isObject()) {
  Branch (98:17): [True: 0, False: 0]
99
0
                throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair not an object as expected");
100
0
            }
101
0
            if (output.size() != 1) {
  Branch (101:17): [True: 0, False: 0]
102
0
                throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair must contain exactly one key");
103
0
            }
104
0
            outputs_dict.pushKVs(output);
105
0
        }
106
0
        outputs = std::move(outputs_dict);
107
0
    }
108
0
    return outputs;
109
0
}
110
111
std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs)
112
0
{
113
    // Duplicate checking
114
0
    std::set<CTxDestination> destinations;
115
0
    std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs;
116
0
    bool has_data{false};
117
0
    const auto& keys{outputs.getKeys()};
118
0
    const auto& values{outputs.getValues()};
119
0
    for (size_t i{0}; i < keys.size(); ++i) {
  Branch (119:23): [True: 0, False: 0]
120
0
        const auto& name_{keys[i]};
121
0
        const auto& value{values[i]};
122
0
        if (name_ == "data") {
  Branch (122:13): [True: 0, False: 0]
123
0
            if (has_data) {
  Branch (123:17): [True: 0, False: 0]
124
0
                throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, duplicate key: data");
125
0
            }
126
0
            has_data = true;
127
0
            std::vector<unsigned char> data = ParseHexV(value.getValStr(), "Data");
128
0
            CTxDestination destination{CNoDestination{CScript() << OP_RETURN << data}};
129
0
            CAmount amount{0};
130
0
            parsed_outputs.emplace_back(destination, amount);
131
0
        } else {
132
0
            CTxDestination destination{DecodeDestination(name_)};
133
0
            CAmount amount{AmountFromValue(value)};
134
0
            if (!IsValidDestination(destination)) {
  Branch (134:17): [True: 0, False: 0]
135
0
                throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + name_);
136
0
            }
137
138
0
            if (!destinations.insert(destination).second) {
  Branch (138:17): [True: 0, False: 0]
139
0
                throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_);
140
0
            }
141
0
            parsed_outputs.emplace_back(destination, amount);
142
0
        }
143
0
    }
144
0
    return parsed_outputs;
145
0
}
146
147
void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in)
148
0
{
149
0
    UniValue outputs(UniValue::VOBJ);
150
0
    outputs = NormalizeOutputs(outputs_in);
151
152
0
    std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs = ParseOutputs(outputs);
153
0
    for (const auto& [destination, nAmount] : parsed_outputs) {
  Branch (153:45): [True: 0, False: 0]
154
0
        CScript scriptPubKey = GetScriptForDestination(destination);
155
156
0
        CTxOut out(nAmount, scriptPubKey);
157
0
        rawTx.vout.push_back(out);
158
0
    }
159
0
}
160
161
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf, const uint32_t version)
162
0
{
163
0
    CMutableTransaction rawTx;
164
165
0
    if (!locktime.isNull()) {
  Branch (165:9): [True: 0, False: 0]
166
0
        int64_t nLockTime = locktime.getInt<int64_t>();
167
0
        if (nLockTime < 0 || nLockTime > LOCKTIME_MAX)
  Branch (167:13): [True: 0, False: 0]
  Branch (167:30): [True: 0, False: 0]
168
0
            throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
169
0
        rawTx.nLockTime = nLockTime;
170
0
    }
171
172
0
    if (version < TX_MIN_STANDARD_VERSION || version > TX_MAX_STANDARD_VERSION) {
  Branch (172:9): [True: 0, False: 0]
  Branch (172:46): [True: 0, False: 0]
173
0
        throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, version out of range(%d~%d)", TX_MIN_STANDARD_VERSION, TX_MAX_STANDARD_VERSION));
174
0
    }
175
0
    rawTx.version = version;
176
177
0
    AddInputs(rawTx, inputs_in, rbf);
178
0
    AddOutputs(rawTx, outputs_in);
179
180
0
    if (rbf.has_value() && rbf.value() && rawTx.vin.size() > 0 && !SignalsOptInRBF(CTransaction(rawTx))) {
  Branch (180:9): [True: 0, False: 0]
  Branch (180:9): [True: 0, False: 0]
  Branch (180:28): [True: 0, False: 0]
  Branch (180:43): [True: 0, False: 0]
  Branch (180:67): [True: 0, False: 0]
181
0
        throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number(s) contradict replaceable option");
182
0
    }
183
184
0
    return rawTx;
185
0
}
186
187
/** Pushes a JSON object for script verification or signing errors to vErrorsRet. */
188
static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::string& strMessage)
189
0
{
190
0
    UniValue entry(UniValue::VOBJ);
191
0
    entry.pushKV("txid", txin.prevout.hash.ToString());
192
0
    entry.pushKV("vout", txin.prevout.n);
193
0
    UniValue witness(UniValue::VARR);
194
0
    for (unsigned int i = 0; i < txin.scriptWitness.stack.size(); i++) {
  Branch (194:30): [True: 0, False: 0]
195
0
        witness.push_back(HexStr(txin.scriptWitness.stack[i]));
196
0
    }
197
0
    entry.pushKV("witness", std::move(witness));
198
0
    entry.pushKV("scriptSig", HexStr(txin.scriptSig));
199
0
    entry.pushKV("sequence", txin.nSequence);
200
0
    entry.pushKV("error", strMessage);
201
0
    vErrorsRet.push_back(std::move(entry));
202
0
}
203
204
void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
205
0
{
206
0
    if (!prevTxsUnival.isNull()) {
  Branch (206:9): [True: 0, False: 0]
207
0
        const UniValue& prevTxs = prevTxsUnival.get_array();
208
0
        for (unsigned int idx = 0; idx < prevTxs.size(); ++idx) {
  Branch (208:36): [True: 0, False: 0]
209
0
            const UniValue& p = prevTxs[idx];
210
0
            if (!p.isObject()) {
  Branch (210:17): [True: 0, False: 0]
211
0
                throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
212
0
            }
213
214
0
            const UniValue& prevOut = p.get_obj();
215
216
0
            RPCTypeCheckObj(prevOut,
217
0
                {
218
0
                    {"txid", UniValueType(UniValue::VSTR)},
219
0
                    {"vout", UniValueType(UniValue::VNUM)},
220
0
                    {"scriptPubKey", UniValueType(UniValue::VSTR)},
221
0
                });
222
223
0
            Txid txid = Txid::FromUint256(ParseHashO(prevOut, "txid"));
224
225
0
            int nOut = prevOut.find_value("vout").getInt<int>();
226
0
            if (nOut < 0) {
  Branch (226:17): [True: 0, False: 0]
227
0
                throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative");
228
0
            }
229
230
0
            COutPoint out(txid, nOut);
231
0
            std::vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
232
0
            CScript scriptPubKey(pkData.begin(), pkData.end());
233
234
0
            {
235
0
                auto coin = coins.find(out);
236
0
                if (coin != coins.end() && !coin->second.IsSpent() && coin->second.out.scriptPubKey != scriptPubKey) {
  Branch (236:21): [True: 0, False: 0]
  Branch (236:21): [True: 0, False: 0]
  Branch (236:44): [True: 0, False: 0]
  Branch (236:71): [True: 0, False: 0]
237
0
                    std::string err("Previous output scriptPubKey mismatch:\n");
238
0
                    err = err + ScriptToAsmStr(coin->second.out.scriptPubKey) + "\nvs:\n"+
239
0
                        ScriptToAsmStr(scriptPubKey);
240
0
                    throw JSONRPCError(RPC_DESERIALIZATION_ERROR, err);
241
0
                }
242
0
                Coin newcoin;
243
0
                newcoin.out.scriptPubKey = scriptPubKey;
244
0
                newcoin.out.nValue = MAX_MONEY;
245
0
                if (prevOut.exists("amount")) {
  Branch (245:21): [True: 0, False: 0]
246
0
                    newcoin.out.nValue = AmountFromValue(prevOut.find_value("amount"));
247
0
                }
248
0
                newcoin.nHeight = 1;
249
0
                coins[out] = std::move(newcoin);
250
0
            }
251
252
            // if redeemScript and private keys were given, add redeemScript to the keystore so it can be signed
253
0
            const bool is_p2sh = scriptPubKey.IsPayToScriptHash();
254
0
            const bool is_p2wsh = scriptPubKey.IsPayToWitnessScriptHash();
255
0
            if (keystore && (is_p2sh || is_p2wsh)) {
  Branch (255:17): [True: 0, False: 0]
  Branch (255:30): [True: 0, False: 0]
  Branch (255:41): [True: 0, False: 0]
256
0
                RPCTypeCheckObj(prevOut,
257
0
                    {
258
0
                        {"redeemScript", UniValueType(UniValue::VSTR)},
259
0
                        {"witnessScript", UniValueType(UniValue::VSTR)},
260
0
                    }, true);
261
0
                const UniValue& rs{prevOut.find_value("redeemScript")};
262
0
                const UniValue& ws{prevOut.find_value("witnessScript")};
263
0
                if (rs.isNull() && ws.isNull()) {
  Branch (263:21): [True: 0, False: 0]
  Branch (263:36): [True: 0, False: 0]
264
0
                    throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing redeemScript/witnessScript");
265
0
                }
266
267
                // work from witnessScript when possible
268
0
                std::vector<unsigned char> scriptData(!ws.isNull() ? ParseHexV(ws, "witnessScript") : ParseHexV(rs, "redeemScript"));
  Branch (268:55): [True: 0, False: 0]
269
0
                CScript script(scriptData.begin(), scriptData.end());
270
0
                keystore->scripts.emplace(CScriptID(script), script);
271
                // Automatically also add the P2WSH wrapped version of the script (to deal with P2SH-P2WSH).
272
                // This is done for redeemScript only for compatibility, it is encouraged to use the explicit witnessScript field instead.
273
0
                CScript witness_output_script{GetScriptForDestination(WitnessV0ScriptHash(script))};
274
0
                keystore->scripts.emplace(CScriptID(witness_output_script), witness_output_script);
275
276
0
                if (!ws.isNull() && !rs.isNull()) {
  Branch (276:21): [True: 0, False: 0]
  Branch (276:37): [True: 0, False: 0]
277
                    // if both witnessScript and redeemScript are provided,
278
                    // they should either be the same (for backwards compat),
279
                    // or the redeemScript should be the encoded form of
280
                    // the witnessScript (ie, for p2sh-p2wsh)
281
0
                    if (ws.get_str() != rs.get_str()) {
  Branch (281:25): [True: 0, False: 0]
282
0
                        std::vector<unsigned char> redeemScriptData(ParseHexV(rs, "redeemScript"));
283
0
                        CScript redeemScript(redeemScriptData.begin(), redeemScriptData.end());
284
0
                        if (redeemScript != witness_output_script) {
  Branch (284:29): [True: 0, False: 0]
285
0
                            throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript does not correspond to witnessScript");
286
0
                        }
287
0
                    }
288
0
                }
289
290
0
                if (is_p2sh) {
  Branch (290:21): [True: 0, False: 0]
291
0
                    const CTxDestination p2sh{ScriptHash(script)};
292
0
                    const CTxDestination p2sh_p2wsh{ScriptHash(witness_output_script)};
293
0
                    if (scriptPubKey == GetScriptForDestination(p2sh)) {
  Branch (293:25): [True: 0, False: 0]
294
                        // traditional p2sh; arguably an error if
295
                        // we got here with rs.IsNull(), because
296
                        // that means the p2sh script was specified
297
                        // via witnessScript param, but for now
298
                        // we'll just quietly accept it
299
0
                    } else if (scriptPubKey == GetScriptForDestination(p2sh_p2wsh)) {
  Branch (299:32): [True: 0, False: 0]
300
                        // p2wsh encoded as p2sh; ideally the witness
301
                        // script was specified in the witnessScript
302
                        // param, but also support specifying it via
303
                        // redeemScript param for backwards compat
304
                        // (in which case ws.IsNull() == true)
305
0
                    } else {
306
                        // otherwise, can't generate scriptPubKey from
307
                        // either script, so we got unusable parameters
308
0
                        throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript/witnessScript does not match scriptPubKey");
309
0
                    }
310
0
                } else if (is_p2wsh) {
  Branch (310:28): [True: 0, False: 0]
311
                    // plain p2wsh; could throw an error if script
312
                    // was specified by redeemScript rather than
313
                    // witnessScript (ie, ws.IsNull() == true), but
314
                    // accept it for backwards compat
315
0
                    const CTxDestination p2wsh{WitnessV0ScriptHash(script)};
316
0
                    if (scriptPubKey != GetScriptForDestination(p2wsh)) {
  Branch (316:25): [True: 0, False: 0]
317
0
                        throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript/witnessScript does not match scriptPubKey");
318
0
                    }
319
0
                }
320
0
            }
321
0
        }
322
0
    }
323
0
}
324
325
void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result)
326
0
{
327
0
    std::optional<int> nHashType = ParseSighashString(hashType);
328
0
    if (!nHashType) {
  Branch (328:9): [True: 0, False: 0]
329
0
        nHashType = SIGHASH_DEFAULT;
330
0
    }
331
332
    // Script verification errors
333
0
    std::map<int, bilingual_str> input_errors;
334
335
0
    bool complete = SignTransaction(mtx, keystore, coins, {.sighash_type = *nHashType}, input_errors);
336
0
    SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
337
0
}
338
339
void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result)
340
0
{
341
    // Make errors UniValue
342
0
    UniValue vErrors(UniValue::VARR);
343
0
    for (const auto& err_pair : input_errors) {
  Branch (343:31): [True: 0, False: 0]
344
0
        if (err_pair.second.original == "Missing amount") {
  Branch (344:13): [True: 0, False: 0]
345
            // This particular error needs to be an exception for some reason
346
0
            throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing amount for %s", coins.at(mtx.vin.at(err_pair.first).prevout).out.ToString()));
347
0
        }
348
0
        TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second.original);
349
0
    }
350
351
0
    result.pushKV("hex", EncodeHexTx(CTransaction(mtx)));
352
0
    result.pushKV("complete", complete);
353
0
    if (!vErrors.empty()) {
  Branch (353:9): [True: 0, False: 0]
354
0
        if (result.exists("errors")) {
  Branch (354:13): [True: 0, False: 0]
355
0
            vErrors.push_backV(result["errors"].getValues());
356
0
        }
357
0
        result.pushKV("errors", std::move(vErrors));
358
0
    }
359
0
}
360
361
std::vector<RPCResult> TxDoc(const TxDocOptions& opts)
362
0
{
363
0
    CHECK_NONFATAL(!opts.fee_doc || opts.fee);
364
0
    CHECK_NONFATAL(!opts.prevout_doc || opts.prevout);
365
0
    CHECK_NONFATAL(!opts.vin_item_doc || opts.vin_inner_elision);
366
0
    CHECK_NONFATAL(opts.elision_mode != ElisionMode::WithSummary || opts.elision_summary.has_value());
367
368
0
    const std::string fee_doc{opts.fee_doc.value_or(
369
0
        "transaction fee in " + CURRENCY_UNIT + ", omitted if block undo data is not available")};
370
0
    const std::string prevout_doc{opts.prevout_doc.value_or(
371
0
        "The previous output, omitted if block undo data is not available")};
372
0
    const std::string vin_item_doc{opts.vin_item_doc.value_or("utxo being spent")};
373
374
0
    auto vin_inner = std::vector<RPCResult>{
375
0
        {RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
376
0
        {RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
377
0
        {RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
378
0
        {RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
379
0
        {
380
0
            {RPCResult::Type::STR, "asm", "Disassembly of the signature script"},
381
0
            {RPCResult::Type::STR_HEX, "hex", "The raw signature script bytes, hex-encoded"},
382
0
        }},
383
0
        {RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "",
384
0
        {
385
0
            {RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"},
386
0
        }},
387
0
    };
388
0
    if (opts.prevout) {
  Branch (388:9): [True: 0, False: 0]
389
0
        vin_inner.emplace_back(
390
0
            RPCResult::Type::OBJ, "prevout", opts.prevout_optional, prevout_doc,
391
0
            std::vector<RPCResult>{
392
0
                {RPCResult::Type::BOOL, "generated", "Coinbase or not"},
393
0
                {RPCResult::Type::NUM, "height", "The height of the prevout"},
394
0
                {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
395
0
                {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
396
0
            }
397
0
        );
398
0
    }
399
0
    vin_inner.emplace_back(RPCResult::Type::NUM, "sequence", "The script sequence number");
400
401
0
    if (opts.vin_inner_elision) {
  Branch (401:9): [True: 0, False: 0]
402
0
        vin_inner = ElideGroup(std::move(vin_inner), *opts.vin_inner_elision);
403
0
        if (opts.prevout) {
  Branch (403:13): [True: 0, False: 0]
404
            // prevout remains visible even when other fields are elided
405
0
            std::vector<RPCResult> new_vin;
406
0
            new_vin.reserve(vin_inner.size());
407
0
            for (const auto& r : vin_inner) {
  Branch (407:32): [True: 0, False: 0]
408
0
                if (r.m_key_name == "prevout") {
  Branch (408:21): [True: 0, False: 0]
409
0
                    RPCResultOptions unopts = r.m_opts;
410
0
                    unopts.print_elision = HelpElisionNone{};
411
0
                    new_vin.emplace_back(r, std::move(unopts));
412
0
                } else {
413
0
                    new_vin.push_back(r);
414
0
                }
415
0
            }
416
0
            vin_inner = std::move(new_vin);
417
0
        }
418
0
    }
419
420
0
    auto fields = std::vector<RPCResult>{
421
0
        {RPCResult::Type::STR_HEX, "txid", opts.txid_field_doc},
422
0
        {RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
423
0
        {RPCResult::Type::NUM, "size", "The serialized transaction size"},
424
0
        {RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
425
0
        {RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"},
426
0
        {RPCResult::Type::NUM, "version", "The version"},
427
0
        {RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
428
0
        {RPCResult::Type::ARR, "vin", "",
429
0
        {
430
0
            {RPCResult::Type::OBJ, "", opts.vin_inner_elision ? vin_item_doc : "", std::move(vin_inner)},
  Branch (430:40): [True: 0, False: 0]
431
0
        }},
432
0
        {RPCResult::Type::ARR, "vout", "",
433
0
        {
434
0
            {RPCResult::Type::OBJ, "", "", Cat(
435
0
                {
436
0
                    {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
437
0
                    {RPCResult::Type::NUM, "n", "index"},
438
0
                    {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
439
0
                },
440
0
                opts.wallet ?
  Branch (440:17): [True: 0, False: 0]
441
0
                    std::vector<RPCResult>{{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} :
442
0
                    std::vector<RPCResult>{}
443
0
            )},
444
0
        }},
445
0
    };
446
447
0
    if (opts.fee) fields.emplace_back(RPCResult::Type::NUM, "fee", /*optional=*/true, fee_doc);
  Branch (447:9): [True: 0, False: 0]
448
0
    if (opts.hex) fields.emplace_back(RPCResult::Type::STR_HEX, "hex", "The hex-encoded transaction data");
  Branch (448:9): [True: 0, False: 0]
449
450
0
    if (opts.elision_mode != ElisionMode::None) {
  Branch (450:9): [True: 0, False: 0]
451
0
        const bool silent = opts.elision_mode == ElisionMode::Silent;
452
0
        std::vector<RPCResult> new_fields;
453
0
        new_fields.reserve(fields.size());
454
0
        bool first = true;
455
0
        for (const auto& f : fields) {
  Branch (455:28): [True: 0, False: 0]
456
0
            if (!silent && f.m_key_name == "fee") {
  Branch (456:17): [True: 0, False: 0]
  Branch (456:28): [True: 0, False: 0]
457
0
                new_fields.push_back(f);
458
0
                continue;
459
0
            }
460
0
            if (f.m_key_name == "vin" && opts.vin_inner_elision) {
  Branch (460:17): [True: 0, False: 0]
  Branch (460:42): [True: 0, False: 0]
461
0
                new_fields.push_back(f);
462
0
                continue;
463
0
            }
464
0
            if (!silent && first) {
  Branch (464:17): [True: 0, False: 0]
  Branch (464:28): [True: 0, False: 0]
465
0
                RPCResultOptions eopts = f.m_opts;
466
0
                eopts.print_elision = opts.elision_summary.value_or("");
467
0
                new_fields.emplace_back(f, std::move(eopts));
468
0
                first = false;
469
0
            } else {
470
0
                RPCResultOptions eopts = f.m_opts;
471
0
                eopts.print_elision = HelpElisionSkip{};
472
0
                new_fields.emplace_back(f, std::move(eopts));
473
0
            }
474
0
        }
475
0
        fields = std::move(new_fields);
476
0
    }
477
478
0
    return fields;
479
0
}