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