Coverage Report

Created: 2026-09-02 14:16

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