Bitcoin Core  24.99.0
P2P Digital Currency
bitcoin-tx.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2021 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 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <clientversion.h>
10 #include <coins.h>
11 #include <compat/compat.h>
12 #include <consensus/amount.h>
13 #include <consensus/consensus.h>
14 #include <core_io.h>
15 #include <key_io.h>
16 #include <fs.h>
17 #include <policy/policy.h>
18 #include <primitives/transaction.h>
19 #include <script/script.h>
20 #include <script/sign.h>
21 #include <script/signingprovider.h>
22 #include <univalue.h>
23 #include <util/moneystr.h>
24 #include <util/rbf.h>
25 #include <util/strencodings.h>
26 #include <util/string.h>
27 #include <util/system.h>
28 #include <util/translation.h>
29 
30 #include <cstdio>
31 #include <functional>
32 #include <memory>
33 
34 static bool fCreateBlank;
35 static std::map<std::string,UniValue> registers;
36 static const int CONTINUE_EXECUTION=-1;
37 
38 const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
39 
40 static void SetupBitcoinTxArgs(ArgsManager &argsman)
41 {
42  SetupHelpOptions(argsman);
43 
44  argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
45  argsman.AddArg("-create", "Create new, empty TX.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
46  argsman.AddArg("-json", "Select JSON output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
47  argsman.AddArg("-txid", "Output only the hex-encoded transaction id of the resultant transaction.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
49 
50  argsman.AddArg("delin=N", "Delete input N from TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
51  argsman.AddArg("delout=N", "Delete output N from TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
52  argsman.AddArg("in=TXID:VOUT(:SEQUENCE_NUMBER)", "Add input to TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
53  argsman.AddArg("locktime=N", "Set TX lock time to N", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
54  argsman.AddArg("nversion=N", "Set TX version to N", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
55  argsman.AddArg("outaddr=VALUE:ADDRESS", "Add address-based output to TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
56  argsman.AddArg("outdata=[VALUE:]DATA", "Add data-based output to TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
57  argsman.AddArg("outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", "Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = PUBKEYS. "
58  "Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output. "
59  "Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
60  argsman.AddArg("outpubkey=VALUE:PUBKEY[:FLAGS]", "Add pay-to-pubkey output to TX. "
61  "Optionally add the \"W\" flag to produce a pay-to-witness-pubkey-hash output. "
62  "Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
63  argsman.AddArg("outscript=VALUE:SCRIPT[:FLAGS]", "Add raw script output to TX. "
64  "Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output. "
65  "Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
66  argsman.AddArg("replaceable(=N)", "Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
67  argsman.AddArg("sign=SIGHASH-FLAGS", "Add zero or more signatures to transaction. "
68  "This command requires JSON registers:"
69  "prevtxs=JSON object, "
70  "privatekeys=JSON object. "
71  "See signrawtransactionwithkey docs for format of sighash flags, JSON objects.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
72 
73  argsman.AddArg("load=NAME:FILENAME", "Load JSON file FILENAME into register NAME", ArgsManager::ALLOW_ANY, OptionsCategory::REGISTER_COMMANDS);
74  argsman.AddArg("set=NAME:JSON-STRING", "Set register NAME to given JSON-STRING", ArgsManager::ALLOW_ANY, OptionsCategory::REGISTER_COMMANDS);
75 }
76 
77 //
78 // This function returns either one of EXIT_ codes when it's expected to stop the process or
79 // CONTINUE_EXECUTION when it's expected to continue further.
80 //
81 static int AppInitRawTx(int argc, char* argv[])
82 {
84  std::string error;
85  if (!gArgs.ParseParameters(argc, argv, error)) {
86  tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);
87  return EXIT_FAILURE;
88  }
89 
90  // Check for chain settings (Params() calls are only valid after this clause)
91  try {
93  } catch (const std::exception& e) {
94  tfm::format(std::cerr, "Error: %s\n", e.what());
95  return EXIT_FAILURE;
96  }
97 
98  fCreateBlank = gArgs.GetBoolArg("-create", false);
99 
100  if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
101  // First part of help message is specific to this utility
102  std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n";
103 
104  if (gArgs.IsArgSet("-version")) {
105  strUsage += FormatParagraph(LicenseInfo());
106  } else {
107  strUsage += "\n"
108  "Usage: bitcoin-tx [options] <hex-tx> [commands] Update hex-encoded bitcoin transaction\n"
109  "or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n"
110  "\n";
111  strUsage += gArgs.GetHelpMessage();
112  }
113 
114  tfm::format(std::cout, "%s", strUsage);
115 
116  if (argc < 2) {
117  tfm::format(std::cerr, "Error: too few parameters\n");
118  return EXIT_FAILURE;
119  }
120  return EXIT_SUCCESS;
121  }
122  return CONTINUE_EXECUTION;
123 }
124 
125 static void RegisterSetJson(const std::string& key, const std::string& rawJson)
126 {
127  UniValue val;
128  if (!val.read(rawJson)) {
129  std::string strErr = "Cannot parse JSON for key " + key;
130  throw std::runtime_error(strErr);
131  }
132 
133  registers[key] = val;
134 }
135 
136 static void RegisterSet(const std::string& strInput)
137 {
138  // separate NAME:VALUE in string
139  size_t pos = strInput.find(':');
140  if ((pos == std::string::npos) ||
141  (pos == 0) ||
142  (pos == (strInput.size() - 1)))
143  throw std::runtime_error("Register input requires NAME:VALUE");
144 
145  std::string key = strInput.substr(0, pos);
146  std::string valStr = strInput.substr(pos + 1, std::string::npos);
147 
148  RegisterSetJson(key, valStr);
149 }
150 
151 static void RegisterLoad(const std::string& strInput)
152 {
153  // separate NAME:FILENAME in string
154  size_t pos = strInput.find(':');
155  if ((pos == std::string::npos) ||
156  (pos == 0) ||
157  (pos == (strInput.size() - 1)))
158  throw std::runtime_error("Register load requires NAME:FILENAME");
159 
160  std::string key = strInput.substr(0, pos);
161  std::string filename = strInput.substr(pos + 1, std::string::npos);
162 
163  FILE *f = fsbridge::fopen(filename.c_str(), "r");
164  if (!f) {
165  std::string strErr = "Cannot open file " + filename;
166  throw std::runtime_error(strErr);
167  }
168 
169  // load file chunks into one big buffer
170  std::string valStr;
171  while ((!feof(f)) && (!ferror(f))) {
172  char buf[4096];
173  int bread = fread(buf, 1, sizeof(buf), f);
174  if (bread <= 0)
175  break;
176 
177  valStr.insert(valStr.size(), buf, bread);
178  }
179 
180  int error = ferror(f);
181  fclose(f);
182 
183  if (error) {
184  std::string strErr = "Error reading file " + filename;
185  throw std::runtime_error(strErr);
186  }
187 
188  // evaluate as JSON buffer register
189  RegisterSetJson(key, valStr);
190 }
191 
192 static CAmount ExtractAndValidateValue(const std::string& strValue)
193 {
194  if (std::optional<CAmount> parsed = ParseMoney(strValue)) {
195  return parsed.value();
196  } else {
197  throw std::runtime_error("invalid TX output value");
198  }
199 }
200 
201 static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal)
202 {
203  int64_t newVersion;
204  if (!ParseInt64(cmdVal, &newVersion) || newVersion < 1 || newVersion > TX_MAX_STANDARD_VERSION) {
205  throw std::runtime_error("Invalid TX version requested: '" + cmdVal + "'");
206  }
207 
208  tx.nVersion = (int) newVersion;
209 }
210 
211 static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
212 {
213  int64_t newLocktime;
214  if (!ParseInt64(cmdVal, &newLocktime) || newLocktime < 0LL || newLocktime > 0xffffffffLL)
215  throw std::runtime_error("Invalid TX locktime requested: '" + cmdVal + "'");
216 
217  tx.nLockTime = (unsigned int) newLocktime;
218 }
219 
220 static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx)
221 {
222  // parse requested index
223  int64_t inIdx;
224  if (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast<int64_t>(tx.vin.size())) {
225  throw std::runtime_error("Invalid TX input index '" + strInIdx + "'");
226  }
227 
228  // set the nSequence to MAX_INT - 2 (= RBF opt in flag)
229  int cnt = 0;
230  for (CTxIn& txin : tx.vin) {
231  if (strInIdx == "" || cnt == inIdx) {
232  if (txin.nSequence > MAX_BIP125_RBF_SEQUENCE) {
234  }
235  }
236  ++cnt;
237  }
238 }
239 
240 template <typename T>
241 static T TrimAndParse(const std::string& int_str, const std::string& err)
242 {
243  const auto parsed{ToIntegral<T>(TrimStringView(int_str))};
244  if (!parsed.has_value()) {
245  throw std::runtime_error(err + " '" + int_str + "'");
246  }
247  return parsed.value();
248 }
249 
250 static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput)
251 {
252  std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
253 
254  // separate TXID:VOUT in string
255  if (vStrInputParts.size()<2)
256  throw std::runtime_error("TX input missing separator");
257 
258  // extract and validate TXID
259  uint256 txid;
260  if (!ParseHashStr(vStrInputParts[0], txid)) {
261  throw std::runtime_error("invalid TX input txid");
262  }
263 
264  static const unsigned int minTxOutSz = 9;
265  static const unsigned int maxVout = MAX_BLOCK_WEIGHT / (WITNESS_SCALE_FACTOR * minTxOutSz);
266 
267  // extract and validate vout
268  const std::string& strVout = vStrInputParts[1];
269  int64_t vout;
270  if (!ParseInt64(strVout, &vout) || vout < 0 || vout > static_cast<int64_t>(maxVout))
271  throw std::runtime_error("invalid TX input vout '" + strVout + "'");
272 
273  // extract the optional sequence number
274  uint32_t nSequenceIn = CTxIn::SEQUENCE_FINAL;
275  if (vStrInputParts.size() > 2) {
276  nSequenceIn = TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid TX sequence id");
277  }
278 
279  // append to transaction input list
280  CTxIn txin(txid, vout, CScript(), nSequenceIn);
281  tx.vin.push_back(txin);
282 }
283 
284 static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strInput)
285 {
286  // Separate into VALUE:ADDRESS
287  std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
288 
289  if (vStrInputParts.size() != 2)
290  throw std::runtime_error("TX output missing or too many separators");
291 
292  // Extract and validate VALUE
293  CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
294 
295  // extract and validate ADDRESS
296  std::string strAddr = vStrInputParts[1];
297  CTxDestination destination = DecodeDestination(strAddr);
298  if (!IsValidDestination(destination)) {
299  throw std::runtime_error("invalid TX output address");
300  }
301  CScript scriptPubKey = GetScriptForDestination(destination);
302 
303  // construct TxOut, append to transaction output list
304  CTxOut txout(value, scriptPubKey);
305  tx.vout.push_back(txout);
306 }
307 
308 static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& strInput)
309 {
310  // Separate into VALUE:PUBKEY[:FLAGS]
311  std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
312 
313  if (vStrInputParts.size() < 2 || vStrInputParts.size() > 3)
314  throw std::runtime_error("TX output missing or too many separators");
315 
316  // Extract and validate VALUE
317  CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
318 
319  // Extract and validate PUBKEY
320  CPubKey pubkey(ParseHex(vStrInputParts[1]));
321  if (!pubkey.IsFullyValid())
322  throw std::runtime_error("invalid TX output pubkey");
323  CScript scriptPubKey = GetScriptForRawPubKey(pubkey);
324 
325  // Extract and validate FLAGS
326  bool bSegWit = false;
327  bool bScriptHash = false;
328  if (vStrInputParts.size() == 3) {
329  std::string flags = vStrInputParts[2];
330  bSegWit = (flags.find('W') != std::string::npos);
331  bScriptHash = (flags.find('S') != std::string::npos);
332  }
333 
334  if (bSegWit) {
335  if (!pubkey.IsCompressed()) {
336  throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
337  }
338  // Build a P2WPKH script
339  scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkey));
340  }
341  if (bScriptHash) {
342  // Get the ID for the script, and then construct a P2SH destination for it.
343  scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey));
344  }
345 
346  // construct TxOut, append to transaction output list
347  CTxOut txout(value, scriptPubKey);
348  tx.vout.push_back(txout);
349 }
350 
351 static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput)
352 {
353  // Separate into VALUE:REQUIRED:NUMKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]
354  std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
355 
356  // Check that there are enough parameters
357  if (vStrInputParts.size()<3)
358  throw std::runtime_error("Not enough multisig parameters");
359 
360  // Extract and validate VALUE
361  CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
362 
363  // Extract REQUIRED
364  const uint32_t required{TrimAndParse<uint32_t>(vStrInputParts.at(1), "invalid multisig required number")};
365 
366  // Extract NUMKEYS
367  const uint32_t numkeys{TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid multisig total number")};
368 
369  // Validate there are the correct number of pubkeys
370  if (vStrInputParts.size() < numkeys + 3)
371  throw std::runtime_error("incorrect number of multisig pubkeys");
372 
373  if (required < 1 || required > MAX_PUBKEYS_PER_MULTISIG || numkeys < 1 || numkeys > MAX_PUBKEYS_PER_MULTISIG || numkeys < required)
374  throw std::runtime_error("multisig parameter mismatch. Required " \
375  + ToString(required) + " of " + ToString(numkeys) + "signatures.");
376 
377  // extract and validate PUBKEYs
378  std::vector<CPubKey> pubkeys;
379  for(int pos = 1; pos <= int(numkeys); pos++) {
380  CPubKey pubkey(ParseHex(vStrInputParts[pos + 2]));
381  if (!pubkey.IsFullyValid())
382  throw std::runtime_error("invalid TX output pubkey");
383  pubkeys.push_back(pubkey);
384  }
385 
386  // Extract FLAGS
387  bool bSegWit = false;
388  bool bScriptHash = false;
389  if (vStrInputParts.size() == numkeys + 4) {
390  std::string flags = vStrInputParts.back();
391  bSegWit = (flags.find('W') != std::string::npos);
392  bScriptHash = (flags.find('S') != std::string::npos);
393  }
394  else if (vStrInputParts.size() > numkeys + 4) {
395  // Validate that there were no more parameters passed
396  throw std::runtime_error("Too many parameters");
397  }
398 
399  CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);
400 
401  if (bSegWit) {
402  for (const CPubKey& pubkey : pubkeys) {
403  if (!pubkey.IsCompressed()) {
404  throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
405  }
406  }
407  // Build a P2WSH with the multisig script
408  scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(scriptPubKey));
409  }
410  if (bScriptHash) {
411  if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
412  throw std::runtime_error(strprintf(
413  "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
414  }
415  // Get the ID for the script, and then construct a P2SH destination for it.
416  scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey));
417  }
418 
419  // construct TxOut, append to transaction output list
420  CTxOut txout(value, scriptPubKey);
421  tx.vout.push_back(txout);
422 }
423 
424 static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strInput)
425 {
426  CAmount value = 0;
427 
428  // separate [VALUE:]DATA in string
429  size_t pos = strInput.find(':');
430 
431  if (pos==0)
432  throw std::runtime_error("TX output value not specified");
433 
434  if (pos == std::string::npos) {
435  pos = 0;
436  } else {
437  // Extract and validate VALUE
438  value = ExtractAndValidateValue(strInput.substr(0, pos));
439  ++pos;
440  }
441 
442  // extract and validate DATA
443  const std::string strData{strInput.substr(pos, std::string::npos)};
444 
445  if (!IsHex(strData))
446  throw std::runtime_error("invalid TX output data");
447 
448  std::vector<unsigned char> data = ParseHex(strData);
449 
450  CTxOut txout(value, CScript() << OP_RETURN << data);
451  tx.vout.push_back(txout);
452 }
453 
454 static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
455 {
456  // separate VALUE:SCRIPT[:FLAGS]
457  std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
458  if (vStrInputParts.size() < 2)
459  throw std::runtime_error("TX output missing separator");
460 
461  // Extract and validate VALUE
462  CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
463 
464  // extract and validate script
465  std::string strScript = vStrInputParts[1];
466  CScript scriptPubKey = ParseScript(strScript);
467 
468  // Extract FLAGS
469  bool bSegWit = false;
470  bool bScriptHash = false;
471  if (vStrInputParts.size() == 3) {
472  std::string flags = vStrInputParts.back();
473  bSegWit = (flags.find('W') != std::string::npos);
474  bScriptHash = (flags.find('S') != std::string::npos);
475  }
476 
477  if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
478  throw std::runtime_error(strprintf(
479  "script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
480  }
481 
482  if (bSegWit) {
483  scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(scriptPubKey));
484  }
485  if (bScriptHash) {
486  if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
487  throw std::runtime_error(strprintf(
488  "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
489  }
490  scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey));
491  }
492 
493  // construct TxOut, append to transaction output list
494  CTxOut txout(value, scriptPubKey);
495  tx.vout.push_back(txout);
496 }
497 
498 static void MutateTxDelInput(CMutableTransaction& tx, const std::string& strInIdx)
499 {
500  // parse requested deletion index
501  int64_t inIdx;
502  if (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast<int64_t>(tx.vin.size())) {
503  throw std::runtime_error("Invalid TX input index '" + strInIdx + "'");
504  }
505 
506  // delete input from transaction
507  tx.vin.erase(tx.vin.begin() + inIdx);
508 }
509 
510 static void MutateTxDelOutput(CMutableTransaction& tx, const std::string& strOutIdx)
511 {
512  // parse requested deletion index
513  int64_t outIdx;
514  if (!ParseInt64(strOutIdx, &outIdx) || outIdx < 0 || outIdx >= static_cast<int64_t>(tx.vout.size())) {
515  throw std::runtime_error("Invalid TX output index '" + strOutIdx + "'");
516  }
517 
518  // delete output from transaction
519  tx.vout.erase(tx.vout.begin() + outIdx);
520 }
521 
522 static const unsigned int N_SIGHASH_OPTS = 7;
523 static const struct {
524  const char *flagStr;
525  int flags;
527  {"DEFAULT", SIGHASH_DEFAULT},
528  {"ALL", SIGHASH_ALL},
529  {"NONE", SIGHASH_NONE},
530  {"SINGLE", SIGHASH_SINGLE},
531  {"ALL|ANYONECANPAY", SIGHASH_ALL|SIGHASH_ANYONECANPAY},
532  {"NONE|ANYONECANPAY", SIGHASH_NONE|SIGHASH_ANYONECANPAY},
533  {"SINGLE|ANYONECANPAY", SIGHASH_SINGLE|SIGHASH_ANYONECANPAY},
534 };
535 
536 static bool findSighashFlags(int& flags, const std::string& flagStr)
537 {
538  flags = 0;
539 
540  for (unsigned int i = 0; i < N_SIGHASH_OPTS; i++) {
541  if (flagStr == sighashOptions[i].flagStr) {
542  flags = sighashOptions[i].flags;
543  return true;
544  }
545  }
546 
547  return false;
548 }
549 
550 static CAmount AmountFromValue(const UniValue& value)
551 {
552  if (!value.isNum() && !value.isStr())
553  throw std::runtime_error("Amount is not a number or string");
554  CAmount amount;
555  if (!ParseFixedPoint(value.getValStr(), 8, &amount))
556  throw std::runtime_error("Invalid amount");
557  if (!MoneyRange(amount))
558  throw std::runtime_error("Amount out of range");
559  return amount;
560 }
561 
562 static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
563 {
564  int nHashType = SIGHASH_ALL;
565 
566  if (flagStr.size() > 0)
567  if (!findSighashFlags(nHashType, flagStr))
568  throw std::runtime_error("unknown sighash flag/sign option");
569 
570  // mergedTx will end up with all the signatures; it
571  // starts as a clone of the raw tx:
572  CMutableTransaction mergedTx{tx};
573  const CMutableTransaction txv{tx};
574  CCoinsView viewDummy;
575  CCoinsViewCache view(&viewDummy);
576 
577  if (!registers.count("privatekeys"))
578  throw std::runtime_error("privatekeys register variable must be set.");
579  FillableSigningProvider tempKeystore;
580  UniValue keysObj = registers["privatekeys"];
581 
582  for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) {
583  if (!keysObj[kidx].isStr())
584  throw std::runtime_error("privatekey not a std::string");
585  CKey key = DecodeSecret(keysObj[kidx].getValStr());
586  if (!key.IsValid()) {
587  throw std::runtime_error("privatekey not valid");
588  }
589  tempKeystore.AddKey(key);
590  }
591 
592  // Add previous txouts given in the RPC call:
593  if (!registers.count("prevtxs"))
594  throw std::runtime_error("prevtxs register variable must be set.");
595  UniValue prevtxsObj = registers["prevtxs"];
596  {
597  for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) {
598  const UniValue& prevOut = prevtxsObj[previdx];
599  if (!prevOut.isObject())
600  throw std::runtime_error("expected prevtxs internal object");
601 
602  std::map<std::string, UniValue::VType> types = {
603  {"txid", UniValue::VSTR},
604  {"vout", UniValue::VNUM},
605  {"scriptPubKey", UniValue::VSTR},
606  };
607  if (!prevOut.checkObject(types))
608  throw std::runtime_error("prevtxs internal object typecheck fail");
609 
610  uint256 txid;
611  if (!ParseHashStr(prevOut["txid"].get_str(), txid)) {
612  throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')");
613  }
614 
615  const int nOut = prevOut["vout"].getInt<int>();
616  if (nOut < 0)
617  throw std::runtime_error("vout cannot be negative");
618 
619  COutPoint out(txid, nOut);
620  std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));
621  CScript scriptPubKey(pkData.begin(), pkData.end());
622 
623  {
624  const Coin& coin = view.AccessCoin(out);
625  if (!coin.IsSpent() && coin.out.scriptPubKey != scriptPubKey) {
626  std::string err("Previous output scriptPubKey mismatch:\n");
627  err = err + ScriptToAsmStr(coin.out.scriptPubKey) + "\nvs:\n"+
628  ScriptToAsmStr(scriptPubKey);
629  throw std::runtime_error(err);
630  }
631  Coin newcoin;
632  newcoin.out.scriptPubKey = scriptPubKey;
633  newcoin.out.nValue = MAX_MONEY;
634  if (prevOut.exists("amount")) {
635  newcoin.out.nValue = AmountFromValue(prevOut["amount"]);
636  }
637  newcoin.nHeight = 1;
638  view.AddCoin(out, std::move(newcoin), true);
639  }
640 
641  // if redeemScript given and private keys given,
642  // add redeemScript to the tempKeystore so it can be signed:
643  if ((scriptPubKey.IsPayToScriptHash() || scriptPubKey.IsPayToWitnessScriptHash()) &&
644  prevOut.exists("redeemScript")) {
645  UniValue v = prevOut["redeemScript"];
646  std::vector<unsigned char> rsData(ParseHexUV(v, "redeemScript"));
647  CScript redeemScript(rsData.begin(), rsData.end());
648  tempKeystore.AddCScript(redeemScript);
649  }
650  }
651  }
652 
653  const FillableSigningProvider& keystore = tempKeystore;
654 
655  bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
656 
657  // Sign what we can:
658  for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
659  CTxIn& txin = mergedTx.vin[i];
660  const Coin& coin = view.AccessCoin(txin.prevout);
661  if (coin.IsSpent()) {
662  continue;
663  }
664  const CScript& prevPubKey = coin.out.scriptPubKey;
665  const CAmount& amount = coin.out.nValue;
666 
667  SignatureData sigdata = DataFromTransaction(mergedTx, i, coin.out);
668  // Only sign SIGHASH_SINGLE if there's a corresponding output:
669  if (!fHashSingle || (i < mergedTx.vout.size()))
670  ProduceSignature(keystore, MutableTransactionSignatureCreator(mergedTx, i, amount, nHashType), prevPubKey, sigdata);
671 
672  if (amount == MAX_MONEY && !sigdata.scriptWitness.IsNull()) {
673  throw std::runtime_error(strprintf("Missing amount for CTxOut with scriptPubKey=%s", HexStr(prevPubKey)));
674  }
675 
676  UpdateInput(txin, sigdata);
677  }
678 
679  tx = mergedTx;
680 }
681 
683 {
685 
686 public:
688  ECC_Start();
689  }
691  ECC_Stop();
692  }
693 };
694 
695 static void MutateTx(CMutableTransaction& tx, const std::string& command,
696  const std::string& commandVal)
697 {
698  std::unique_ptr<Secp256k1Init> ecc;
699 
700  if (command == "nversion")
701  MutateTxVersion(tx, commandVal);
702  else if (command == "locktime")
703  MutateTxLocktime(tx, commandVal);
704  else if (command == "replaceable") {
705  MutateTxRBFOptIn(tx, commandVal);
706  }
707 
708  else if (command == "delin")
709  MutateTxDelInput(tx, commandVal);
710  else if (command == "in")
711  MutateTxAddInput(tx, commandVal);
712 
713  else if (command == "delout")
714  MutateTxDelOutput(tx, commandVal);
715  else if (command == "outaddr")
716  MutateTxAddOutAddr(tx, commandVal);
717  else if (command == "outpubkey") {
718  ecc.reset(new Secp256k1Init());
719  MutateTxAddOutPubKey(tx, commandVal);
720  } else if (command == "outmultisig") {
721  ecc.reset(new Secp256k1Init());
722  MutateTxAddOutMultiSig(tx, commandVal);
723  } else if (command == "outscript")
724  MutateTxAddOutScript(tx, commandVal);
725  else if (command == "outdata")
726  MutateTxAddOutData(tx, commandVal);
727 
728  else if (command == "sign") {
729  ecc.reset(new Secp256k1Init());
730  MutateTxSign(tx, commandVal);
731  }
732 
733  else if (command == "load")
734  RegisterLoad(commandVal);
735 
736  else if (command == "set")
737  RegisterSet(commandVal);
738 
739  else
740  throw std::runtime_error("unknown command");
741 }
742 
743 static void OutputTxJSON(const CTransaction& tx)
744 {
745  UniValue entry(UniValue::VOBJ);
746  TxToUniv(tx, /*block_hash=*/uint256(), entry);
747 
748  std::string jsonOutput = entry.write(4);
749  tfm::format(std::cout, "%s\n", jsonOutput);
750 }
751 
752 static void OutputTxHash(const CTransaction& tx)
753 {
754  std::string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)
755 
756  tfm::format(std::cout, "%s\n", strHexHash);
757 }
758 
759 static void OutputTxHex(const CTransaction& tx)
760 {
761  std::string strHex = EncodeHexTx(tx);
762 
763  tfm::format(std::cout, "%s\n", strHex);
764 }
765 
766 static void OutputTx(const CTransaction& tx)
767 {
768  if (gArgs.GetBoolArg("-json", false))
769  OutputTxJSON(tx);
770  else if (gArgs.GetBoolArg("-txid", false))
771  OutputTxHash(tx);
772  else
773  OutputTxHex(tx);
774 }
775 
776 static std::string readStdin()
777 {
778  char buf[4096];
779  std::string ret;
780 
781  while (!feof(stdin)) {
782  size_t bread = fread(buf, 1, sizeof(buf), stdin);
783  ret.append(buf, bread);
784  if (bread < sizeof(buf))
785  break;
786  }
787 
788  if (ferror(stdin))
789  throw std::runtime_error("error reading stdin");
790 
791  return TrimString(ret);
792 }
793 
794 static int CommandLineRawTx(int argc, char* argv[])
795 {
796  std::string strPrint;
797  int nRet = 0;
798  try {
799  // Skip switches; Permit common stdin convention "-"
800  while (argc > 1 && IsSwitchChar(argv[1][0]) &&
801  (argv[1][1] != 0)) {
802  argc--;
803  argv++;
804  }
805 
807  int startArg;
808 
809  if (!fCreateBlank) {
810  // require at least one param
811  if (argc < 2)
812  throw std::runtime_error("too few parameters");
813 
814  // param: hex-encoded bitcoin transaction
815  std::string strHexTx(argv[1]);
816  if (strHexTx == "-") // "-" implies standard input
817  strHexTx = readStdin();
818 
819  if (!DecodeHexTx(tx, strHexTx, true))
820  throw std::runtime_error("invalid transaction encoding");
821 
822  startArg = 2;
823  } else
824  startArg = 1;
825 
826  for (int i = startArg; i < argc; i++) {
827  std::string arg = argv[i];
828  std::string key, value;
829  size_t eqpos = arg.find('=');
830  if (eqpos == std::string::npos)
831  key = arg;
832  else {
833  key = arg.substr(0, eqpos);
834  value = arg.substr(eqpos + 1);
835  }
836 
837  MutateTx(tx, key, value);
838  }
839 
840  OutputTx(CTransaction(tx));
841  }
842  catch (const std::exception& e) {
843  strPrint = std::string("error: ") + e.what();
844  nRet = EXIT_FAILURE;
845  }
846  catch (...) {
847  PrintExceptionContinue(nullptr, "CommandLineRawTx()");
848  throw;
849  }
850 
851  if (strPrint != "") {
852  tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint);
853  }
854  return nRet;
855 }
856 
858 {
860 
861  try {
862  int ret = AppInitRawTx(argc, argv);
863  if (ret != CONTINUE_EXECUTION)
864  return ret;
865  }
866  catch (const std::exception& e) {
867  PrintExceptionContinue(&e, "AppInitRawTx()");
868  return EXIT_FAILURE;
869  } catch (...) {
870  PrintExceptionContinue(nullptr, "AppInitRawTx()");
871  return EXIT_FAILURE;
872  }
873 
874  int ret = EXIT_FAILURE;
875  try {
876  ret = CommandLineRawTx(argc, argv);
877  }
878  catch (const std::exception& e) {
879  PrintExceptionContinue(&e, "CommandLineRawTx()");
880  } catch (...) {
881  PrintExceptionContinue(nullptr, "CommandLineRawTx()");
882  }
883  return ret;
884 }
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:27
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
#define PACKAGE_NAME
static bool findSighashFlags(int &flags, const std::string &flagStr)
Definition: bitcoin-tx.cpp:536
static void OutputTxHash(const CTransaction &tx)
Definition: bitcoin-tx.cpp:752
static const unsigned int N_SIGHASH_OPTS
Definition: bitcoin-tx.cpp:522
static void MutateTxSign(CMutableTransaction &tx, const std::string &flagStr)
Definition: bitcoin-tx.cpp:562
static const int CONTINUE_EXECUTION
Definition: bitcoin-tx.cpp:36
static std::string readStdin()
Definition: bitcoin-tx.cpp:776
static void OutputTxJSON(const CTransaction &tx)
Definition: bitcoin-tx.cpp:743
static void RegisterSet(const std::string &strInput)
Definition: bitcoin-tx.cpp:136
static void RegisterSetJson(const std::string &key, const std::string &rawJson)
Definition: bitcoin-tx.cpp:125
int ret
Definition: bitcoin-tx.cpp:874
static CAmount ExtractAndValidateValue(const std::string &strValue)
Definition: bitcoin-tx.cpp:192
static void MutateTxDelOutput(CMutableTransaction &tx, const std::string &strOutIdx)
Definition: bitcoin-tx.cpp:510
const char * flagStr
Definition: bitcoin-tx.cpp:524
static const struct @0 sighashOptions[N_SIGHASH_OPTS]
static CAmount AmountFromValue(const UniValue &value)
Definition: bitcoin-tx.cpp:550
static void MutateTx(CMutableTransaction &tx, const std::string &command, const std::string &commandVal)
Definition: bitcoin-tx.cpp:695
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate string to current locale using Qt.
Definition: bitcoin-tx.cpp:38
static T TrimAndParse(const std::string &int_str, const std::string &err)
Definition: bitcoin-tx.cpp:241
static void MutateTxAddOutPubKey(CMutableTransaction &tx, const std::string &strInput)
Definition: bitcoin-tx.cpp:308
static bool fCreateBlank
Definition: bitcoin-tx.cpp:34
static void MutateTxRBFOptIn(CMutableTransaction &tx, const std::string &strInIdx)
Definition: bitcoin-tx.cpp:220
static void MutateTxAddOutData(CMutableTransaction &tx, const std::string &strInput)
Definition: bitcoin-tx.cpp:424
static void MutateTxVersion(CMutableTransaction &tx, const std::string &cmdVal)
Definition: bitcoin-tx.cpp:201
static void MutateTxAddOutAddr(CMutableTransaction &tx, const std::string &strInput)
Definition: bitcoin-tx.cpp:284
static int CommandLineRawTx(int argc, char *argv[])
Definition: bitcoin-tx.cpp:794
static void OutputTxHex(const CTransaction &tx)
Definition: bitcoin-tx.cpp:759
static void RegisterLoad(const std::string &strInput)
Definition: bitcoin-tx.cpp:151
static void MutateTxDelInput(CMutableTransaction &tx, const std::string &strInIdx)
Definition: bitcoin-tx.cpp:498
static int AppInitRawTx(int argc, char *argv[])
Definition: bitcoin-tx.cpp:81
static void MutateTxAddInput(CMutableTransaction &tx, const std::string &strInput)
Definition: bitcoin-tx.cpp:250
int flags
Definition: bitcoin-tx.cpp:525
static std::map< std::string, UniValue > registers
Definition: bitcoin-tx.cpp:35
static void SetupBitcoinTxArgs(ArgsManager &argsman)
Definition: bitcoin-tx.cpp:40
static void MutateTxAddOutMultiSig(CMutableTransaction &tx, const std::string &strInput)
Definition: bitcoin-tx.cpp:351
static void MutateTxAddOutScript(CMutableTransaction &tx, const std::string &strInput)
Definition: bitcoin-tx.cpp:454
static void MutateTxLocktime(CMutableTransaction &tx, const std::string &cmdVal)
Definition: bitcoin-tx.cpp:211
MAIN_FUNCTION
Definition: bitcoin-tx.cpp:858
static void OutputTx(const CTransaction &tx)
Definition: bitcoin-tx.cpp:766
SetupEnvironment()
Definition: system.cpp:1338
std::string strPrint
return EXIT_SUCCESS
const auto command
ECC_Start()
Definition: key.cpp:392
ECC_Stop()
Definition: key.cpp:409
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
void SetupChainParamsBaseOptions(ArgsManager &argsman)
Set the arguments for chainparams.
@ ALLOW_ANY
disable validation
Definition: system.h:172
bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: system.cpp:287
std::string GetHelpMessage() const
Get the help string.
Definition: system.cpp:726
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:487
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:641
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:698
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
Definition: system.cpp:1060
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:213
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool possible_overwrite)
Add a coin.
Definition: coins.cpp:67
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Definition: coins.cpp:150
Abstract view on the open txout dataset.
Definition: coins.h:157
An encapsulated private key.
Definition: key.h:27
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:93
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:35
An encapsulated public key.
Definition: pubkey.h:34
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:198
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Definition: pubkey.cpp:292
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:411
bool IsPayToScriptHash() const
Definition: script.cpp:201
bool IsPayToWitnessScriptHash() const
Definition: script.cpp:210
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:288
const uint256 & GetHash() const
Definition: transaction.h:330
An input of a transaction.
Definition: transaction.h:74
uint32_t nSequence
Definition: transaction.h:78
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
Definition: transaction.h:88
COutPoint prevout
Definition: transaction.h:76
An output of a transaction.
Definition: transaction.h:157
CScript scriptPubKey
Definition: transaction.h:160
CAmount nValue
Definition: transaction.h:159
A UTXO entry.
Definition: coins.h:31
CTxOut out
unspent transaction output
Definition: coins.h:34
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:79
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition: coins.h:40
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:336
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
virtual bool AddKey(const CKey &key)
A signature creator for transactions.
Definition: sign.h:39
ECCVerifyHandle globalVerifyHandle
Definition: bitcoin-tx.cpp:684
bool checkObject(const std::map< std::string, UniValue::VType > &memberTypes) const
Definition: univalue.cpp:168
@ VOBJ
Definition: univalue.h:20
@ VSTR
Definition: univalue.h:20
@ VNUM
Definition: univalue.h:20
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const std::string & getValStr() const
Definition: univalue.h:64
size_t size() const
Definition: univalue.h:67
bool isStr() const
Definition: univalue.h:80
Int getInt() const
Definition: univalue.h:139
bool exists(const std::string &key) const
Definition: univalue.h:74
bool isNum() const
Definition: univalue.h:81
bool read(const char *raw, size_t len)
bool isObject() const
Definition: univalue.h:83
std::string GetHex() const
Definition: uint256.cpp:20
size_type size() const
Definition: prevector.h:284
256-bit opaque blob.
Definition: uint256.h:119
std::string FormatFullVersion()
std::string LicenseInfo()
Returns licensing information (for -version)
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
CScript ParseScript(const std::string &s)
Definition: core_read.cpp:62
std::vector< unsigned char > ParseHexUV(const UniValue &v, const std::string &strName)
Definition: core_read.cpp:245
bool ParseHashStr(const std::string &strHex, uint256 &result)
Parse a hex string into 256 bits.
Definition: core_read.cpp:236
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
Definition: core_write.cpp:98
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
Definition: core_write.cpp:143
void TxToUniv(const CTransaction &tx, const uint256 &block_hash, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr, TxVerbosity verbosity=TxVerbosity::SHOW_DETAILS)
Definition: core_write.cpp:171
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
Definition: core_read.cpp:195
#define T(expected, seed, data)
@ SIGHASH_ANYONECANPAY
Definition: interpreter.h:31
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
Definition: interpreter.h:33
@ SIGHASH_ALL
Definition: interpreter.h:28
@ SIGHASH_NONE
Definition: interpreter.h:29
@ SIGHASH_SINGLE
Definition: interpreter.h:30
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Definition: key_io.cpp:281
CKey DecodeSecret(const std::string &str)
Definition: key_io.cpp:198
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:42
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:25
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1062
static constexpr decltype(CTransaction::nVersion) TX_MAX_STANDARD_VERSION
Definition: policy.h:114
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
Definition: script.h:24
static const int MAX_SCRIPT_SIZE
Definition: script.h:36
@ OP_RETURN
Definition: script.h:107
static const int MAX_PUBKEYS_PER_MULTISIG
Definition: script.h:30
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:384
void UpdateInput(CTxIn &input, const SignatureData &data)
Definition: sign.cpp:545
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
Definition: sign.cpp:480
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:344
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:339
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:356
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:334
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:149
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Definition: string.h:41
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:21
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:109
std::string_view TrimStringView(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Definition: string.h:31
A mutable version of CTransaction.
Definition: transaction.h:373
std::vector< CTxOut > vout
Definition: transaction.h:375
std::vector< CTxIn > vin
Definition: transaction.h:374
bool IsNull() const
Definition: script.h:571
CScriptWitness scriptWitness
The scriptWitness of an input. Contains complete signatures or the traditional partial signatures for...
Definition: sign.h:73
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
bool IsSwitchChar(char c)
Definition: system.h:121
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
Definition: rbf.h:12
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::vector< Byte > ParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool ParseInt64(std::string_view str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
bool IsHex(std::string_view str)
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
bool HelpRequested(const ArgsManager &args)
Definition: system.cpp:795
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
Definition: system.cpp:800
ArgsManager gArgs
Definition: system.cpp:73
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
Definition: system.cpp:837