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