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