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