Bitcoin Core  31.0.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>
11 #include <consensus/validation.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
18 #include <primitives/transaction.h>
19 #include <script/descriptor.h>
20 #include <script/interpreter.h>
21 #include <script/script.h>
22 #include <script/signingprovider.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 
50 using util::SplitString;
51 
52 namespace {
53 class OpCodeParser
54 {
55 private:
56  std::map<std::string, opcodetype> mapOpNames;
57 
58 public:
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 
86 opcodetype ParseOpCode(const std::string& s)
87 {
88  static const OpCodeParser ocp;
89  return ocp.Parse(s);
90 }
91 
92 } // namespace
93 
94 CScript ParseScript(const std::string& s)
95 {
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 
156 static 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  SpanReader 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  SpanReader 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 
227 bool 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 
237 bool 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  try {
243  SpanReader{header_data} >> header;
244  } catch (const std::exception&) {
245  return false;
246  }
247  return true;
248 }
249 
250 bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
251 {
252  if (!IsHex(strHexBlk))
253  return false;
254 
255  std::vector<unsigned char> blockData(ParseHex(strHexBlk));
256  try {
257  SpanReader{blockData} >> TX_WITH_WITNESS(block);
258  }
259  catch (const std::exception&) {
260  return false;
261  }
262 
263  return true;
264 }
265 
266 util::Result<int> SighashFromStr(const std::string& sighash)
267 {
268  static const std::map<std::string, int> map_sighash_values = {
269  {std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
270  {std::string("ALL"), int(SIGHASH_ALL)},
271  {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
272  {std::string("NONE"), int(SIGHASH_NONE)},
273  {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
274  {std::string("SINGLE"), int(SIGHASH_SINGLE)},
275  {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
276  };
277  const auto& it = map_sighash_values.find(sighash);
278  if (it != map_sighash_values.end()) {
279  return it->second;
280  } else {
281  return util::Error{Untranslated("'" + sighash + "' is not a valid sighash parameter.")};
282  }
283 }
284 
286 {
287  static_assert(COIN > 1);
288  int64_t quotient = amount / COIN;
289  int64_t remainder = amount % COIN;
290  if (amount < 0) {
291  quotient = -quotient;
292  remainder = -remainder;
293  }
294  return UniValue(UniValue::VNUM,
295  strprintf("%s%d.%08d", amount < 0 ? "-" : "", quotient, remainder));
296 }
297 
298 std::string FormatScript(const CScript& script)
299 {
300  std::string ret;
301  CScript::const_iterator it = script.begin();
302  opcodetype op;
303  while (it != script.end()) {
304  CScript::const_iterator it2 = it;
305  std::vector<unsigned char> vch;
306  if (script.GetOp(it, op, vch)) {
307  if (op == OP_0) {
308  ret += "0 ";
309  continue;
310  } else if ((op >= OP_1 && op <= OP_16) || op == OP_1NEGATE) {
311  ret += strprintf("%i ", op - OP_1NEGATE - 1);
312  continue;
313  } else if (op >= OP_NOP && op <= OP_NOP10) {
314  std::string str(GetOpName(op));
315  if (str.substr(0, 3) == std::string("OP_")) {
316  ret += str.substr(3, std::string::npos) + " ";
317  continue;
318  }
319  }
320  if (vch.size() > 0) {
321  ret += strprintf("0x%x 0x%x ", HexStr(std::vector<uint8_t>(it2, it - vch.size())),
322  HexStr(std::vector<uint8_t>(it - vch.size(), it)));
323  } else {
324  ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, it)));
325  }
326  continue;
327  }
328  ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, script.end())));
329  break;
330  }
331  return ret.substr(0, ret.empty() ? ret.npos : ret.size() - 1);
332 }
333 
334 const std::map<unsigned char, std::string> mapSigHashTypes = {
335  {static_cast<unsigned char>(SIGHASH_ALL), std::string("ALL")},
336  {static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_ANYONECANPAY), std::string("ALL|ANYONECANPAY")},
337  {static_cast<unsigned char>(SIGHASH_NONE), std::string("NONE")},
338  {static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_ANYONECANPAY), std::string("NONE|ANYONECANPAY")},
339  {static_cast<unsigned char>(SIGHASH_SINGLE), std::string("SINGLE")},
340  {static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY")},
341 };
342 
343 std::string SighashToStr(unsigned char sighash_type)
344 {
345  const auto& it = mapSigHashTypes.find(sighash_type);
346  if (it == mapSigHashTypes.end()) return "";
347  return it->second;
348 }
349 
357 std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
358 {
359  std::string str;
360  opcodetype opcode;
361  std::vector<unsigned char> vch;
362  CScript::const_iterator pc = script.begin();
363  while (pc < script.end()) {
364  if (!str.empty()) {
365  str += " ";
366  }
367  if (!script.GetOp(pc, opcode, vch)) {
368  str += "[error]";
369  return str;
370  }
371  if (0 <= opcode && opcode <= OP_PUSHDATA4) {
372  if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) {
373  str += strprintf("%d", CScriptNum(vch, false).getint());
374  } else {
375  // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
376  if (fAttemptSighashDecode && !script.IsUnspendable()) {
377  std::string strSigHashDecode;
378  // goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig.
379  // this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
380  // the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
381  // checks in CheckSignatureEncoding.
382  if (CheckSignatureEncoding(vch, SCRIPT_VERIFY_STRICTENC, nullptr)) {
383  const unsigned char chSigHashType = vch.back();
384  const auto it = mapSigHashTypes.find(chSigHashType);
385  if (it != mapSigHashTypes.end()) {
386  strSigHashDecode = "[" + it->second + "]";
387  vch.pop_back(); // remove the sighash type byte. it will be replaced by the decode.
388  }
389  }
390  str += HexStr(vch) + strSigHashDecode;
391  } else {
392  str += HexStr(vch);
393  }
394  }
395  } else {
396  str += GetOpName(opcode);
397  }
398  }
399  return str;
400 }
401 
402 std::string EncodeHexTx(const CTransaction& tx)
403 {
404  DataStream ssTx;
405  ssTx << TX_WITH_WITNESS(tx);
406  return HexStr(ssTx);
407 }
408 
409 void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address, const SigningProvider* provider)
410 {
411  CTxDestination address;
412 
413  out.pushKV("asm", ScriptToAsmStr(script));
414  if (include_address) {
415  out.pushKV("desc", InferDescriptor(script, provider ? *provider : DUMMY_SIGNING_PROVIDER)->ToString());
416  }
417  if (include_hex) {
418  out.pushKV("hex", HexStr(script));
419  }
420 
421  std::vector<std::vector<unsigned char>> solns;
422  const TxoutType type{Solver(script, solns)};
423 
424  if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
425  out.pushKV("address", EncodeDestination(address));
426  }
427  out.pushKV("type", GetTxnOutputType(type));
428 }
429 
430 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)
431 {
433 
434  entry.pushKV("txid", tx.GetHash().GetHex());
435  entry.pushKV("hash", tx.GetWitnessHash().GetHex());
436  entry.pushKV("version", tx.version);
437  entry.pushKV("size", tx.ComputeTotalSize());
439  entry.pushKV("weight", GetTransactionWeight(tx));
440  entry.pushKV("locktime", tx.nLockTime);
441 
443  vin.reserve(tx.vin.size());
444 
445  // If available, use Undo data to calculate the fee. Note that txundo == nullptr
446  // for coinbase transactions and for transactions where undo data is unavailable.
447  const bool have_undo = txundo != nullptr;
448  CAmount amt_total_in = 0;
449  CAmount amt_total_out = 0;
450 
451  for (unsigned int i = 0; i < tx.vin.size(); i++) {
452  const CTxIn& txin = tx.vin[i];
454  if (tx.IsCoinBase()) {
455  in.pushKV("coinbase", HexStr(txin.scriptSig));
456  } else {
457  in.pushKV("txid", txin.prevout.hash.GetHex());
458  in.pushKV("vout", txin.prevout.n);
460  o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
461  o.pushKV("hex", HexStr(txin.scriptSig));
462  in.pushKV("scriptSig", std::move(o));
463  }
464  if (!tx.vin[i].scriptWitness.IsNull()) {
465  UniValue txinwitness(UniValue::VARR);
466  txinwitness.reserve(tx.vin[i].scriptWitness.stack.size());
467  for (const auto& item : tx.vin[i].scriptWitness.stack) {
468  txinwitness.push_back(HexStr(item));
469  }
470  in.pushKV("txinwitness", std::move(txinwitness));
471  }
472  if (have_undo) {
473  const Coin& prev_coin = txundo->vprevout[i];
474  const CTxOut& prev_txout = prev_coin.out;
475 
476  amt_total_in += prev_txout.nValue;
477 
478  if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) {
479  UniValue o_script_pub_key(UniValue::VOBJ);
480  ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true);
481 
483  p.pushKV("generated", static_cast<bool>(prev_coin.fCoinBase));
484  p.pushKV("height", prev_coin.nHeight);
485  p.pushKV("value", ValueFromAmount(prev_txout.nValue));
486  p.pushKV("scriptPubKey", std::move(o_script_pub_key));
487  in.pushKV("prevout", std::move(p));
488  }
489  }
490  in.pushKV("sequence", txin.nSequence);
491  vin.push_back(std::move(in));
492  }
493  entry.pushKV("vin", std::move(vin));
494 
495  UniValue vout(UniValue::VARR);
496  vout.reserve(tx.vout.size());
497  for (unsigned int i = 0; i < tx.vout.size(); i++) {
498  const CTxOut& txout = tx.vout[i];
499 
501 
502  out.pushKV("value", ValueFromAmount(txout.nValue));
503  out.pushKV("n", i);
504 
506  ScriptToUniv(txout.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
507  out.pushKV("scriptPubKey", std::move(o));
508 
509  if (is_change_func && is_change_func(txout)) {
510  out.pushKV("ischange", true);
511  }
512 
513  vout.push_back(std::move(out));
514 
515  if (have_undo) {
516  amt_total_out += txout.nValue;
517  }
518  }
519  entry.pushKV("vout", std::move(vout));
520 
521  if (have_undo) {
522  const CAmount fee = amt_total_in - amt_total_out;
524  entry.pushKV("fee", ValueFromAmount(fee));
525  }
526 
527  if (!block_hash.IsNull()) {
528  entry.pushKV("blockhash", block_hash.GetHex());
529  }
530 
531  if (include_hex) {
532  entry.pushKV("hex", EncodeHexTx(tx)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction".
533  }
534 }
CAmount nValue
Definition: transaction.h:142
std::string GetHex() const
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:395
void push_back(UniValue val)
Definition: univalue.cpp:103
std::vector< Coin > vprevout
Definition: undo.h:56
int ret
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:149
The same as previous option with information about prevouts if available.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
Definition: strencodings.h:69
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
CScript scriptPubKey
Definition: transaction.h:143
UniValue ValueFromAmount(const CAmount amount)
Definition: core_io.cpp:285
A UTXO entry.
Definition: coins.h:34
Definition: block.h:73
static const int MAX_SCRIPT_SIZE
Definition: script.h:40
TxVerbosity
Verbose level for block&#39;s transaction.
Definition: core_io.h:28
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
Definition: interpreter.h:36
std::vector< CTxIn > vin
Definition: transaction.h:359
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
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:82
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:27
#define CHECK_NONFATAL(condition)
Identity function.
Definition: check.h:109
bool IsHex(std::string_view str)
CTxOut out
unspent transaction output
Definition: coins.h:38
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
Definition: strencodings.h:150
bool DecodeHexBlk(CBlock &block, const std::string &strHexBlk)
Definition: core_io.cpp:250
const std::map< unsigned char, std::string > mapSigHashTypes
Definition: core_io.cpp:334
unsigned int fCoinBase
whether containing transaction was a coinbase
Definition: coins.h:41
Definition: script.h:76
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:430
Definition: script.h:102
static int32_t GetTransactionWeight(const CTransaction &tx)
Definition: validation.h:132
std::string FormatScript(const CScript &script)
Definition: core_io.cpp:298
bool IsCoinBase() const
Definition: transaction.h:341
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
void reserve(size_t new_cap)
Definition: univalue.cpp:242
const std::vector< CTxIn > vin
Definition: transaction.h:291
std::string SighashToStr(unsigned char sighash_type)
Definition: core_io.cpp:343
Minimal stream for reading from an existing byte array by std::span.
Definition: streams.h:82
Definition: script.h:83
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Definition: coins.h:44
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
Definition: addresstype.cpp:49
Include TXID, inputs, outputs, and other common block&#39;s transaction information.
An input of a transaction.
Definition: transaction.h:61
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:132
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, script_verify_flags flags, ScriptError *serror)
const SigningProvider & DUMMY_SIGNING_PROVIDER
Txid hash
Definition: transaction.h:31
uint32_t n
Definition: transaction.h:32
opcodetype
Script opcodes.
Definition: script.h:73
const std::vector< CTxOut > vout
Definition: transaction.h:292
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
Definition: core_io.cpp:357
An output of a transaction.
Definition: transaction.h:139
std::vector< CTxOut > vout
Definition: transaction.h:360
constexpr bool IsNull() const
Definition: uint256.h:48
static bool DecodeTx(CMutableTransaction &tx, const std::vector< unsigned char > &tx_data, bool try_no_witness, bool try_witness)
Definition: core_io.cpp:156
CScript ParseScript(const std::string &s)
Definition: core_io.cpp:94
void ScriptToUniv(const CScript &script, UniValue &out, bool include_hex, bool include_address, const SigningProvider *provider)
Definition: core_io.cpp:409
CScript scriptSig
Definition: transaction.h:65
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Definition: solver.cpp:18
256-bit opaque blob.
Definition: uint256.h:195
TxoutType
Definition: solver.h:22
auto result
Definition: common-types.h:74
An interface to be implemented by keystores that support signing.
std::string GetOpName(opcodetype opcode)
Definition: script.cpp:18
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:125
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:404
uint32_t nSequence
Definition: transaction.h:66
Undo information for a CTransaction.
Definition: undo.h:52
bool DecodeHexBlockHeader(CBlockHeader &header, const std::string &hex_header)
Definition: core_io.cpp:237
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_io.cpp:402
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness, bool try_witness)
Definition: core_io.cpp:227
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:143
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
std::string GetHex() const
Definition: uint256.cpp:11
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:294
A mutable version of CTransaction.
Definition: transaction.h:357
Definition: script.h:99
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:280
util::Result< int > SighashFromStr(const std::string &sighash)
Definition: core_io.cpp:266
static const unsigned int MAX_OPCODE
Definition: script.h:216
COutPoint prevout
Definition: transaction.h:64
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
unsigned int ComputeTotalSize() const
Calculate the total transaction size in bytes, including witness data.
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:26
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
Definition: transaction.h:329
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:246
uint64_t fee
const Txid & GetHash() const LIFETIMEBOUND
Definition: transaction.h:328
const uint32_t nLockTime
Definition: transaction.h:294
static constexpr TransactionSerParams TX_NO_WITNESS
Definition: transaction.h:181
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:180
const uint32_t version
Definition: transaction.h:293
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15