Bitcoin Core 30.99.0
P2P Digital Currency
core_io.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <core_io.h>
6
7#include <addresstype.h>
8#include <coins.h>
9#include <consensus/amount.h>
10#include <consensus/consensus.h>
12#include <crypto/hex_base.h>
13#include <key_io.h>
14// IWYU incorrectly suggests replacing this header
15// with forward declarations.
16// See https://github.com/include-what-you-use/include-what-you-use/issues/1886.
17#include <primitives/block.h> // IWYU pragma: keep
19#include <script/descriptor.h>
20#include <script/interpreter.h>
21#include <script/script.h>
23#include <script/solver.h>
24#include <serialize.h>
25#include <streams.h>
26#include <tinyformat.h>
27#include <uint256.h>
28#include <undo.h>
29#include <univalue.h>
30#include <util/check.h>
31#include <util/result.h>
32#include <util/strencodings.h>
33#include <util/string.h>
34#include <util/translation.h>
35
36#include <algorithm>
37#include <compare>
38#include <cstdint>
39#include <exception>
40#include <functional>
41#include <map>
42#include <memory>
43#include <optional>
44#include <span>
45#include <stdexcept>
46#include <string>
47#include <utility>
48#include <vector>
49
51
52namespace {
53class OpCodeParser
54{
55private:
56 std::map<std::string, opcodetype> mapOpNames;
57
58public:
59 OpCodeParser()
60 {
61 for (unsigned int op = 0; op <= MAX_OPCODE; ++op) {
62 // Allow OP_RESERVED to get into mapOpNames
63 if (op < OP_NOP && op != OP_RESERVED) {
64 continue;
65 }
66
67 std::string strName = GetOpName(static_cast<opcodetype>(op));
68 if (strName == "OP_UNKNOWN") {
69 continue;
70 }
71 mapOpNames[strName] = static_cast<opcodetype>(op);
72 // Convenience: OP_ADD and just ADD are both recognized:
73 if (strName.starts_with("OP_")) {
74 mapOpNames[strName.substr(3)] = static_cast<opcodetype>(op);
75 }
76 }
77 }
78 opcodetype Parse(const std::string& s) const
79 {
80 auto it = mapOpNames.find(s);
81 if (it == mapOpNames.end()) throw std::runtime_error("script parse error: unknown opcode");
82 return it->second;
83 }
84};
85
86opcodetype ParseOpCode(const std::string& s)
87{
88 static const OpCodeParser ocp;
89 return ocp.Parse(s);
90}
91
92} // namespace
93
94CScript ParseScript(const std::string& s)
95{
96 CScript result;
97
98 std::vector<std::string> words = SplitString(s, " \t\n");
99
100 for (const std::string& w : words) {
101 if (w.empty()) {
102 // Empty string, ignore. (SplitString doesn't combine multiple separators)
103 } else if (std::all_of(w.begin(), w.end(), ::IsDigit) ||
104 (w.front() == '-' && w.size() > 1 && std::all_of(w.begin() + 1, w.end(), ::IsDigit)))
105 {
106 // Number
107 const auto num{ToIntegral<int64_t>(w)};
108
109 // limit the range of numbers ParseScript accepts in decimal
110 // since numbers outside -0xFFFFFFFF...0xFFFFFFFF are illegal in scripts
111 if (!num.has_value() || num > int64_t{0xffffffff} || num < -1 * int64_t{0xffffffff}) {
112 throw std::runtime_error("script parse error: decimal numeric value only allowed in the "
113 "range -0xFFFFFFFF...0xFFFFFFFF");
114 }
115
116 result << num.value();
117 } else if (w.starts_with("0x") && w.size() > 2 && IsHex(std::string(w.begin() + 2, w.end()))) {
118 // Raw hex data, inserted NOT pushed onto stack:
119 std::vector<unsigned char> raw = ParseHex(std::string(w.begin() + 2, w.end()));
120 result.insert(result.end(), raw.begin(), raw.end());
121 } else if (w.size() >= 2 && w.front() == '\'' && w.back() == '\'') {
122 // Single-quoted string, pushed as data. NOTE: this is poor-man's
123 // parsing, spaces/tabs/newlines in single-quoted strings won't work.
124 std::vector<unsigned char> value(w.begin() + 1, w.end() - 1);
125 result << value;
126 } else {
127 // opcode, e.g. OP_ADD or ADD:
128 result << ParseOpCode(w);
129 }
130 }
131
132 return result;
133}
134
137{
138 // Check input scripts for non-coinbase txs
139 if (!CTransaction(tx).IsCoinBase()) {
140 for (unsigned int i = 0; i < tx.vin.size(); i++) {
141 if (!tx.vin[i].scriptSig.HasValidOps() || tx.vin[i].scriptSig.size() > MAX_SCRIPT_SIZE) {
142 return false;
143 }
144 }
145 }
146 // Check output scripts
147 for (unsigned int i = 0; i < tx.vout.size(); i++) {
148 if (!tx.vout[i].scriptPubKey.HasValidOps() || tx.vout[i].scriptPubKey.size() > MAX_SCRIPT_SIZE) {
149 return false;
150 }
151 }
152
153 return true;
154}
155
156static bool DecodeTx(CMutableTransaction& tx, const std::vector<unsigned char>& tx_data, bool try_no_witness, bool try_witness)
157{
158 // General strategy:
159 // - Decode both with extended serialization (which interprets the 0x0001 tag as a marker for
160 // the presence of witnesses) and with legacy serialization (which interprets the tag as a
161 // 0-input 1-output incomplete transaction).
162 // - Restricted by try_no_witness (which disables legacy if false) and try_witness (which
163 // disables extended if false).
164 // - Ignore serializations that do not fully consume the hex string.
165 // - If neither succeeds, fail.
166 // - If only one succeeds, return that one.
167 // - If both decode attempts succeed:
168 // - If only one passes the CheckTxScriptsSanity check, return that one.
169 // - If neither or both pass CheckTxScriptsSanity, return the extended one.
170
171 CMutableTransaction tx_extended, tx_legacy;
172 bool ok_extended = false, ok_legacy = false;
173
174 // Try decoding with extended serialization support, and remember if the result successfully
175 // consumes the entire input.
176 if (try_witness) {
177 DataStream ssData(tx_data);
178 try {
179 ssData >> TX_WITH_WITNESS(tx_extended);
180 if (ssData.empty()) ok_extended = true;
181 } catch (const std::exception&) {
182 // Fall through.
183 }
184 }
185
186 // Optimization: if extended decoding succeeded and the result passes CheckTxScriptsSanity,
187 // don't bother decoding the other way.
188 if (ok_extended && CheckTxScriptsSanity(tx_extended)) {
189 tx = std::move(tx_extended);
190 return true;
191 }
192
193 // Try decoding with legacy serialization, and remember if the result successfully consumes the entire input.
194 if (try_no_witness) {
195 DataStream ssData(tx_data);
196 try {
197 ssData >> TX_NO_WITNESS(tx_legacy);
198 if (ssData.empty()) ok_legacy = true;
199 } catch (const std::exception&) {
200 // Fall through.
201 }
202 }
203
204 // If legacy decoding succeeded and passes CheckTxScriptsSanity, that's our answer, as we know
205 // at this point that extended decoding either failed or doesn't pass the sanity check.
206 if (ok_legacy && CheckTxScriptsSanity(tx_legacy)) {
207 tx = std::move(tx_legacy);
208 return true;
209 }
210
211 // If extended decoding succeeded, and neither decoding passes sanity, return the extended one.
212 if (ok_extended) {
213 tx = std::move(tx_extended);
214 return true;
215 }
216
217 // If legacy decoding succeeded and extended didn't, return the legacy one.
218 if (ok_legacy) {
219 tx = std::move(tx_legacy);
220 return true;
221 }
222
223 // If none succeeded, we failed.
224 return false;
225}
226
227bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness, bool try_witness)
228{
229 if (!IsHex(hex_tx)) {
230 return false;
231 }
232
233 std::vector<unsigned char> txData(ParseHex(hex_tx));
234 return DecodeTx(tx, txData, try_no_witness, try_witness);
235}
236
237bool DecodeHexBlockHeader(CBlockHeader& header, const std::string& hex_header)
238{
239 if (!IsHex(hex_header)) return false;
240
241 const std::vector<unsigned char> header_data{ParseHex(hex_header)};
242 DataStream ser_header{header_data};
243 try {
244 ser_header >> header;
245 } catch (const std::exception&) {
246 return false;
247 }
248 return true;
249}
250
251bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
252{
253 if (!IsHex(strHexBlk))
254 return false;
255
256 std::vector<unsigned char> blockData(ParseHex(strHexBlk));
257 DataStream ssBlock(blockData);
258 try {
259 ssBlock >> TX_WITH_WITNESS(block);
260 }
261 catch (const std::exception&) {
262 return false;
263 }
264
265 return true;
266}
267
268util::Result<int> SighashFromStr(const std::string& sighash)
269{
270 static const std::map<std::string, int> map_sighash_values = {
271 {std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
272 {std::string("ALL"), int(SIGHASH_ALL)},
273 {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
274 {std::string("NONE"), int(SIGHASH_NONE)},
275 {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
276 {std::string("SINGLE"), int(SIGHASH_SINGLE)},
277 {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
278 };
279 const auto& it = map_sighash_values.find(sighash);
280 if (it != map_sighash_values.end()) {
281 return it->second;
282 } else {
283 return util::Error{Untranslated("'" + sighash + "' is not a valid sighash parameter.")};
284 }
285}
286
288{
289 static_assert(COIN > 1);
290 int64_t quotient = amount / COIN;
291 int64_t remainder = amount % COIN;
292 if (amount < 0) {
293 quotient = -quotient;
294 remainder = -remainder;
295 }
297 strprintf("%s%d.%08d", amount < 0 ? "-" : "", quotient, remainder));
298}
299
300std::string FormatScript(const CScript& script)
301{
302 std::string ret;
303 CScript::const_iterator it = script.begin();
304 opcodetype op;
305 while (it != script.end()) {
307 std::vector<unsigned char> vch;
308 if (script.GetOp(it, op, vch)) {
309 if (op == OP_0) {
310 ret += "0 ";
311 continue;
312 } else if ((op >= OP_1 && op <= OP_16) || op == OP_1NEGATE) {
313 ret += strprintf("%i ", op - OP_1NEGATE - 1);
314 continue;
315 } else if (op >= OP_NOP && op <= OP_NOP10) {
316 std::string str(GetOpName(op));
317 if (str.substr(0, 3) == std::string("OP_")) {
318 ret += str.substr(3, std::string::npos) + " ";
319 continue;
320 }
321 }
322 if (vch.size() > 0) {
323 ret += strprintf("0x%x 0x%x ", HexStr(std::vector<uint8_t>(it2, it - vch.size())),
324 HexStr(std::vector<uint8_t>(it - vch.size(), it)));
325 } else {
326 ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, it)));
327 }
328 continue;
329 }
330 ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, script.end())));
331 break;
332 }
333 return ret.substr(0, ret.empty() ? ret.npos : ret.size() - 1);
334}
335
336const std::map<unsigned char, std::string> mapSigHashTypes = {
337 {static_cast<unsigned char>(SIGHASH_ALL), std::string("ALL")},
338 {static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_ANYONECANPAY), std::string("ALL|ANYONECANPAY")},
339 {static_cast<unsigned char>(SIGHASH_NONE), std::string("NONE")},
340 {static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_ANYONECANPAY), std::string("NONE|ANYONECANPAY")},
341 {static_cast<unsigned char>(SIGHASH_SINGLE), std::string("SINGLE")},
342 {static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY")},
343};
344
345std::string SighashToStr(unsigned char sighash_type)
346{
347 const auto& it = mapSigHashTypes.find(sighash_type);
348 if (it == mapSigHashTypes.end()) return "";
349 return it->second;
350}
351
359std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
360{
361 std::string str;
362 opcodetype opcode;
363 std::vector<unsigned char> vch;
364 CScript::const_iterator pc = script.begin();
365 while (pc < script.end()) {
366 if (!str.empty()) {
367 str += " ";
368 }
369 if (!script.GetOp(pc, opcode, vch)) {
370 str += "[error]";
371 return str;
372 }
373 if (0 <= opcode && opcode <= OP_PUSHDATA4) {
374 if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) {
375 str += strprintf("%d", CScriptNum(vch, false).getint());
376 } else {
377 // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
378 if (fAttemptSighashDecode && !script.IsUnspendable()) {
379 std::string strSigHashDecode;
380 // goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig.
381 // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
382 // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
383 // checks in CheckSignatureEncoding.
385 const unsigned char chSigHashType = vch.back();
386 const auto it = mapSigHashTypes.find(chSigHashType);
387 if (it != mapSigHashTypes.end()) {
388 strSigHashDecode = "[" + it->second + "]";
389 vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
390 }
391 }
392 str += HexStr(vch) + strSigHashDecode;
393 } else {
394 str += HexStr(vch);
395 }
396 }
397 } else {
398 str += GetOpName(opcode);
399 }
400 }
401 return str;
402}
403
404std::string EncodeHexTx(const CTransaction& tx)
405{
406 DataStream ssTx;
407 ssTx << TX_WITH_WITNESS(tx);
408 return HexStr(ssTx);
409}
410
411void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address, const SigningProvider* provider)
412{
413 CTxDestination address;
414
415 out.pushKV("asm", ScriptToAsmStr(script));
416 if (include_address) {
417 out.pushKV("desc", InferDescriptor(script, provider ? *provider : DUMMY_SIGNING_PROVIDER)->ToString());
418 }
419 if (include_hex) {
420 out.pushKV("hex", HexStr(script));
421 }
422
423 std::vector<std::vector<unsigned char>> solns;
424 const TxoutType type{Solver(script, solns)};
425
426 if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
427 out.pushKV("address", EncodeDestination(address));
428 }
429 out.pushKV("type", GetTxnOutputType(type));
430}
431
432void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex, const CTxUndo* txundo, TxVerbosity verbosity, std::function<bool(const CTxOut&)> is_change_func)
433{
435
436 entry.pushKV("txid", tx.GetHash().GetHex());
437 entry.pushKV("hash", tx.GetWitnessHash().GetHex());
438 entry.pushKV("version", tx.version);
439 entry.pushKV("size", tx.GetTotalSize());
441 entry.pushKV("weight", GetTransactionWeight(tx));
442 entry.pushKV("locktime", (int64_t)tx.nLockTime);
443
445 vin.reserve(tx.vin.size());
446
447 // If available, use Undo data to calculate the fee. Note that txundo == nullptr
448 // for coinbase transactions and for transactions where undo data is unavailable.
449 const bool have_undo = txundo != nullptr;
450 CAmount amt_total_in = 0;
451 CAmount amt_total_out = 0;
452
453 for (unsigned int i = 0; i < tx.vin.size(); i++) {
454 const CTxIn& txin = tx.vin[i];
456 if (tx.IsCoinBase()) {
457 in.pushKV("coinbase", HexStr(txin.scriptSig));
458 } else {
459 in.pushKV("txid", txin.prevout.hash.GetHex());
460 in.pushKV("vout", (int64_t)txin.prevout.n);
462 o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
463 o.pushKV("hex", HexStr(txin.scriptSig));
464 in.pushKV("scriptSig", std::move(o));
465 }
466 if (!tx.vin[i].scriptWitness.IsNull()) {
467 UniValue txinwitness(UniValue::VARR);
468 txinwitness.reserve(tx.vin[i].scriptWitness.stack.size());
469 for (const auto& item : tx.vin[i].scriptWitness.stack) {
470 txinwitness.push_back(HexStr(item));
471 }
472 in.pushKV("txinwitness", std::move(txinwitness));
473 }
474 if (have_undo) {
475 const Coin& prev_coin = txundo->vprevout[i];
476 const CTxOut& prev_txout = prev_coin.out;
477
478 amt_total_in += prev_txout.nValue;
479
480 if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) {
481 UniValue o_script_pub_key(UniValue::VOBJ);
482 ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true);
483
485 p.pushKV("generated", bool(prev_coin.fCoinBase));
486 p.pushKV("height", uint64_t(prev_coin.nHeight));
487 p.pushKV("value", ValueFromAmount(prev_txout.nValue));
488 p.pushKV("scriptPubKey", std::move(o_script_pub_key));
489 in.pushKV("prevout", std::move(p));
490 }
491 }
492 in.pushKV("sequence", (int64_t)txin.nSequence);
493 vin.push_back(std::move(in));
494 }
495 entry.pushKV("vin", std::move(vin));
496
498 vout.reserve(tx.vout.size());
499 for (unsigned int i = 0; i < tx.vout.size(); i++) {
500 const CTxOut& txout = tx.vout[i];
501
503
504 out.pushKV("value", ValueFromAmount(txout.nValue));
505 out.pushKV("n", (int64_t)i);
506
508 ScriptToUniv(txout.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
509 out.pushKV("scriptPubKey", std::move(o));
510
511 if (is_change_func && is_change_func(txout)) {
512 out.pushKV("ischange", true);
513 }
514
515 vout.push_back(std::move(out));
516
517 if (have_undo) {
518 amt_total_out += txout.nValue;
519 }
520 }
521 entry.pushKV("vout", std::move(vout));
522
523 if (have_undo) {
524 const CAmount fee = amt_total_in - amt_total_out;
526 entry.pushKV("fee", ValueFromAmount(fee));
527 }
528
529 if (!block_hash.IsNull()) {
530 entry.pushKV("blockhash", block_hash.GetHex());
531 }
532
533 if (include_hex) {
534 entry.pushKV("hex", EncodeHexTx(tx)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction".
535 }
536}
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
Definition: addresstype.cpp:49
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:143
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:27
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
int ret
#define CHECK_NONFATAL(condition)
Identity function.
Definition: check.h:109
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:22
Definition: block.h:69
uint32_t n
Definition: transaction.h:32
Txid hash
Definition: transaction.h:31
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
const uint32_t nLockTime
Definition: transaction.h:294
const std::vector< CTxOut > vout
Definition: transaction.h:292
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
Definition: transaction.h:329
unsigned int GetTotalSize() const
Get the total transaction size in bytes, including witness data.
bool IsCoinBase() const
Definition: transaction.h:341
const Txid & GetHash() const LIFETIMEBOUND
Definition: transaction.h:328
const uint32_t version
Definition: transaction.h:293
const std::vector< CTxIn > vin
Definition: transaction.h:291
An input of a transaction.
Definition: transaction.h:62
uint32_t nSequence
Definition: transaction.h:66
CScript scriptSig
Definition: transaction.h:65
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
Undo information for a CTransaction.
Definition: undo.h:53
std::vector< Coin > vprevout
Definition: undo.h:56
A UTXO entry.
Definition: coins.h:33
CTxOut out
unspent transaction output
Definition: coins.h:36
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition: coins.h:42
unsigned int fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:39
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:130
bool empty() const
Definition: streams.h:165
An interface to be implemented by keystores that support signing.
void push_back(UniValue val)
Definition: univalue.cpp:104
@ VOBJ
Definition: univalue.h:24
@ VARR
Definition: univalue.h:24
@ VNUM
Definition: univalue.h:24
void reserve(size_t new_cap)
Definition: univalue.cpp:243
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
constexpr bool IsNull() const
Definition: uint256.h:48
std::string GetHex() const
Definition: uint256.cpp:11
iterator end()
Definition: prevector.h:257
iterator insert(iterator pos, const T &value)
Definition: prevector.h:307
std::string GetHex() const
256-bit opaque blob.
Definition: uint256.h:195
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
Definition: client.cpp:393
static int32_t GetTransactionWeight(const CTransaction &tx)
Definition: validation.h:132
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_io.cpp:404
std::string SighashToStr(unsigned char sighash_type)
Definition: core_io.cpp:345
CScript ParseScript(const std::string &s)
Definition: core_io.cpp:94
std::string FormatScript(const CScript &script)
Definition: core_io.cpp:300
static bool CheckTxScriptsSanity(const CMutableTransaction &tx)
Check that all of the input and output scripts of a transaction contain valid opcodes.
Definition: core_io.cpp:136
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness, bool try_witness)
Definition: core_io.cpp:227
void ScriptToUniv(const CScript &script, UniValue &out, bool include_hex, bool include_address, const SigningProvider *provider)
Definition: core_io.cpp:411
bool DecodeHexBlockHeader(CBlockHeader &header, const std::string &hex_header)
Definition: core_io.cpp:237
util::Result< int > SighashFromStr(const std::string &sighash)
Definition: core_io.cpp:268
void TxToUniv(const CTransaction &tx, const uint256 &block_hash, UniValue &entry, bool include_hex, const CTxUndo *txundo, TxVerbosity verbosity, std::function< bool(const CTxOut &)> is_change_func)
Definition: core_io.cpp:432
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
Definition: core_io.cpp:359
static bool DecodeTx(CMutableTransaction &tx, const std::vector< unsigned char > &tx_data, bool try_no_witness, bool try_witness)
Definition: core_io.cpp:156
const std::map< unsigned char, std::string > mapSigHashTypes
Definition: core_io.cpp:336
bool DecodeHexBlk(CBlock &block, const std::string &strHexBlk)
Definition: core_io.cpp:251
UniValue ValueFromAmount(const CAmount amount)
Definition: core_io.cpp:287
TxVerbosity
Verbose level for block's transaction.
Definition: core_io.h:28
@ SHOW_DETAILS_AND_PREVOUT
The same as previous option with information about prevouts if available.
@ SHOW_DETAILS
Include TXID, inputs, outputs, and other common block's transaction information.
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
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, script_verify_flags flags, ScriptError *serror)
@ SIGHASH_ANYONECANPAY
Definition: interpreter.h:34
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
Definition: interpreter.h:36
@ SIGHASH_ALL
Definition: interpreter.h:31
@ SIGHASH_NONE
Definition: interpreter.h:32
@ SIGHASH_SINGLE
Definition: interpreter.h:33
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:294
uint64_t fee
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:148
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:245
static constexpr TransactionSerParams TX_NO_WITNESS
Definition: transaction.h:181
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:180
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible.
std::string GetOpName(opcodetype opcode)
Definition: script.cpp:18
static const unsigned int MAX_OPCODE
Definition: script.h:216
static const int MAX_SCRIPT_SIZE
Definition: script.h:40
opcodetype
Script opcodes.
Definition: script.h:74
@ OP_PUSHDATA4
Definition: script.h:80
@ OP_1NEGATE
Definition: script.h:81
@ OP_16
Definition: script.h:99
@ OP_NOP10
Definition: script.h:207
@ OP_NOP
Definition: script.h:102
@ OP_1
Definition: script.h:83
@ OP_0
Definition: script.h:76
@ OP_RESERVED
Definition: script.h:82
const SigningProvider & DUMMY_SIGNING_PROVIDER
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: solver.cpp:141
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Definition: solver.cpp:18
TxoutType
Definition: solver.h:22
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
Definition: strencodings.h:149
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
Definition: strencodings.h:68
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
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:82
bool IsHex(std::string_view str)