Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
rawtransaction_util.cpp
Go to the documentation of this file.
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
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>
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>
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
36static void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, std::optional<bool> rbf)
37{
38 UniValue inputs;
39 if (inputs_in.isNull()) {
40 inputs = UniValue::VARR;
41 } else {
42 inputs = inputs_in.get_array();
43 }
44
45 for (unsigned int idx = 0; idx < inputs.size(); idx++) {
46 const UniValue& input = inputs[idx];
47 const UniValue& o = input.get_obj();
48
49 Txid txid = Txid::FromUint256(ParseHashO(o, "txid"));
50
51 const UniValue& vout_v = o.find_value("vout");
52 if (!vout_v.isNum())
53 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
54 int nOutput = vout_v.getInt<int>();
55 if (nOutput < 0)
56 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
57
58 uint32_t nSequence;
59
60 if (rbf.value_or(true)) {
61 nSequence = MAX_BIP125_RBF_SEQUENCE; /* CTxIn::SEQUENCE_FINAL - 2 */
62 } else if (rawTx.nLockTime) {
63 nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; /* CTxIn::SEQUENCE_FINAL - 1 */
64 } else {
65 nSequence = CTxIn::SEQUENCE_FINAL;
66 }
67
68 // set the sequence number if passed in the parameters object
69 const UniValue& sequenceObj = o.find_value("sequence");
70 if (sequenceObj.isNum()) {
73 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
74 } else {
75 nSequence = (uint32_t)seqNr64;
76 }
77 }
78
79 CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
80
81 rawTx.vin.push_back(in);
82 }
83}
84
86{
87 if (outputs_in.isNull()) {
88 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, output argument must be non-null");
89 }
90
91 const bool outputs_is_obj = outputs_in.isObject();
93
94 if (!outputs_is_obj) {
95 // Translate array of key-value pairs into dict
97 for (size_t i = 0; i < outputs.size(); ++i) {
98 const UniValue& output = outputs[i];
99 if (!output.isObject()) {
100 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair not an object as expected");
101 }
102 if (output.size() != 1) {
103 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair must contain exactly one key");
104 }
105 outputs_dict.pushKVs(output);
106 }
107 outputs = std::move(outputs_dict);
108 }
109 return outputs;
110}
111
112std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs)
113{
114 // Duplicate checking
115 std::set<CTxDestination> destinations;
116 std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs;
117 bool has_data{false};
118 const auto& keys{outputs.getKeys()};
119 const auto& values{outputs.getValues()};
120 for (size_t i{0}; i < keys.size(); ++i) {
121 const auto& name_{keys[i]};
122 const auto& value{values[i]};
123 if (name_ == "data") {
124 if (has_data) {
125 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, duplicate key: data");
126 }
127 has_data = true;
128 std::vector<unsigned char> data = ParseHexV(value.getValStr(), "Data");
129 CTxDestination destination{CNoDestination{CScript() << OP_RETURN << data}};
130 CAmount amount{0};
131 parsed_outputs.emplace_back(destination, amount);
132 } else {
134 CAmount amount{AmountFromValue(value)};
135 if (!IsValidDestination(destination)) {
136 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + name_);
137 }
138
139 if (!destinations.insert(destination).second) {
140 throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_);
141 }
142 parsed_outputs.emplace_back(destination, amount);
143 }
144 }
145 return parsed_outputs;
146}
147
149{
150 UniValue outputs(UniValue::VOBJ);
151 outputs = NormalizeOutputs(outputs_in);
152
153 std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs = ParseOutputs(outputs);
154 for (const auto& [destination, nAmount] : parsed_outputs) {
155 CScript scriptPubKey = GetScriptForDestination(destination);
156
157 CTxOut out(nAmount, scriptPubKey);
158 rawTx.vout.push_back(out);
159 }
160}
161
163{
165
166 if (!locktime.isNull()) {
167 int64_t nLockTime = locktime.getInt<int64_t>();
169 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
170 rawTx.nLockTime = nLockTime;
171 }
172
174 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, version out of range(%d~%d)", TX_MIN_STANDARD_VERSION, TX_MAX_STANDARD_VERSION));
175 }
176 rawTx.version = version;
177
180
181 if (rbf.has_value() && rbf.value() && rawTx.vin.size() > 0 && !SignalsOptInRBF(CTransaction(rawTx))) {
182 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number(s) contradict replaceable option");
183 }
184
185 return rawTx;
186}
187
189static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::string& strMessage)
190{
192 entry.pushKV("txid", txin.prevout.hash.ToString());
193 entry.pushKV("vout", txin.prevout.n);
194 UniValue witness(UniValue::VARR);
195 for (unsigned int i = 0; i < txin.scriptWitness.stack.size(); i++) {
196 witness.push_back(HexStr(txin.scriptWitness.stack[i]));
197 }
198 entry.pushKV("witness", std::move(witness));
199 entry.pushKV("scriptSig", HexStr(txin.scriptSig));
200 entry.pushKV("sequence", txin.nSequence);
201 entry.pushKV("error", strMessage);
202 vErrorsRet.push_back(std::move(entry));
203}
204
205void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
206{
207 if (!prevTxsUnival.isNull()) {
209 for (unsigned int idx = 0; idx < prevTxs.size(); ++idx) {
210 const UniValue& p = prevTxs[idx];
211 if (!p.isObject()) {
212 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
213 }
214
215 const UniValue& prevOut = p.get_obj();
216
218 {
219 {"txid", UniValueType(UniValue::VSTR)},
220 {"vout", UniValueType(UniValue::VNUM)},
221 {"scriptPubKey", UniValueType(UniValue::VSTR)},
222 });
223
224 Txid txid = Txid::FromUint256(ParseHashO(prevOut, "txid"));
225
226 int nOut = prevOut.find_value("vout").getInt<int>();
227 if (nOut < 0) {
228 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative");
229 }
230
231 COutPoint out(txid, nOut);
232 std::vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
233 CScript scriptPubKey(pkData.begin(), pkData.end());
234
235 {
236 auto coin = coins.find(out);
237 if (coin != coins.end() && !coin->second.IsSpent() && coin->second.out.scriptPubKey != scriptPubKey) {
238 std::string err("Previous output scriptPubKey mismatch:\n");
239 err = err + ScriptToAsmStr(coin->second.out.scriptPubKey) + "\nvs:\n"+
240 ScriptToAsmStr(scriptPubKey);
242 }
244 newcoin.out.scriptPubKey = scriptPubKey;
245 newcoin.out.nValue = MAX_MONEY;
246 if (prevOut.exists("amount")) {
247 newcoin.out.nValue = AmountFromValue(prevOut.find_value("amount"));
248 }
249 newcoin.nHeight = 1;
250 coins[out] = std::move(newcoin);
251 }
252
253 // if redeemScript and private keys were given, add redeemScript to the keystore so it can be signed
254 const bool is_p2sh = scriptPubKey.IsPayToScriptHash();
255 const bool is_p2wsh = scriptPubKey.IsPayToWitnessScriptHash();
256 if (keystore && (is_p2sh || is_p2wsh)) {
258 {
259 {"redeemScript", UniValueType(UniValue::VSTR)},
260 {"witnessScript", UniValueType(UniValue::VSTR)},
261 }, true);
262 const UniValue& rs{prevOut.find_value("redeemScript")};
263 const UniValue& ws{prevOut.find_value("witnessScript")};
264 if (rs.isNull() && ws.isNull()) {
265 throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing redeemScript/witnessScript");
266 }
267
268 // work from witnessScript when possible
269 std::vector<unsigned char> scriptData(!ws.isNull() ? ParseHexV(ws, "witnessScript") : ParseHexV(rs, "redeemScript"));
270 CScript script(scriptData.begin(), scriptData.end());
271 keystore->scripts.emplace(CScriptID(script), script);
272 // Automatically also add the P2WSH wrapped version of the script (to deal with P2SH-P2WSH).
273 // This is done for redeemScript only for compatibility, it is encouraged to use the explicit witnessScript field instead.
276
277 if (!ws.isNull() && !rs.isNull()) {
278 // if both witnessScript and redeemScript are provided,
279 // they should either be the same (for backwards compat),
280 // or the redeemScript should be the encoded form of
281 // the witnessScript (ie, for p2sh-p2wsh)
282 if (ws.get_str() != rs.get_str()) {
283 std::vector<unsigned char> redeemScriptData(ParseHexV(rs, "redeemScript"));
286 throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript does not correspond to witnessScript");
287 }
288 }
289 }
290
291 if (is_p2sh) {
294 if (scriptPubKey == GetScriptForDestination(p2sh)) {
295 // traditional p2sh; arguably an error if
296 // we got here with rs.IsNull(), because
297 // that means the p2sh script was specified
298 // via witnessScript param, but for now
299 // we'll just quietly accept it
300 } else if (scriptPubKey == GetScriptForDestination(p2sh_p2wsh)) {
301 // p2wsh encoded as p2sh; ideally the witness
302 // script was specified in the witnessScript
303 // param, but also support specifying it via
304 // redeemScript param for backwards compat
305 // (in which case ws.IsNull() == true)
306 } else {
307 // otherwise, can't generate scriptPubKey from
308 // either script, so we got unusable parameters
309 throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript/witnessScript does not match scriptPubKey");
310 }
311 } else if (is_p2wsh) {
312 // plain p2wsh; could throw an error if script
313 // was specified by redeemScript rather than
314 // witnessScript (ie, ws.IsNull() == true), but
315 // accept it for backwards compat
317 if (scriptPubKey != GetScriptForDestination(p2wsh)) {
318 throw JSONRPCError(RPC_INVALID_PARAMETER, "redeemScript/witnessScript does not match scriptPubKey");
319 }
320 }
321 }
322 }
323 }
324}
325
326void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result)
327{
328 std::optional<int> nHashType = ParseSighashString(hashType);
329 if (!nHashType) {
331 }
332
333 // Script verification errors
334 std::map<int, bilingual_str> input_errors;
335
336 bool complete = SignTransaction(mtx, keystore, coins, {.sighash_type = *nHashType}, input_errors);
337 SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
338}
339
340void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result)
341{
342 // Make errors UniValue
344 for (const auto& err_pair : input_errors) {
345 if (err_pair.second.original == "Missing amount") {
346 // This particular error needs to be an exception for some reason
347 throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing amount for %s", coins.at(mtx.vin.at(err_pair.first).prevout).out.ToString()));
348 }
349 TxInErrorToJSON(mtx.vin.at(err_pair.first), vErrors, err_pair.second.original);
350 }
351
352 result.pushKV("hex", EncodeHexTx(CTransaction(mtx)));
353 result.pushKV("complete", complete);
354 if (!vErrors.empty()) {
355 if (result.exists("errors")) {
356 vErrors.push_backV(result["errors"].getValues());
357 }
358 result.pushKV("errors", std::move(vErrors));
359 }
360}
361
362std::vector<RPCResult> TxDoc(const TxDocOptions& opts)
363{
364 CHECK_NONFATAL(!opts.fee_doc || opts.fee);
365 CHECK_NONFATAL(!opts.prevout_doc || opts.prevout);
368
369 const std::string fee_doc{opts.fee_doc.value_or(
370 "transaction fee in " + CURRENCY_UNIT + ", omitted if block undo data is not available")};
371 const std::string prevout_doc{opts.prevout_doc.value_or(
372 "The previous output, omitted if block undo data is not available")};
373 const std::string vin_item_doc{opts.vin_item_doc.value_or("utxo being spent")};
374
375 auto vin_inner = std::vector<RPCResult>{
376 {RPCResult::Type::STR_HEX, "coinbase", /*optional=*/true, "The coinbase value (only if coinbase transaction)"},
377 {RPCResult::Type::STR_HEX, "txid", /*optional=*/true, "The transaction id (if not coinbase transaction)"},
378 {RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"},
379 {RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)",
380 {
381 {RPCResult::Type::STR, "asm", "Disassembly of the signature script"},
382 {RPCResult::Type::STR_HEX, "hex", "The raw signature script bytes, hex-encoded"},
383 }},
384 {RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "",
385 {
386 {RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"},
387 }},
388 };
389 if (opts.prevout) {
390 vin_inner.emplace_back(
391 RPCResult::Type::OBJ, "prevout", opts.prevout_optional, prevout_doc,
392 std::vector<RPCResult>{
393 {RPCResult::Type::BOOL, "generated", "Coinbase or not"},
394 {RPCResult::Type::NUM, "height", "The height of the prevout"},
395 {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
396 {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
397 }
398 );
399 }
400 vin_inner.emplace_back(RPCResult::Type::NUM, "sequence", "The script sequence number");
401
402 if (opts.vin_inner_elision) {
403 vin_inner = ElideGroup(std::move(vin_inner), *opts.vin_inner_elision);
404 if (opts.prevout) {
405 // prevout remains visible even when other fields are elided
406 std::vector<RPCResult> new_vin;
407 new_vin.reserve(vin_inner.size());
408 for (const auto& r : vin_inner) {
409 if (r.m_key_name == "prevout") {
410 RPCResultOptions unopts = r.m_opts;
412 new_vin.emplace_back(r, std::move(unopts));
413 } else {
414 new_vin.push_back(r);
415 }
416 }
417 vin_inner = std::move(new_vin);
418 }
419 }
420
421 auto fields = std::vector<RPCResult>{
422 {RPCResult::Type::STR_HEX, "txid", opts.txid_field_doc},
423 {RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"},
424 {RPCResult::Type::NUM, "size", "The serialized transaction size"},
425 {RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"},
426 {RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"},
427 {RPCResult::Type::NUM, "version", "The version"},
428 {RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
429 {RPCResult::Type::ARR, "vin", "",
430 {
431 {RPCResult::Type::OBJ, "", opts.vin_inner_elision ? vin_item_doc : "", std::move(vin_inner)},
432 }},
433 {RPCResult::Type::ARR, "vout", "",
434 {
435 {RPCResult::Type::OBJ, "", "", Cat(
436 {
437 {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
438 {RPCResult::Type::NUM, "n", "index"},
439 {RPCResult::Type::OBJ, "scriptPubKey", "", ScriptPubKeyDoc()},
440 },
441 opts.wallet ?
442 std::vector<RPCResult>{{RPCResult::Type::BOOL, "ischange", /*optional=*/true, "Output script is change (only present if true)"}} :
443 std::vector<RPCResult>{}
444 )},
445 }},
446 };
447
448 if (opts.fee) fields.emplace_back(RPCResult::Type::NUM, "fee", /*optional=*/true, fee_doc);
449 if (opts.hex) fields.emplace_back(RPCResult::Type::STR_HEX, "hex", "The hex-encoded transaction data");
450
451 if (opts.elision_mode != ElisionMode::None) {
452 const bool silent = opts.elision_mode == ElisionMode::Silent;
453 std::vector<RPCResult> new_fields;
454 new_fields.reserve(fields.size());
455 bool first = true;
456 for (const auto& f : fields) {
457 if (!silent && f.m_key_name == "fee") {
458 new_fields.push_back(f);
459 continue;
460 }
461 if (f.m_key_name == "vin" && opts.vin_inner_elision) {
462 new_fields.push_back(f);
463 continue;
464 }
465 if (!silent && first) {
466 RPCResultOptions eopts = f.m_opts;
467 eopts.print_elision = opts.elision_summary.value_or("");
468 new_fields.emplace_back(f, std::move(eopts));
469 first = false;
470 } else {
471 RPCResultOptions eopts = f.m_opts;
473 new_fields.emplace_back(f, std::move(eopts));
474 }
475 }
476 fields = std::move(new_fields);
477 }
478
479 return fields;
480}
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition amount.h:26
int64_t CAmount
Amount in satoshis (Can be negative)
Definition amount.h:12
static CAmount AmountFromValue(const UniValue &value)
#define CHECK_NONFATAL(condition)
Identity function.
Definition check.h:115
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:30
Serialized script, used inside transaction inputs and outputs.
Definition script.h:406
bool IsPayToScriptHash() const
Definition script.cpp:224
bool IsPayToWitnessScriptHash() const
Definition script.cpp:233
A reference to a CScript: the Hash160 of its serialization.
Definition script.h:597
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
Definition transaction.h:63
static constexpr uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
Definition transaction.h:77
static constexpr uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
Definition transaction.h:83
An output of a transaction.
CScript scriptPubKey
A UTXO entry.
Definition coins.h:46
CTxOut out
unspent transaction output
Definition coins.h:49
An interface to be implemented by keystores that support signing.
void push_back(UniValue val)
Definition univalue.cpp:103
const UniValue & find_value(std::string_view key) const
Definition univalue.cpp:232
const UniValue & get_obj() const
size_t size() const
Definition univalue.h:71
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
Int getInt() const
Definition univalue.h:143
const UniValue & get_array() const
bool exists(const std::string &key) const
Definition univalue.h:79
void pushKV(std::string key, UniValue val)
Definition univalue.cpp:125
bool isObject() const
Definition univalue.h:88
void emplace_back(Args &&... args)
Definition prevector.h:383
static transaction_identifier FromUint256(const uint256 &id)
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
std::string EncodeHexTx(const CTransaction &tx)
Definition core_io.cpp:404
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
Definition core_io.cpp:359
const std::string CURRENCY_UNIT
Definition feerate.h:19
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition hex_base.cpp:30
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
Definition interpreter.h:37
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Definition key_io.cpp:316
constexpr decltype(CTransaction::version) TX_MIN_STANDARD_VERSION
Definition policy.h:145
constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION
Definition policy.h:146
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, bilingual_str > &input_errors, UniValue &result)
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
void AddOutputs(CMutableTransaction &rawTx, const UniValue &outputs_in)
Normalize, parse, and add outputs to the transaction.
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, std::optional< bool > rbf, const uint32_t version)
Create a transaction from univalue parameters.
static void AddInputs(CMutableTransaction &rawTx, const UniValue &inputs_in, std::optional< bool > rbf)
Normalize univalue-represented inputs and add them to the transaction.
static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, const std::string &strMessage)
Pushes a JSON object for script verification or signing errors to vErrorsRet.
std::vector< std::pair< CTxDestination, CAmount > > ParseOutputs(const UniValue &outputs)
Parse normalized outputs into destination, amount tuples.
UniValue NormalizeOutputs(const UniValue &outputs_in)
Normalize univalue-represented outputs.
void ParsePrevouts(const UniValue &prevTxsUnival, FlatSigningProvider *keystore, std::map< COutPoint, Coin > &coins)
Parse a prevtxs UniValue array and get the map of coins from it.
std::vector< RPCResult > TxDoc(const TxDocOptions &opts)
Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet.
@ WithSummary
first field carries elision_summary as "...", rest skipped
@ Silent
all top-level fields skipped silently (no "..." line)
@ None
no elision, all top-level fields rendered normally
UniValue JSONRPCError(int code, const std::string &message)
Definition request.cpp:75
@ RPC_TYPE_ERROR
Unexpected type was passed as parameter.
Definition protocol.h:66
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition protocol.h:69
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
Definition protocol.h:71
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
Definition protocol.h:67
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
Definition util.cpp:136
std::vector< RPCResult > ElideGroup(std::vector< RPCResult > fields, std::string summary)
Stamp elision onto an entire vector of RPCResult fields at once.
Definition util.cpp:1431
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
Definition util.cpp:145
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
Definition util.cpp:363
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
Definition util.cpp:132
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
Definition util.cpp:62
std::vector< RPCResult > ScriptPubKeyDoc()
Definition util.cpp:1414
@ OP_RETURN
Definition script.h:112
constexpr uint32_t LOCKTIME_MAX
Definition script.h:54
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
A mutable version of CTransaction.
Controls how an RPCResult is rendered in human-readable help text.field printed normally.
Definition util.h:297
field hidden from help
Definition util.h:298
@ NUM_TIME
Special numeric to denote unix epoch time.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
HelpElision print_elision
Definition util.h:303
std::optional< std::string > prevout_doc
Customize the prevout field's description (only meaningful when prevout is true)
std::optional< std::string > vin_item_doc
Customize the vin item object's description (only meaningful when vin_inner_elision is set)
std::optional< std::string > elision_summary
Summary text shown as "..." required for elision_mode == WithSummary.
std::optional< std::string > vin_inner_elision
Elide vin inner fields but keep vin array with prevout expanded.
bool prevout
Include prevout field.
std::optional< std::string > fee_doc
Customize the fee field's description (only meaningful when fee is true)
ElisionMode elision_mode
Controls top-level field elision in the help.
bool fee
Include fee field.
bool prevout_optional
Mark prevout field as optional (omitted when undo data unavailable)
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
Definition util.h:79
std::vector< uint16_t > keys
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
bool SignalsOptInRBF(const CTransaction &tx)
Check whether the sequence numbers on this transaction are signaling opt-in to replace-by-fee,...
Definition rbf.cpp:11
constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
Definition rbf.h:12
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.
Definition vector.h:34