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