Branch data Line data Source code
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 : 1171 : void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, std::optional<bool> rbf)
27 : : {
28 [ + + ]: 1171 : UniValue inputs;
29 [ + + ]: 1171 : if (inputs_in.isNull()) {
30 : 320 : inputs = UniValue::VARR;
31 : : } else {
32 [ + - + - ]: 851 : inputs = inputs_in.get_array();
33 : : }
34 : :
35 [ - + + + ]: 4461 : for (unsigned int idx = 0; idx < inputs.size(); idx++) {
36 [ + - ]: 3299 : const UniValue& input = inputs[idx];
37 [ + + ]: 3299 : const UniValue& o = input.get_obj();
38 : :
39 [ + + ]: 3298 : Txid txid = Txid::FromUint256(ParseHashO(o, "txid"));
40 : :
41 [ + - ]: 3295 : const UniValue& vout_v = o.find_value("vout");
42 [ + + ]: 3295 : if (!vout_v.isNum())
43 [ + - + - ]: 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
44 [ + - ]: 3293 : int nOutput = vout_v.getInt<int>();
45 [ + + ]: 3293 : if (nOutput < 0)
46 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
47 : :
48 : 3292 : uint32_t nSequence;
49 : :
50 [ + + + + ]: 3292 : if (rbf.value_or(true)) {
51 : : nSequence = MAX_BIP125_RBF_SEQUENCE; /* CTxIn::SEQUENCE_FINAL - 2 */
52 [ + + ]: 4 : } else if (rawTx.nLockTime) {
53 : : nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; /* CTxIn::SEQUENCE_FINAL - 1 */
54 : : } else {
55 : 3 : nSequence = CTxIn::SEQUENCE_FINAL;
56 : : }
57 : :
58 : : // set the sequence number if passed in the parameters object
59 [ + - ]: 3292 : const UniValue& sequenceObj = o.find_value("sequence");
60 [ + + ]: 3292 : if (sequenceObj.isNum()) {
61 [ + - ]: 54 : int64_t seqNr64 = sequenceObj.getInt<int64_t>();
62 [ + + ]: 54 : if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) {
63 [ + - + - ]: 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
64 : : } else {
65 : 52 : nSequence = (uint32_t)seqNr64;
66 : : }
67 : : }
68 : :
69 [ + - ]: 3290 : CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
70 : :
71 [ + - ]: 3290 : rawTx.vin.push_back(in);
72 : 3290 : }
73 : 1171 : }
74 : :
75 : 1638 : UniValue NormalizeOutputs(const UniValue& outputs_in)
76 : : {
77 [ - + ]: 1638 : if (outputs_in.isNull()) {
78 [ # # # # ]: 0 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, output argument must be non-null");
79 : : }
80 : :
81 : 1638 : const bool outputs_is_obj = outputs_in.isObject();
82 [ + + ]: 1638 : UniValue outputs = outputs_is_obj ? outputs_in.get_obj() : outputs_in.get_array();
83 : :
84 [ + + ]: 1637 : if (!outputs_is_obj) {
85 : : // Translate array of key-value pairs into dict
86 : 952 : UniValue outputs_dict = UniValue(UniValue::VOBJ);
87 [ - + + + ]: 8648 : for (size_t i = 0; i < outputs.size(); ++i) {
88 [ + - ]: 7698 : const UniValue& output = outputs[i];
89 [ + + ]: 7698 : if (!output.isObject()) {
90 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair not an object as expected");
91 : : }
92 [ - + + + ]: 7697 : if (output.size() != 1) {
93 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair must contain exactly one key");
94 : : }
95 [ + - + - ]: 7696 : outputs_dict.pushKVs(output);
96 : : }
97 : 950 : outputs = std::move(outputs_dict);
98 : 952 : }
99 : 1635 : return outputs;
100 : 2 : }
101 : :
102 : 2922 : std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs)
103 : : {
104 : : // Duplicate checking
105 [ + - ]: 2922 : std::set<CTxDestination> destinations;
106 : 2922 : std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs;
107 : 2922 : bool has_data{false};
108 [ + - ]: 2922 : const auto& keys{outputs.getKeys()};
109 [ + - ]: 2922 : const auto& values{outputs.getValues()};
110 [ - + + + ]: 17882 : for (size_t i{0}; i < keys.size(); ++i) {
111 [ + + ]: 14977 : const auto& name_{keys[i]};
112 : 14977 : const auto& value{values[i]};
113 [ + + ]: 14977 : if (name_ == "data") {
114 [ + + ]: 24 : if (has_data) {
115 [ + - + - ]: 6 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, duplicate key: data");
116 : : }
117 : 21 : has_data = true;
118 [ + - + + ]: 21 : std::vector<unsigned char> data = ParseHexV(value.getValStr(), "Data");
119 [ + - - + ]: 17 : CTxDestination destination{CNoDestination{CScript() << OP_RETURN << data}};
120 : 17 : CAmount amount{0};
121 [ + - ]: 17 : parsed_outputs.emplace_back(destination, amount);
122 : 17 : } else {
123 [ + - ]: 14953 : CTxDestination destination{DecodeDestination(name_)};
124 [ + + ]: 14953 : CAmount amount{AmountFromValue(value)};
125 [ + - + + ]: 14948 : if (!IsValidDestination(destination)) {
126 [ + - + - : 2 : throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + name_);
+ - ]
127 : : }
128 : :
129 [ + - + + ]: 14947 : if (!destinations.insert(destination).second) {
130 [ + - + - : 8 : throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_);
+ - ]
131 : : }
132 [ + - ]: 14943 : parsed_outputs.emplace_back(destination, amount);
133 : 14953 : }
134 : : }
135 : 2905 : return parsed_outputs;
136 : 2922 : }
137 : :
138 : 1172 : void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in)
139 : : {
140 : 1172 : UniValue outputs(UniValue::VOBJ);
141 [ + + ]: 1172 : outputs = NormalizeOutputs(outputs_in);
142 : :
143 [ + + ]: 1169 : std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs = ParseOutputs(outputs);
144 [ + - + + ]: 6501 : for (const auto& [destination, nAmount] : parsed_outputs) {
145 [ + - ]: 5346 : CScript scriptPubKey = GetScriptForDestination(destination);
146 : :
147 [ + - ]: 5346 : CTxOut out(nAmount, scriptPubKey);
148 [ + - ]: 5346 : rawTx.vout.push_back(out);
149 : 5346 : }
150 : 1172 : }
151 : :
152 : 1175 : CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf, const uint32_t version)
153 : : {
154 : 1175 : CMutableTransaction rawTx;
155 : :
156 [ + + ]: 1175 : if (!locktime.isNull()) {
157 [ + - ]: 161 : int64_t nLockTime = locktime.getInt<int64_t>();
158 [ + + ]: 161 : if (nLockTime < 0 || nLockTime > LOCKTIME_MAX)
159 [ + - + - ]: 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
160 : 159 : rawTx.nLockTime = nLockTime;
161 : : }
162 : :
163 [ + + ]: 1173 : if (version < TX_MIN_STANDARD_VERSION || version > TX_MAX_STANDARD_VERSION) {
164 [ + - + - ]: 4 : throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, version out of range(%d~%d)", TX_MIN_STANDARD_VERSION, TX_MAX_STANDARD_VERSION));
165 : : }
166 : 1171 : rawTx.version = version;
167 : :
168 [ + + ]: 1171 : AddInputs(rawTx, inputs_in, rbf);
169 [ + + ]: 1162 : AddOutputs(rawTx, outputs_in);
170 : :
171 [ + + + + : 1371 : if (rbf.has_value() && rbf.value() && rawTx.vin.size() > 0 && !SignalsOptInRBF(CTransaction(rawTx))) {
- + + + +
- + - + +
+ + ]
172 [ + - + - ]: 2 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number(s) contradict replaceable option");
173 : : }
174 : :
175 : 1146 : return rawTx;
176 : 29 : }
177 : :
178 : : /** Pushes a JSON object for script verification or signing errors to vErrorsRet. */
179 : 96 : static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::string& strMessage)
180 : : {
181 : 96 : UniValue entry(UniValue::VOBJ);
182 [ + - + - : 192 : entry.pushKV("txid", txin.prevout.hash.ToString());
+ - + - ]
183 [ + - + - : 192 : 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 : : }
188 [ + - + - ]: 192 : entry.pushKV("witness", std::move(witness));
189 [ + + + - : 288 : entry.pushKV("scriptSig", HexStr(txin.scriptSig));
+ - + - +
- ]
190 [ + - + - : 192 : entry.pushKV("sequence", txin.nSequence);
+ - ]
191 [ + - + - : 192 : entry.pushKV("error", strMessage);
+ - ]
192 [ + - ]: 96 : vErrorsRet.push_back(std::move(entry));
193 : 96 : }
194 : :
195 : 512 : void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
196 : : {
197 [ + + ]: 512 : if (!prevTxsUnival.isNull()) {
198 : 210 : const UniValue& prevTxs = prevTxsUnival.get_array();
199 [ - + + + ]: 726 : 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 : : }
204 : :
205 : 609 : const UniValue& prevOut = p.get_obj();
206 : :
207 [ + + + + : 3054 : RPCTypeCheckObj(prevOut,
+ + ]
208 : : {
209 [ + - ]: 609 : {"txid", UniValueType(UniValue::VSTR)},
210 [ + - ]: 609 : {"vout", UniValueType(UniValue::VNUM)},
211 [ + - ]: 609 : {"scriptPubKey", UniValueType(UniValue::VSTR)},
212 : : });
213 : :
214 : 600 : Txid txid = Txid::FromUint256(ParseHashO(prevOut, "txid"));
215 : :
216 : 600 : int nOut = prevOut.find_value("vout").getInt<int>();
217 [ - + ]: 600 : if (nOut < 0) {
218 [ # # # # ]: 0 : throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative");
219 : : }
220 : :
221 : 600 : COutPoint out(txid, nOut);
222 : 600 : std::vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
223 : 600 : CScript scriptPubKey(pkData.begin(), pkData.end());
224 : :
225 : 600 : {
226 : 600 : auto coin = coins.find(out);
227 [ + - + + : 600 : 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 : 600 : Coin newcoin;
234 : 600 : newcoin.out.scriptPubKey = scriptPubKey;
235 : 600 : newcoin.out.nValue = MAX_MONEY;
236 [ + - + + ]: 1200 : if (prevOut.exists("amount")) {
237 [ + - + - ]: 587 : newcoin.out.nValue = AmountFromValue(prevOut.find_value("amount"));
238 : : }
239 : 600 : newcoin.nHeight = 1;
240 [ + - ]: 600 : coins[out] = std::move(newcoin);
241 : 0 : }
242 : :
243 : : // if redeemScript and private keys were given, add redeemScript to the keystore so it can be signed
244 [ + - ]: 600 : const bool is_p2sh = scriptPubKey.IsPayToScriptHash();
245 [ + - ]: 600 : const bool is_p2wsh = scriptPubKey.IsPayToWitnessScriptHash();
246 [ + + + + ]: 600 : if (keystore && (is_p2sh || is_p2wsh)) {
247 [ + - + + : 956 : RPCTypeCheckObj(prevOut,
- - ]
248 : : {
249 [ + - ]: 239 : {"redeemScript", UniValueType(UniValue::VSTR)},
250 [ + - ]: 239 : {"witnessScript", UniValueType(UniValue::VSTR)},
251 : : }, true);
252 [ + - ]: 239 : const UniValue& rs{prevOut.find_value("redeemScript")};
253 [ + - ]: 239 : const UniValue& ws{prevOut.find_value("witnessScript")};
254 [ + + + + ]: 239 : if (rs.isNull() && ws.isNull()) {
255 [ + - + - ]: 42 : throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing redeemScript/witnessScript");
256 : : }
257 : :
258 : : // work from witnessScript when possible
259 [ + + + - : 218 : std::vector<unsigned char> scriptData(!ws.isNull() ? ParseHexV(ws, "witnessScript") : ParseHexV(rs, "redeemScript"));
+ - ]
260 : 218 : CScript script(scriptData.begin(), scriptData.end());
261 [ + - + - ]: 218 : 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 [ + - + - ]: 218 : CScript witness_output_script{GetScriptForDestination(WitnessV0ScriptHash(script))};
265 [ + - + - ]: 218 : keystore->scripts.emplace(CScriptID(witness_output_script), witness_output_script);
266 : :
267 [ + + + + ]: 218 : 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 [ + - + - ]: 42 : throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript does not correspond to witnessScript");
277 : : }
278 : 45 : }
279 : : }
280 : :
281 [ + + ]: 197 : if (is_p2sh) {
282 [ + - ]: 149 : const CTxDestination p2sh{ScriptHash(script)};
283 [ + - ]: 149 : const CTxDestination p2sh_p2wsh{ScriptHash(witness_output_script)};
284 [ + - + + ]: 149 : 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 [ + - + + ]: 58 : } 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 : : } else {
297 : : // otherwise, can't generate scriptPubKey from
298 : : // either script, so we got unusable parameters
299 [ + - + - ]: 52 : throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript/witnessScript does not match scriptPubKey");
300 : : }
301 [ + - ]: 223 : } 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 [ + - + - ]: 32 : throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript/witnessScript does not match scriptPubKey");
309 : : }
310 : 48 : }
311 : 344 : }
312 : 600 : }
313 : : }
314 [ + - + - : 1276 : }
+ - + - +
- + - + -
- + - - ]
315 : :
316 : 113 : void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result)
317 : : {
318 : 113 : std::optional<int> nHashType = ParseSighashString(hashType);
319 [ + - ]: 112 : if (!nHashType) {
320 : 112 : nHashType = SIGHASH_DEFAULT;
321 : : }
322 : :
323 : : // Script verification errors
324 [ + - ]: 112 : std::map<int, bilingual_str> input_errors;
325 : :
326 [ + - ]: 112 : bool complete = SignTransaction(mtx, keystore, coins, {.sighash_type = *nHashType}, input_errors);
327 [ + - ]: 112 : SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
328 : 112 : }
329 : :
330 : 417 : void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result)
331 : : {
332 : : // Make errors UniValue
333 : 417 : UniValue vErrors(UniValue::VARR);
334 [ + + ]: 513 : 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 [ + - + - : 4 : throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing amount for %s", coins.at(mtx.vin.at(err_pair.first).prevout).out.ToString()));
+ - + - +
- ]
338 : : }
339 [ + - + - ]: 96 : TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second.original);
340 : : }
341 : :
342 [ + - + - : 830 : result.pushKV("hex", EncodeHexTx(CTransaction(mtx)));
+ - + - +
- ]
343 [ + - + - : 830 : result.pushKV("complete", complete);
+ - ]
344 [ - + + + ]: 415 : if (!vErrors.empty()) {
345 [ + - - + ]: 188 : if (result.exists("errors")) {
346 [ # # # # : 0 : vErrors.push_backV(result["errors"].getValues());
# # # # ]
347 : : }
348 [ + - + - ]: 188 : result.pushKV("errors", std::move(vErrors));
349 : : }
350 : 417 : }
351 : :
352 : 46884 : std::vector<RPCResult> TxDoc(const TxDocOptions& opts)
353 : : {
354 [ + + - + ]: 46884 : CHECK_NONFATAL(!opts.fee_doc || opts.fee);
355 [ + + - + ]: 46884 : CHECK_NONFATAL(!opts.prevout_doc || opts.prevout);
356 [ + + + - ]: 57966 : CHECK_NONFATAL(!opts.vin_item_doc || opts.vin_inner_elision);
357 [ + + + - ]: 62267 : CHECK_NONFATAL(opts.elision_mode != ElisionMode::WithSummary || opts.elision_summary.has_value());
358 : :
359 : 46884 : const std::string fee_doc{opts.fee_doc.value_or(
360 [ + - + - ]: 140652 : "transaction fee in " + CURRENCY_UNIT + ", omitted if block undo data is not available")};
361 : 46884 : const std::string prevout_doc{opts.prevout_doc.value_or(
362 [ + - ]: 46884 : "The previous output, omitted if block undo data is not available")};
363 [ + - ]: 46884 : const std::string vin_item_doc{opts.vin_item_doc.value_or("utxo being spent")};
364 : :
365 : 46884 : auto vin_inner = std::vector<RPCResult>{
366 [ + - + - ]: 93768 : {RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
367 [ + - + - ]: 93768 : {RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
368 [ + - + - ]: 93768 : {RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
369 [ + - + - ]: 93768 : {RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
370 : : {
371 [ + - + - ]: 93768 : {RPCResult::Type::STR, "asm", "Disassembly of the signature script"},
372 [ + - + - ]: 93768 : {RPCResult::Type::STR_HEX, "hex", "The raw signature script bytes, hex-encoded"},
373 : : }},
374 [ + - + - ]: 93768 : {RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "",
375 : : {
376 [ + - + - ]: 93768 : {RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"},
377 : : }},
378 [ + - + - : 890796 : };
- + + + +
+ + + - -
- - - - ]
379 [ + + ]: 46884 : if (opts.prevout) {
380 : 35164 : vin_inner.emplace_back(
381 [ + - ]: 17582 : RPCResult::Type::OBJ, "prevout", opts.prevout_optional, prevout_doc,
382 : 17582 : std::vector<RPCResult>{
383 [ + - + - ]: 35164 : {RPCResult::Type::BOOL, "generated", "Coinbase or not"},
384 [ + - + - ]: 35164 : {RPCResult::Type::NUM, "height", "The height of the prevout"},
385 [ + - + - ]: 35164 : {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
386 [ + - + - : 35164 : {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
+ - ]
387 [ + - + + : 158238 : }
- - ]
388 : : );
389 : : }
390 [ + - ]: 46884 : vin_inner.emplace_back(RPCResult::Type::NUM, "sequence", "The script sequence number");
391 : :
392 [ + + ]: 46884 : if (opts.vin_inner_elision) {
393 [ - + + - ]: 52746 : vin_inner = ElideGroup(std::move(vin_inner), *opts.vin_inner_elision);
394 [ + - ]: 17582 : if (opts.prevout) {
395 : : // prevout remains visible even when other fields are elided
396 : 17582 : std::vector<RPCResult> new_vin;
397 [ - + + - ]: 17582 : new_vin.reserve(vin_inner.size());
398 [ + + ]: 140656 : for (const auto& r : vin_inner) {
399 [ + + ]: 123074 : if (r.m_key_name == "prevout") {
400 [ + - ]: 17582 : RPCResultOptions unopts = r.m_opts;
401 : 17582 : unopts.print_elision = HelpElisionNone{};
402 [ + - ]: 17582 : new_vin.emplace_back(r, std::move(unopts));
403 : 17582 : } else {
404 [ + - ]: 105492 : new_vin.push_back(r);
405 : : }
406 : : }
407 : 17582 : vin_inner = std::move(new_vin);
408 : 17582 : }
409 : : }
410 : :
411 : 46884 : auto fields = std::vector<RPCResult>{
412 [ + - - + ]: 46884 : {RPCResult::Type::STR_HEX, "txid", opts.txid_field_doc},
413 [ + - + - ]: 93768 : {RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
414 [ + - + - ]: 93768 : {RPCResult::Type::NUM, "size", "The serialized transaction size"},
415 [ + - + - ]: 93768 : {RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
416 [ + - + - ]: 93768 : {RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"},
417 [ + - + - ]: 93768 : {RPCResult::Type::NUM, "version", "The version"},
418 [ + - + - ]: 93768 : {RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
419 [ + - + - ]: 93768 : {RPCResult::Type::ARR, "vin", "",
420 : : {
421 [ + - + + : 111350 : {RPCResult::Type::OBJ, "", opts.vin_inner_elision ? vin_item_doc : "", std::move(vin_inner)},
+ - + - ]
422 : : }},
423 [ + - + - ]: 93768 : {RPCResult::Type::ARR, "vout", "",
424 : : {
425 [ + - + - : 421956 : {RPCResult::Type::OBJ, "", "", Cat(
+ - + - +
+ - - ]
426 : : {
427 [ + - + - ]: 93768 : {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
428 [ + - + - ]: 93768 : {RPCResult::Type::NUM, "n", "index"},
429 [ + - + - : 93768 : {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
+ - ]
430 : : },
431 [ + + + - : 96434 : opts.wallet ?
+ + + + -
- - - ]
432 [ + - + - : 52216 : std::vector<RPCResult>{{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} :
+ + + + +
+ - - - -
- - ]
433 : : std::vector<RPCResult>{}
434 : : )},
435 : : }},
436 [ + - + - : 1125216 : };
- + + + +
+ + + - -
- - - - ]
437 : :
438 [ + + + - ]: 46884 : if (opts.fee) fields.emplace_back(RPCResult::Type::NUM, "fee", /*optional=*/true, fee_doc);
439 [ + + + - ]: 46884 : if (opts.hex) fields.emplace_back(RPCResult::Type::STR_HEX, "hex", "The hex-encoded transaction data");
440 : :
441 [ + + ]: 46884 : if (opts.elision_mode != ElisionMode::None) {
442 : 32965 : const bool silent = opts.elision_mode == ElisionMode::Silent;
443 : 32965 : std::vector<RPCResult> new_fields;
444 [ - + + - ]: 32965 : new_fields.reserve(fields.size());
445 : 32965 : bool first = true;
446 [ + + ]: 373978 : for (const auto& f : fields) {
447 [ + + + + ]: 341013 : if (!silent && f.m_key_name == "fee") {
448 [ + - ]: 11082 : new_fields.push_back(f);
449 : 11082 : continue;
450 : : }
451 [ + + + + ]: 329931 : if (f.m_key_name == "vin" && opts.vin_inner_elision) {
452 [ + - ]: 17582 : new_fields.push_back(f);
453 : 17582 : continue;
454 : : }
455 [ + + ]: 312349 : if (!silent && first) {
456 [ + - ]: 15383 : RPCResultOptions eopts = f.m_opts;
457 [ + - ]: 15383 : eopts.print_elision = opts.elision_summary.value_or("");
458 [ + - ]: 15383 : new_fields.emplace_back(f, std::move(eopts));
459 : 15383 : first = false;
460 : 15383 : } else {
461 [ + - ]: 296966 : RPCResultOptions eopts = f.m_opts;
462 : 296966 : eopts.print_elision = HelpElisionSkip{};
463 [ + - ]: 296966 : new_fields.emplace_back(f, std::move(eopts));
464 : 296966 : }
465 : : }
466 : 32965 : fields = std::move(new_fields);
467 : 32965 : }
468 : :
469 : 93768 : return fields;
470 [ + - + - : 2299986 : }
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ + - - -
- - - - -
- - - - ]
|