Dash Core  0.12.2.1
P2P Digital Currency
dash-tx.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2015 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 "base58.h"
6 #include "clientversion.h"
7 #include "coins.h"
8 #include "consensus/consensus.h"
9 #include "core_io.h"
10 #include "keystore.h"
11 #include "policy/policy.h"
12 #include "primitives/transaction.h"
13 #include "script/script.h"
14 #include "script/sign.h"
15 #include <univalue.h>
16 #include "util.h"
17 #include "utilmoneystr.h"
18 #include "utilstrencodings.h"
19 
20 #include <stdio.h>
21 
22 #include <boost/algorithm/string.hpp>
23 #include <boost/assign/list_of.hpp>
24 
25 using namespace std;
26 
27 static bool fCreateBlank;
28 static map<string,UniValue> registers;
29 static const int CONTINUE_EXECUTION=-1;
30 
31 //
32 // This function returns either one of EXIT_ codes when it's expected to stop the process or
33 // CONTINUE_EXECUTION when it's expected to continue further.
34 //
35 static int AppInitRawTx(int argc, char* argv[])
36 {
37  //
38  // Parameters
39  //
40  ParseParameters(argc, argv);
41 
42  // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
43  try {
45  } catch (const std::exception& e) {
46  fprintf(stderr, "Error: %s\n", e.what());
47  return EXIT_FAILURE;
48  }
49 
50  fCreateBlank = GetBoolArg("-create", false);
51 
52  if (argc<2 || mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help"))
53  {
54  // First part of help message is specific to this utility
55  std::string strUsage = _("Dash Core dash-tx utility version") + " " + FormatFullVersion() + "\n\n" +
56  _("Usage:") + "\n" +
57  " dash-tx [options] <hex-tx> [commands] " + _("Update hex-encoded dash transaction") + "\n" +
58  " dash-tx [options] -create [commands] " + _("Create hex-encoded dash transaction") + "\n" +
59  "\n";
60 
61  fprintf(stdout, "%s", strUsage.c_str());
62 
63  strUsage = HelpMessageGroup(_("Options:"));
64  strUsage += HelpMessageOpt("-?", _("This help message"));
65  strUsage += HelpMessageOpt("-create", _("Create new, empty TX."));
66  strUsage += HelpMessageOpt("-json", _("Select JSON output"));
67  strUsage += HelpMessageOpt("-txid", _("Output only the hex-encoded transaction id of the resultant transaction."));
68  AppendParamsHelpMessages(strUsage);
69 
70  fprintf(stdout, "%s", strUsage.c_str());
71 
72  strUsage = HelpMessageGroup(_("Commands:"));
73  strUsage += HelpMessageOpt("delin=N", _("Delete input N from TX"));
74  strUsage += HelpMessageOpt("delout=N", _("Delete output N from TX"));
75  strUsage += HelpMessageOpt("in=TXID:VOUT", _("Add input to TX"));
76  strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N"));
77  strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
78  strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
79  strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", _("Add data-based output to TX"));
80  strUsage += HelpMessageOpt("outscript=VALUE:SCRIPT", _("Add raw script output to TX"));
81  strUsage += HelpMessageOpt("sign=SIGHASH-FLAGS", _("Add zero or more signatures to transaction") + ". " +
82  _("This command requires JSON registers:") +
83  _("prevtxs=JSON object") + ", " +
84  _("privatekeys=JSON object") + ". " +
85  _("See signrawtransaction docs for format of sighash flags, JSON objects."));
86  fprintf(stdout, "%s", strUsage.c_str());
87 
88  strUsage = HelpMessageGroup(_("Register Commands:"));
89  strUsage += HelpMessageOpt("load=NAME:FILENAME", _("Load JSON file FILENAME into register NAME"));
90  strUsage += HelpMessageOpt("set=NAME:JSON-STRING", _("Set register NAME to given JSON-STRING"));
91  fprintf(stdout, "%s", strUsage.c_str());
92 
93  if (argc < 2) {
94  fprintf(stderr, "Error: too few parameters\n");
95  return EXIT_FAILURE;
96  }
97  return EXIT_SUCCESS;
98  }
99  return CONTINUE_EXECUTION;
100 }
101 
102 static void RegisterSetJson(const string& key, const string& rawJson)
103 {
104  UniValue val;
105  if (!val.read(rawJson)) {
106  string strErr = "Cannot parse JSON for key " + key;
107  throw runtime_error(strErr);
108  }
109 
110  registers[key] = val;
111 }
112 
113 static void RegisterSet(const string& strInput)
114 {
115  // separate NAME:VALUE in string
116  size_t pos = strInput.find(':');
117  if ((pos == string::npos) ||
118  (pos == 0) ||
119  (pos == (strInput.size() - 1)))
120  throw runtime_error("Register input requires NAME:VALUE");
121 
122  string key = strInput.substr(0, pos);
123  string valStr = strInput.substr(pos + 1, string::npos);
124 
125  RegisterSetJson(key, valStr);
126 }
127 
128 static void RegisterLoad(const string& strInput)
129 {
130  // separate NAME:FILENAME in string
131  size_t pos = strInput.find(':');
132  if ((pos == string::npos) ||
133  (pos == 0) ||
134  (pos == (strInput.size() - 1)))
135  throw runtime_error("Register load requires NAME:FILENAME");
136 
137  string key = strInput.substr(0, pos);
138  string filename = strInput.substr(pos + 1, string::npos);
139 
140  FILE *f = fopen(filename.c_str(), "r");
141  if (!f) {
142  string strErr = "Cannot open file " + filename;
143  throw runtime_error(strErr);
144  }
145 
146  // load file chunks into one big buffer
147  string valStr;
148  while ((!feof(f)) && (!ferror(f))) {
149  char buf[4096];
150  int bread = fread(buf, 1, sizeof(buf), f);
151  if (bread <= 0)
152  break;
153 
154  valStr.insert(valStr.size(), buf, bread);
155  }
156 
157  int error = ferror(f);
158  fclose(f);
159 
160  if (error) {
161  string strErr = "Error reading file " + filename;
162  throw runtime_error(strErr);
163  }
164 
165  // evaluate as JSON buffer register
166  RegisterSetJson(key, valStr);
167 }
168 
169 static void MutateTxVersion(CMutableTransaction& tx, const string& cmdVal)
170 {
171  int64_t newVersion = atoi64(cmdVal);
172  if (newVersion < 1 || newVersion > CTransaction::CURRENT_VERSION)
173  throw runtime_error("Invalid TX version requested");
174 
175  tx.nVersion = (int) newVersion;
176 }
177 
178 static void MutateTxLocktime(CMutableTransaction& tx, const string& cmdVal)
179 {
180  int64_t newLocktime = atoi64(cmdVal);
181  if (newLocktime < 0LL || newLocktime > 0xffffffffLL)
182  throw runtime_error("Invalid TX locktime requested");
183 
184  tx.nLockTime = (unsigned int) newLocktime;
185 }
186 
187 static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
188 {
189  // separate TXID:VOUT in string
190  size_t pos = strInput.find(':');
191  if ((pos == string::npos) ||
192  (pos == 0) ||
193  (pos == (strInput.size() - 1)))
194  throw runtime_error("TX input missing separator");
195 
196  // extract and validate TXID
197  string strTxid = strInput.substr(0, pos);
198  if ((strTxid.size() != 64) || !IsHex(strTxid))
199  throw runtime_error("invalid TX input txid");
200  uint256 txid(uint256S(strTxid));
201 
202  static const unsigned int minTxOutSz = 9;
203  static const unsigned int maxVout = MaxBlockSize(true) / minTxOutSz;
204 
205  // extract and validate vout
206  string strVout = strInput.substr(pos + 1, string::npos);
207  int vout = atoi(strVout);
208  if ((vout < 0) || (vout > (int)maxVout))
209  throw runtime_error("invalid TX input vout");
210 
211  // append to transaction input list
212  CTxIn txin(txid, vout);
213  tx.vin.push_back(txin);
214 }
215 
216 static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)
217 {
218  // separate VALUE:ADDRESS in string
219  size_t pos = strInput.find(':');
220  if ((pos == string::npos) ||
221  (pos == 0) ||
222  (pos == (strInput.size() - 1)))
223  throw runtime_error("TX output missing separator");
224 
225  // extract and validate VALUE
226  string strValue = strInput.substr(0, pos);
227  CAmount value;
228  if (!ParseMoney(strValue, value))
229  throw runtime_error("invalid TX output value");
230 
231  // extract and validate ADDRESS
232  string strAddr = strInput.substr(pos + 1, string::npos);
233  CBitcoinAddress addr(strAddr);
234  if (!addr.IsValid())
235  throw runtime_error("invalid TX output address");
236 
237  // build standard output script via GetScriptForDestination()
238  CScript scriptPubKey = GetScriptForDestination(addr.Get());
239 
240  // construct TxOut, append to transaction output list
241  CTxOut txout(value, scriptPubKey);
242  tx.vout.push_back(txout);
243 }
244 
245 static void MutateTxAddOutData(CMutableTransaction& tx, const string& strInput)
246 {
247  CAmount value = 0;
248 
249  // separate [VALUE:]DATA in string
250  size_t pos = strInput.find(':');
251 
252  if (pos==0)
253  throw runtime_error("TX output value not specified");
254 
255  if (pos != string::npos) {
256  // extract and validate VALUE
257  string strValue = strInput.substr(0, pos);
258  if (!ParseMoney(strValue, value))
259  throw runtime_error("invalid TX output value");
260  }
261 
262  // extract and validate DATA
263  string strData = strInput.substr(pos + 1, string::npos);
264 
265  if (!IsHex(strData))
266  throw runtime_error("invalid TX output data");
267 
268  std::vector<unsigned char> data = ParseHex(strData);
269 
270  CTxOut txout(value, CScript() << OP_RETURN << data);
271  tx.vout.push_back(txout);
272 }
273 
274 static void MutateTxAddOutScript(CMutableTransaction& tx, const string& strInput)
275 {
276  // separate VALUE:SCRIPT in string
277  size_t pos = strInput.find(':');
278  if ((pos == string::npos) ||
279  (pos == 0))
280  throw runtime_error("TX output missing separator");
281 
282  // extract and validate VALUE
283  string strValue = strInput.substr(0, pos);
284  CAmount value;
285  if (!ParseMoney(strValue, value))
286  throw runtime_error("invalid TX output value");
287 
288  // extract and validate script
289  string strScript = strInput.substr(pos + 1, string::npos);
290  CScript scriptPubKey = ParseScript(strScript); // throws on err
291 
292  // construct TxOut, append to transaction output list
293  CTxOut txout(value, scriptPubKey);
294  tx.vout.push_back(txout);
295 }
296 
297 static void MutateTxDelInput(CMutableTransaction& tx, const string& strInIdx)
298 {
299  // parse requested deletion index
300  int inIdx = atoi(strInIdx);
301  if (inIdx < 0 || inIdx >= (int)tx.vin.size()) {
302  string strErr = "Invalid TX input index '" + strInIdx + "'";
303  throw runtime_error(strErr.c_str());
304  }
305 
306  // delete input from transaction
307  tx.vin.erase(tx.vin.begin() + inIdx);
308 }
309 
310 static void MutateTxDelOutput(CMutableTransaction& tx, const string& strOutIdx)
311 {
312  // parse requested deletion index
313  int outIdx = atoi(strOutIdx);
314  if (outIdx < 0 || outIdx >= (int)tx.vout.size()) {
315  string strErr = "Invalid TX output index '" + strOutIdx + "'";
316  throw runtime_error(strErr.c_str());
317  }
318 
319  // delete output from transaction
320  tx.vout.erase(tx.vout.begin() + outIdx);
321 }
322 
323 static const unsigned int N_SIGHASH_OPTS = 6;
324 static const struct {
325  const char *flagStr;
326  int flags;
328  {"ALL", SIGHASH_ALL},
329  {"NONE", SIGHASH_NONE},
330  {"SINGLE", SIGHASH_SINGLE},
331  {"ALL|ANYONECANPAY", SIGHASH_ALL|SIGHASH_ANYONECANPAY},
332  {"NONE|ANYONECANPAY", SIGHASH_NONE|SIGHASH_ANYONECANPAY},
333  {"SINGLE|ANYONECANPAY", SIGHASH_SINGLE|SIGHASH_ANYONECANPAY},
334 };
335 
336 static bool findSighashFlags(int& flags, const string& flagStr)
337 {
338  flags = 0;
339 
340  for (unsigned int i = 0; i < N_SIGHASH_OPTS; i++) {
341  if (flagStr == sighashOptions[i].flagStr) {
342  flags = sighashOptions[i].flags;
343  return true;
344  }
345  }
346 
347  return false;
348 }
349 
350 uint256 ParseHashUO(map<string,UniValue>& o, string strKey)
351 {
352  if (!o.count(strKey))
353  return uint256();
354  return ParseHashUV(o[strKey], strKey);
355 }
356 
357 vector<unsigned char> ParseHexUO(map<string,UniValue>& o, string strKey)
358 {
359  if (!o.count(strKey)) {
360  vector<unsigned char> emptyVec;
361  return emptyVec;
362  }
363  return ParseHexUV(o[strKey], strKey);
364 }
365 
366 static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
367 {
368  int nHashType = SIGHASH_ALL;
369 
370  if (flagStr.size() > 0)
371  if (!findSighashFlags(nHashType, flagStr))
372  throw runtime_error("unknown sighash flag/sign option");
373 
374  vector<CTransaction> txVariants;
375  txVariants.push_back(tx);
376 
377  // mergedTx will end up with all the signatures; it
378  // starts as a clone of the raw tx:
379  CMutableTransaction mergedTx(txVariants[0]);
380  bool fComplete = true;
381  CCoinsView viewDummy;
382  CCoinsViewCache view(&viewDummy);
383 
384  if (!registers.count("privatekeys"))
385  throw runtime_error("privatekeys register variable must be set.");
386  bool fGivenKeys = false;
387  CBasicKeyStore tempKeystore;
388  UniValue keysObj = registers["privatekeys"];
389  fGivenKeys = true;
390 
391  for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) {
392  if (!keysObj[kidx].isStr())
393  throw runtime_error("privatekey not a string");
394  CBitcoinSecret vchSecret;
395  bool fGood = vchSecret.SetString(keysObj[kidx].getValStr());
396  if (!fGood)
397  throw runtime_error("privatekey not valid");
398 
399  CKey key = vchSecret.GetKey();
400  tempKeystore.AddKey(key);
401  }
402 
403  // Add previous txouts given in the RPC call:
404  if (!registers.count("prevtxs"))
405  throw runtime_error("prevtxs register variable must be set.");
406  UniValue prevtxsObj = registers["prevtxs"];
407  {
408  for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) {
409  UniValue prevOut = prevtxsObj[previdx];
410  if (!prevOut.isObject())
411  throw runtime_error("expected prevtxs internal object");
412 
413  map<string,UniValue::VType> types = boost::assign::map_list_of("txid", UniValue::VSTR)("vout",UniValue::VNUM)("scriptPubKey",UniValue::VSTR);
414  if (!prevOut.checkObject(types))
415  throw runtime_error("prevtxs internal object typecheck fail");
416 
417  uint256 txid = ParseHashUV(prevOut["txid"], "txid");
418 
419  int nOut = atoi(prevOut["vout"].getValStr());
420  if (nOut < 0)
421  throw runtime_error("vout must be positive");
422 
423  vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));
424  CScript scriptPubKey(pkData.begin(), pkData.end());
425 
426  {
427  CCoinsModifier coins = view.ModifyCoins(txid);
428  if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) {
429  string err("Previous output scriptPubKey mismatch:\n");
430  err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + "\nvs:\n"+
431  ScriptToAsmStr(scriptPubKey);
432  throw runtime_error(err);
433  }
434  if ((unsigned int)nOut >= coins->vout.size())
435  coins->vout.resize(nOut+1);
436  coins->vout[nOut].scriptPubKey = scriptPubKey;
437  coins->vout[nOut].nValue = 0; // we don't know the actual output value
438  }
439 
440  // if redeemScript given and private keys given,
441  // add redeemScript to the tempKeystore so it can be signed:
442  if (fGivenKeys && scriptPubKey.IsPayToScriptHash() &&
443  prevOut.exists("redeemScript")) {
444  UniValue v = prevOut["redeemScript"];
445  vector<unsigned char> rsData(ParseHexUV(v, "redeemScript"));
446  CScript redeemScript(rsData.begin(), rsData.end());
447  tempKeystore.AddCScript(redeemScript);
448  }
449  }
450  }
451 
452  const CKeyStore& keystore = tempKeystore;
453 
454  bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
455 
456  // Sign what we can:
457  for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
458  CTxIn& txin = mergedTx.vin[i];
459  const CCoins* coins = view.AccessCoins(txin.prevout.hash);
460  if (!coins || !coins->IsAvailable(txin.prevout.n)) {
461  fComplete = false;
462  continue;
463  }
464  const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
465 
466  txin.scriptSig.clear();
467  // Only sign SIGHASH_SINGLE if there's a corresponding output:
468  if (!fHashSingle || (i < mergedTx.vout.size()))
469  SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
470 
471  // ... and merge in other signatures:
472  BOOST_FOREACH(const CTransaction& txv, txVariants) {
473  txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
474  }
476  fComplete = false;
477  }
478 
479  if (fComplete) {
480  // do nothing... for now
481  // perhaps store this for later optional JSON output
482  }
483 
484  tx = mergedTx;
485 }
486 
488 {
490 
491 public:
493  ECC_Start();
494  }
496  ECC_Stop();
497  }
498 };
499 
500 static void MutateTx(CMutableTransaction& tx, const string& command,
501  const string& commandVal)
502 {
503  boost::scoped_ptr<Secp256k1Init> ecc;
504 
505  if (command == "nversion")
506  MutateTxVersion(tx, commandVal);
507  else if (command == "locktime")
508  MutateTxLocktime(tx, commandVal);
509 
510  else if (command == "delin")
511  MutateTxDelInput(tx, commandVal);
512  else if (command == "in")
513  MutateTxAddInput(tx, commandVal);
514 
515  else if (command == "delout")
516  MutateTxDelOutput(tx, commandVal);
517  else if (command == "outaddr")
518  MutateTxAddOutAddr(tx, commandVal);
519  else if (command == "outdata")
520  MutateTxAddOutData(tx, commandVal);
521  else if (command == "outscript")
522  MutateTxAddOutScript(tx, commandVal);
523 
524  else if (command == "sign") {
525  if (!ecc) { ecc.reset(new Secp256k1Init()); }
526  MutateTxSign(tx, commandVal);
527  }
528 
529  else if (command == "load")
530  RegisterLoad(commandVal);
531 
532  else if (command == "set")
533  RegisterSet(commandVal);
534 
535  else
536  throw runtime_error("unknown command");
537 }
538 
539 static void OutputTxJSON(const CTransaction& tx)
540 {
541  UniValue entry(UniValue::VOBJ);
542  TxToUniv(tx, uint256(), entry);
543 
544  string jsonOutput = entry.write(4);
545  fprintf(stdout, "%s\n", jsonOutput.c_str());
546 }
547 
548 static void OutputTxHash(const CTransaction& tx)
549 {
550  string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)
551 
552  fprintf(stdout, "%s\n", strHexHash.c_str());
553 }
554 
555 static void OutputTxHex(const CTransaction& tx)
556 {
557  string strHex = EncodeHexTx(tx);
558 
559  fprintf(stdout, "%s\n", strHex.c_str());
560 }
561 
562 static void OutputTx(const CTransaction& tx)
563 {
564  if (GetBoolArg("-json", false))
565  OutputTxJSON(tx);
566  else if (GetBoolArg("-txid", false))
567  OutputTxHash(tx);
568  else
569  OutputTxHex(tx);
570 }
571 
572 static string readStdin()
573 {
574  char buf[4096];
575  string ret;
576 
577  while (!feof(stdin)) {
578  size_t bread = fread(buf, 1, sizeof(buf), stdin);
579  ret.append(buf, bread);
580  if (bread < sizeof(buf))
581  break;
582  }
583 
584  if (ferror(stdin))
585  throw runtime_error("error reading stdin");
586 
587  boost::algorithm::trim_right(ret);
588 
589  return ret;
590 }
591 
592 static int CommandLineRawTx(int argc, char* argv[])
593 {
594  string strPrint;
595  int nRet = 0;
596  try {
597  // Skip switches; Permit common stdin convention "-"
598  while (argc > 1 && IsSwitchChar(argv[1][0]) &&
599  (argv[1][1] != 0)) {
600  argc--;
601  argv++;
602  }
603 
604  CTransaction txDecodeTmp;
605  int startArg;
606 
607  if (!fCreateBlank) {
608  // require at least one param
609  if (argc < 2)
610  throw runtime_error("too few parameters");
611 
612  // param: hex-encoded dash transaction
613  string strHexTx(argv[1]);
614  if (strHexTx == "-") // "-" implies standard input
615  strHexTx = readStdin();
616 
617  if (!DecodeHexTx(txDecodeTmp, strHexTx))
618  throw runtime_error("invalid transaction encoding");
619 
620  startArg = 2;
621  } else
622  startArg = 1;
623 
624  CMutableTransaction tx(txDecodeTmp);
625 
626  for (int i = startArg; i < argc; i++) {
627  string arg = argv[i];
628  string key, value;
629  size_t eqpos = arg.find('=');
630  if (eqpos == string::npos)
631  key = arg;
632  else {
633  key = arg.substr(0, eqpos);
634  value = arg.substr(eqpos + 1);
635  }
636 
637  MutateTx(tx, key, value);
638  }
639 
640  OutputTx(tx);
641  }
642 
643  catch (const boost::thread_interrupted&) {
644  throw;
645  }
646  catch (const std::exception& e) {
647  strPrint = string("error: ") + e.what();
648  nRet = EXIT_FAILURE;
649  }
650  catch (...) {
651  PrintExceptionContinue(NULL, "CommandLineRawTx()");
652  throw;
653  }
654 
655  if (strPrint != "") {
656  fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
657  }
658  return nRet;
659 }
660 
661 int main(int argc, char* argv[])
662 {
664 
665  try {
666  int ret = AppInitRawTx(argc, argv);
667  if (ret != CONTINUE_EXECUTION)
668  return ret;
669  }
670  catch (const std::exception& e) {
671  PrintExceptionContinue(&e, "AppInitRawTx()");
672  return EXIT_FAILURE;
673  } catch (...) {
674  PrintExceptionContinue(NULL, "AppInitRawTx()");
675  return EXIT_FAILURE;
676  }
677 
678  int ret = EXIT_FAILURE;
679  try {
680  ret = CommandLineRawTx(argc, argv);
681  }
682  catch (const std::exception& e) {
683  PrintExceptionContinue(&e, "CommandLineRawTx()");
684  } catch (...) {
685  PrintExceptionContinue(NULL, "CommandLineRawTx()");
686  }
687  return ret;
688 }
std::vector< unsigned char > ParseHexUV(const UniValue &v, const std::string &strName)
bool SetString(const char *pszSecret)
Definition: base58.cpp:329
uint32_t n
Definition: transaction.h:19
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Definition: util.cpp:486
static const int CONTINUE_EXECUTION
Definition: dash-tx.cpp:29
void ECC_Start()
Definition: key.cpp:304
void AppendParamsHelpMessages(std::string &strUsage, bool debugHelp)
static void MutateTxAddOutScript(CMutableTransaction &tx, const string &strInput)
Definition: dash-tx.cpp:274
Definition: coins.h:73
static void MutateTx(CMutableTransaction &tx, const string &command, const string &commandVal)
Definition: dash-tx.cpp:500
static const int32_t CURRENT_VERSION
Definition: transaction.h:219
unsigned int MaxBlockSize(bool fDIP0001Active)
Definition: consensus.h:12
bool IsValid() const
Definition: base58.cpp:247
vector< unsigned char > ParseHexUO(map< string, UniValue > &o, string strKey)
Definition: dash-tx.cpp:357
static void MutateTxSign(CMutableTransaction &tx, const string &flagStr)
Definition: dash-tx.cpp:366
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
Definition: coins.h:245
static void MutateTxAddOutData(CMutableTransaction &tx, const string &strInput)
Definition: dash-tx.cpp:245
static int AppInitRawTx(int argc, char *argv[])
Definition: dash-tx.cpp:35
static void RegisterSet(const string &strInput)
Definition: dash-tx.cpp:113
static bool fCreateBlank
Definition: dash-tx.cpp:27
int flags
Definition: dash-tx.cpp:326
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: util.cpp:509
std::vector< CTxIn > vin
Definition: transaction.h:306
bool IsHex(const string &str)
static void MutateTxVersion(CMutableTransaction &tx, const string &cmdVal)
Definition: dash-tx.cpp:169
static void OutputTxJSON(const CTransaction &tx)
Definition: dash-tx.cpp:539
static void RegisterLoad(const string &strInput)
Definition: dash-tx.cpp:128
static CScript CombineSignatures(const CScript &scriptPubKey, const BaseSignatureChecker &checker, const txnouttype txType, const vector< valtype > &vSolutions, vector< valtype > &sigs1, vector< valtype > &sigs2)
Definition: sign.cpp:213
uint256 ParseHashUO(map< string, UniValue > &o, string strKey)
Definition: dash-tx.cpp:350
static int CommandLineRawTx(int argc, char *argv[])
Definition: dash-tx.cpp:592
static void MutateTxAddOutAddr(CMutableTransaction &tx, const string &strInput)
Definition: dash-tx.cpp:216
static bool findSighashFlags(int &flags, const string &flagStr)
Definition: dash-tx.cpp:336
CScript scriptSig
Definition: transaction.h:62
int64_t CAmount
Definition: amount.h:14
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
Definition: coins.h:80
static void MutateTxLocktime(CMutableTransaction &tx, const string &cmdVal)
Definition: dash-tx.cpp:178
static map< string, UniValue > registers
Definition: dash-tx.cpp:28
static void OutputTxHash(const CTransaction &tx)
Definition: dash-tx.cpp:548
bool GetBoolArg(const std::string &strArg, bool fDefault)
Definition: util.cpp:455
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Definition: core_write.cpp:75
COutPoint prevout
Definition: transaction.h:61
void ECC_Stop()
Definition: key.cpp:323
void SelectParams(const std::string &network)
uint256 ParseHashUV(const UniValue &v, const std::string &strName)
uint256 uint256S(const char *str)
Definition: uint256.h:140
static bool error(const char *format)
Definition: util.h:131
virtual bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: keystore.cpp:41
bool exists(const std::string &key) const
Definition: univalue.h:75
int main(int argc, char *argv[])
Definition: dash-tx.cpp:661
vector< unsigned char > ParseHex(const char *psz)
const char * flagStr
Definition: dash-tx.cpp:325
bool ParseMoney(const string &str, CAmount &nRet)
CCoinsModifier ModifyCoins(const uint256 &txid)
Definition: coins.cpp:99
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:262
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:406
static void MutateTxDelOutput(CMutableTransaction &tx, const string &strOutIdx)
Definition: dash-tx.cpp:310
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
static const struct @10 sighashOptions[N_SIGHASH_OPTS]
std::string FormatFullVersion()
std::vector< CTxOut > vout
Definition: transaction.h:307
static void MutateTxDelInput(CMutableTransaction &tx, const string &strInIdx)
Definition: dash-tx.cpp:297
CKey GetKey()
Definition: base58.cpp:314
static void MutateTxAddInput(CMutableTransaction &tx, const string &strInput)
Definition: dash-tx.cpp:187
static const unsigned int N_SIGHASH_OPTS
Definition: dash-tx.cpp:323
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_write.cpp:119
const std::vector< CTxIn > vin
Definition: transaction.h:233
CTxDestination Get() const
Definition: base58.cpp:260
bool IsSwitchChar(char c)
Definition: util.h:164
static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
Definition: policy.h:35
static string readStdin()
Definition: dash-tx.cpp:572
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const uint256 & GetHash() const
Definition: transaction.h:262
std::string GetHex() const
Definition: uint256.cpp:21
std::string ChainNameFromCommandLine()
int64_t atoi64(const char *psz)
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry)
Definition: core_write.cpp:151
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:14
void clear()
Definition: script.h:639
bool isObject() const
Definition: univalue.h:84
void SetupEnvironment()
Definition: util.cpp:904
bool checkObject(const std::map< std::string, UniValue::VType > &memberTypes)
Definition: univalue.cpp:228
CScript ParseScript(const std::string &s)
Definition: core_read.cpp:25
ECCVerifyHandle globalVerifyHandle
Definition: dash-tx.cpp:489
bool read(const char *raw)
Definition: key.h:35
static void OutputTxHex(const CTransaction &tx)
Definition: dash-tx.cpp:555
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, int nHashType)
Definition: sign.cpp:129
uint256 hash
Definition: transaction.h:18
std::string HelpMessageGroup(const std::string &message)
Definition: util.cpp:482
size_t size() const
Definition: univalue.h:69
static void OutputTx(const CTransaction &tx)
Definition: dash-tx.cpp:562
std::string _(const char *psz)
Definition: util.h:84
static void RegisterSetJson(const string &key, const string &rawJson)
Definition: dash-tx.cpp:102
int atoi(const std::string &str)
map< string, string > mapArgs
Definition: util.cpp:122
bool DecodeHexTx(CTransaction &tx, const std::string &strHexTx)
Definition: core_read.cpp:93
const CCoins * AccessCoins(const uint256 &txid) const
Definition: coins.cpp:129