Dash Core  0.12.2.1
P2P Digital Currency
rawtransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2017 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "base58.h"
8 #include "chain.h"
9 #include "coins.h"
10 #include "consensus/validation.h"
11 #include "core_io.h"
12 #include "init.h"
13 #include "keystore.h"
14 #include "validation.h"
15 #include "merkleblock.h"
16 #include "net.h"
17 #include "policy/policy.h"
18 #include "primitives/transaction.h"
19 #include "rpc/server.h"
20 #include "script/script.h"
21 #include "script/script_error.h"
22 #include "script/sign.h"
23 #include "script/standard.h"
24 #include "txmempool.h"
25 #include "uint256.h"
26 #include "utilstrencodings.h"
27 #include "instantx.h"
28 #ifdef ENABLE_WALLET
29 #include "wallet/wallet.h"
30 #endif
31 
32 #include <stdint.h>
33 
34 #include <boost/assign/list_of.hpp>
35 
36 #include <univalue.h>
37 
38 using namespace std;
39 
40 void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
41 {
42  txnouttype type;
43  vector<CTxDestination> addresses;
44  int nRequired;
45 
46  out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey)));
47  if (fIncludeHex)
48  out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
49 
50  if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
51  out.push_back(Pair("type", GetTxnOutputType(type)));
52  return;
53  }
54 
55  out.push_back(Pair("reqSigs", nRequired));
56  out.push_back(Pair("type", GetTxnOutputType(type)));
57 
59  BOOST_FOREACH(const CTxDestination& addr, addresses)
60  a.push_back(CBitcoinAddress(addr).ToString());
61  out.push_back(Pair("addresses", a));
62 }
63 
64 void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
65 {
66  uint256 txid = tx.GetHash();
67  entry.push_back(Pair("txid", txid.GetHex()));
68  entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)));
69  entry.push_back(Pair("version", tx.nVersion));
70  entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
72  BOOST_FOREACH(const CTxIn& txin, tx.vin) {
74  if (tx.IsCoinBase())
75  in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
76  else {
77  in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
78  in.push_back(Pair("vout", (int64_t)txin.prevout.n));
80  o.push_back(Pair("asm", ScriptToAsmStr(txin.scriptSig, true)));
81  o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
82  in.push_back(Pair("scriptSig", o));
83 
84  // Add address and value info if spentindex enabled
85  CSpentIndexValue spentInfo;
86  CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n);
87  if (GetSpentIndex(spentKey, spentInfo)) {
88  in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
89  in.push_back(Pair("valueSat", spentInfo.satoshis));
90  if (spentInfo.addressType == 1) {
91  in.push_back(Pair("address", CBitcoinAddress(CKeyID(spentInfo.addressHash)).ToString()));
92  } else if (spentInfo.addressType == 2) {
93  in.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString()));
94  }
95  }
96 
97  }
98  in.push_back(Pair("sequence", (int64_t)txin.nSequence));
99  vin.push_back(in);
100  }
101  entry.push_back(Pair("vin", vin));
102  UniValue vout(UniValue::VARR);
103  for (unsigned int i = 0; i < tx.vout.size(); i++) {
104  const CTxOut& txout = tx.vout[i];
106  out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
107  out.push_back(Pair("valueSat", txout.nValue));
108  out.push_back(Pair("n", (int64_t)i));
110  ScriptPubKeyToJSON(txout.scriptPubKey, o, true);
111  out.push_back(Pair("scriptPubKey", o));
112 
113  // Add spent information if spentindex is enabled
114  CSpentIndexValue spentInfo;
115  CSpentIndexKey spentKey(txid, i);
116  if (GetSpentIndex(spentKey, spentInfo)) {
117  out.push_back(Pair("spentTxId", spentInfo.txid.GetHex()));
118  out.push_back(Pair("spentIndex", (int)spentInfo.inputIndex));
119  out.push_back(Pair("spentHeight", spentInfo.blockHeight));
120  }
121 
122  vout.push_back(out);
123  }
124  entry.push_back(Pair("vout", vout));
125 
126  if (!hashBlock.IsNull()) {
127  entry.push_back(Pair("blockhash", hashBlock.GetHex()));
128  BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
129  if (mi != mapBlockIndex.end() && (*mi).second) {
130  CBlockIndex* pindex = (*mi).second;
131  if (chainActive.Contains(pindex)) {
132  entry.push_back(Pair("height", pindex->nHeight));
133  entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
134  entry.push_back(Pair("time", pindex->GetBlockTime()));
135  entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
136  } else {
137  entry.push_back(Pair("height", -1));
138  entry.push_back(Pair("confirmations", 0));
139  }
140  }
141  }
142 }
143 
144 UniValue getrawtransaction(const UniValue& params, bool fHelp)
145 {
146  if (fHelp || params.size() < 1 || params.size() > 2)
147  throw runtime_error(
148  "getrawtransaction \"txid\" ( verbose )\n"
149  "\nNOTE: By default this function only works sometimes. This is when the tx is in the mempool\n"
150  "or there is an unspent output in the utxo for this transaction. To make it always work,\n"
151  "you need to maintain a transaction index, using the -txindex command line option.\n"
152  "\nReturn the raw transaction data.\n"
153  "\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n"
154  "If verbose is non-zero, returns an Object with information about 'txid'.\n"
155 
156  "\nArguments:\n"
157  "1. \"txid\" (string, required) The transaction id\n"
158  "2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n"
159 
160  "\nResult (if verbose is not set or set to 0):\n"
161  "\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
162 
163  "\nResult (if verbose > 0):\n"
164  "{\n"
165  " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
166  " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
167  " \"size\" : n, (numeric) The transaction size\n"
168  " \"version\" : n, (numeric) The version\n"
169  " \"locktime\" : ttt, (numeric) The lock time\n"
170  " \"vin\" : [ (array of json objects)\n"
171  " {\n"
172  " \"txid\": \"id\", (string) The transaction id\n"
173  " \"vout\": n, (numeric) \n"
174  " \"scriptSig\": { (json object) The script\n"
175  " \"asm\": \"asm\", (string) asm\n"
176  " \"hex\": \"hex\" (string) hex\n"
177  " },\n"
178  " \"sequence\": n (numeric) The script sequence number\n"
179  " }\n"
180  " ,...\n"
181  " ],\n"
182  " \"vout\" : [ (array of json objects)\n"
183  " {\n"
184  " \"value\" : x.xxx, (numeric) The value in " + CURRENCY_UNIT + "\n"
185  " \"n\" : n, (numeric) index\n"
186  " \"scriptPubKey\" : { (json object)\n"
187  " \"asm\" : \"asm\", (string) the asm\n"
188  " \"hex\" : \"hex\", (string) the hex\n"
189  " \"reqSigs\" : n, (numeric) The required sigs\n"
190  " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
191  " \"addresses\" : [ (json array of string)\n"
192  " \"dashaddress\" (string) dash address\n"
193  " ,...\n"
194  " ]\n"
195  " }\n"
196  " }\n"
197  " ,...\n"
198  " ],\n"
199  " \"blockhash\" : \"hash\", (string) the block hash\n"
200  " \"confirmations\" : n, (numeric) The confirmations\n"
201  " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
202  " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
203  "}\n"
204 
205  "\nExamples:\n"
206  + HelpExampleCli("getrawtransaction", "\"mytxid\"")
207  + HelpExampleCli("getrawtransaction", "\"mytxid\" 1")
208  + HelpExampleRpc("getrawtransaction", "\"mytxid\", 1")
209  );
210 
211  LOCK(cs_main);
212 
213  uint256 hash = ParseHashV(params[0], "parameter 1");
214 
215  bool fVerbose = false;
216  if (params.size() > 1)
217  fVerbose = (params[1].get_int() != 0);
218 
219  CTransaction tx;
220  uint256 hashBlock;
221  if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
222  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
223 
224  string strHex = EncodeHexTx(tx);
225 
226  if (!fVerbose)
227  return strHex;
228 
230  result.push_back(Pair("hex", strHex));
231  TxToJSON(tx, hashBlock, result);
232  return result;
233 }
234 
235 UniValue gettxoutproof(const UniValue& params, bool fHelp)
236 {
237  if (fHelp || (params.size() != 1 && params.size() != 2))
238  throw runtime_error(
239  "gettxoutproof [\"txid\",...] ( blockhash )\n"
240  "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n"
241  "\nNOTE: By default this function only works sometimes. This is when there is an\n"
242  "unspent output in the utxo for this transaction. To make it always work,\n"
243  "you need to maintain a transaction index, using the -txindex command line option or\n"
244  "specify the block in which the transaction is included in manually (by blockhash).\n"
245  "\nReturn the raw transaction data.\n"
246  "\nArguments:\n"
247  "1. \"txids\" (string) A json array of txids to filter\n"
248  " [\n"
249  " \"txid\" (string) A transaction hash\n"
250  " ,...\n"
251  " ]\n"
252  "2. \"block hash\" (string, optional) If specified, looks for txid in the block with this hash\n"
253  "\nResult:\n"
254  "\"data\" (string) A string that is a serialized, hex-encoded data for the proof.\n"
255 
256  "\nExamples:\n"
257  + HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]'")
258  + HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]' \"blockhash\"")
259  + HelpExampleRpc("gettxoutproof", "[\"mytxid\",...], \"blockhash\"")
260  );
261 
262  set<uint256> setTxids;
263  uint256 oneTxid;
264  UniValue txids = params[0].get_array();
265  for (unsigned int idx = 0; idx < txids.size(); idx++) {
266  const UniValue& txid = txids[idx];
267  if (txid.get_str().length() != 64 || !IsHex(txid.get_str()))
268  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid txid ")+txid.get_str());
269  uint256 hash(uint256S(txid.get_str()));
270  if (setTxids.count(hash))
271  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated txid: ")+txid.get_str());
272  setTxids.insert(hash);
273  oneTxid = hash;
274  }
275 
276  LOCK(cs_main);
277 
278  CBlockIndex* pblockindex = NULL;
279 
280  uint256 hashBlock;
281  if (params.size() > 1)
282  {
283  hashBlock = uint256S(params[1].get_str());
284  if (!mapBlockIndex.count(hashBlock))
285  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
286  pblockindex = mapBlockIndex[hashBlock];
287  } else {
288  CCoins coins;
289  if (pcoinsTip->GetCoins(oneTxid, coins) && coins.nHeight > 0 && coins.nHeight <= chainActive.Height())
290  pblockindex = chainActive[coins.nHeight];
291  }
292 
293  if (pblockindex == NULL)
294  {
295  CTransaction tx;
296  if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock, false) || hashBlock.IsNull())
297  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block");
298  if (!mapBlockIndex.count(hashBlock))
299  throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction index corrupt");
300  pblockindex = mapBlockIndex[hashBlock];
301  }
302 
303  CBlock block;
304  if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
305  throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
306 
307  unsigned int ntxFound = 0;
308  BOOST_FOREACH(const CTransaction&tx, block.vtx)
309  if (setTxids.count(tx.GetHash()))
310  ntxFound++;
311  if (ntxFound != setTxids.size())
312  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "(Not all) transactions not found in specified block");
313 
315  CMerkleBlock mb(block, setTxids);
316  ssMB << mb;
317  std::string strHex = HexStr(ssMB.begin(), ssMB.end());
318  return strHex;
319 }
320 
321 UniValue verifytxoutproof(const UniValue& params, bool fHelp)
322 {
323  if (fHelp || params.size() != 1)
324  throw runtime_error(
325  "verifytxoutproof \"proof\"\n"
326  "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n"
327  "and throwing an RPC error if the block is not in our best chain\n"
328  "\nArguments:\n"
329  "1. \"proof\" (string, required) The hex-encoded proof generated by gettxoutproof\n"
330  "\nResult:\n"
331  "[\"txid\"] (array, strings) The txid(s) which the proof commits to, or empty array if the proof is invalid\n"
332 
333  "\nExamples:\n"
334  + HelpExampleCli("verifytxoutproof", "\"proof\"")
335  + HelpExampleRpc("gettxoutproof", "\"proof\"")
336  );
337 
338  CDataStream ssMB(ParseHexV(params[0], "proof"), SER_NETWORK, PROTOCOL_VERSION);
339  CMerkleBlock merkleBlock;
340  ssMB >> merkleBlock;
341 
343 
344  vector<uint256> vMatch;
345  if (merkleBlock.txn.ExtractMatches(vMatch) != merkleBlock.header.hashMerkleRoot)
346  return res;
347 
348  LOCK(cs_main);
349 
350  if (!mapBlockIndex.count(merkleBlock.header.GetHash()) || !chainActive.Contains(mapBlockIndex[merkleBlock.header.GetHash()]))
351  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
352 
353  BOOST_FOREACH(const uint256& hash, vMatch)
354  res.push_back(hash.GetHex());
355  return res;
356 }
357 
358 UniValue createrawtransaction(const UniValue& params, bool fHelp)
359 {
360  if (fHelp || params.size() < 2 || params.size() > 3)
361  throw runtime_error(
362  "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n"
363  "\nCreate a transaction spending the given inputs and creating new outputs.\n"
364  "Outputs can be addresses or data.\n"
365  "Returns hex-encoded raw transaction.\n"
366  "Note that the transaction's inputs are not signed, and\n"
367  "it is not stored in the wallet or transmitted to the network.\n"
368 
369  "\nArguments:\n"
370  "1. \"transactions\" (string, required) A json array of json objects\n"
371  " [\n"
372  " {\n"
373  " \"txid\":\"id\", (string, required) The transaction id\n"
374  " \"vout\":n (numeric, required) The output number\n"
375  " }\n"
376  " ,...\n"
377  " ]\n"
378  "2. \"outputs\" (string, required) a json object with outputs\n"
379  " {\n"
380  " \"address\": x.xxx (numeric or string, required) The key is the dash address, the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n"
381  " \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n"
382  " ...\n"
383  " }\n"
384  "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n"
385  "\nResult:\n"
386  "\"transaction\" (string) hex string of the transaction\n"
387 
388  "\nExamples\n"
389  + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"")
390  + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"data\\\":\\\"00010203\\\"}\"")
391  + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"")
392  + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"}\"")
393  );
394 
395  LOCK(cs_main);
396  RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM), true);
397  if (params[0].isNull() || params[1].isNull())
398  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
399 
400  UniValue inputs = params[0].get_array();
401  UniValue sendTo = params[1].get_obj();
402 
403  CMutableTransaction rawTx;
404 
405  if (params.size() > 2 && !params[2].isNull()) {
406  int64_t nLockTime = params[2].get_int64();
407  if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
408  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
409  rawTx.nLockTime = nLockTime;
410  }
411 
412  for (unsigned int idx = 0; idx < inputs.size(); idx++) {
413  const UniValue& input = inputs[idx];
414  const UniValue& o = input.get_obj();
415 
416  uint256 txid = ParseHashO(o, "txid");
417 
418  const UniValue& vout_v = find_value(o, "vout");
419  if (!vout_v.isNum())
420  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
421  int nOutput = vout_v.get_int();
422  if (nOutput < 0)
423  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
424 
425  uint32_t nSequence = (rawTx.nLockTime ? std::numeric_limits<uint32_t>::max() - 1 : std::numeric_limits<uint32_t>::max());
426  CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
427 
428  rawTx.vin.push_back(in);
429  }
430 
431  set<CBitcoinAddress> setAddress;
432  vector<string> addrList = sendTo.getKeys();
433  BOOST_FOREACH(const string& name_, addrList) {
434 
435  if (name_ == "data") {
436  std::vector<unsigned char> data = ParseHexV(sendTo[name_].getValStr(),"Data");
437 
438  CTxOut out(0, CScript() << OP_RETURN << data);
439  rawTx.vout.push_back(out);
440  } else {
441  CBitcoinAddress address(name_);
442  if (!address.IsValid())
443  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Dash address: ")+name_);
444 
445  if (setAddress.count(address))
446  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_);
447  setAddress.insert(address);
448 
449  CScript scriptPubKey = GetScriptForDestination(address.Get());
450  CAmount nAmount = AmountFromValue(sendTo[name_]);
451 
452  CTxOut out(nAmount, scriptPubKey);
453  rawTx.vout.push_back(out);
454  }
455  }
456 
457  return EncodeHexTx(rawTx);
458 }
459 
460 UniValue decoderawtransaction(const UniValue& params, bool fHelp)
461 {
462  if (fHelp || params.size() != 1)
463  throw runtime_error(
464  "decoderawtransaction \"hexstring\"\n"
465  "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
466 
467  "\nArguments:\n"
468  "1. \"hex\" (string, required) The transaction hex string\n"
469 
470  "\nResult:\n"
471  "{\n"
472  " \"txid\" : \"id\", (string) The transaction id\n"
473  " \"size\" : n, (numeric) The transaction size\n"
474  " \"version\" : n, (numeric) The version\n"
475  " \"locktime\" : ttt, (numeric) The lock time\n"
476  " \"vin\" : [ (array of json objects)\n"
477  " {\n"
478  " \"txid\": \"id\", (string) The transaction id\n"
479  " \"vout\": n, (numeric) The output number\n"
480  " \"scriptSig\": { (json object) The script\n"
481  " \"asm\": \"asm\", (string) asm\n"
482  " \"hex\": \"hex\" (string) hex\n"
483  " },\n"
484  " \"sequence\": n (numeric) The script sequence number\n"
485  " }\n"
486  " ,...\n"
487  " ],\n"
488  " \"vout\" : [ (array of json objects)\n"
489  " {\n"
490  " \"value\" : x.xxx, (numeric) The value in " + CURRENCY_UNIT + "\n"
491  " \"n\" : n, (numeric) index\n"
492  " \"scriptPubKey\" : { (json object)\n"
493  " \"asm\" : \"asm\", (string) the asm\n"
494  " \"hex\" : \"hex\", (string) the hex\n"
495  " \"reqSigs\" : n, (numeric) The required sigs\n"
496  " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
497  " \"addresses\" : [ (json array of string)\n"
498  " \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" (string) Dash address\n"
499  " ,...\n"
500  " ]\n"
501  " }\n"
502  " }\n"
503  " ,...\n"
504  " ],\n"
505  "}\n"
506 
507  "\nExamples:\n"
508  + HelpExampleCli("decoderawtransaction", "\"hexstring\"")
509  + HelpExampleRpc("decoderawtransaction", "\"hexstring\"")
510  );
511 
512  LOCK(cs_main);
513  RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR));
514 
515  CTransaction tx;
516 
517  if (!DecodeHexTx(tx, params[0].get_str()))
518  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
519 
521  TxToJSON(tx, uint256(), result);
522 
523  return result;
524 }
525 
526 UniValue decodescript(const UniValue& params, bool fHelp)
527 {
528  if (fHelp || params.size() != 1)
529  throw runtime_error(
530  "decodescript \"hex\"\n"
531  "\nDecode a hex-encoded script.\n"
532  "\nArguments:\n"
533  "1. \"hex\" (string) the hex encoded script\n"
534  "\nResult:\n"
535  "{\n"
536  " \"asm\":\"asm\", (string) Script public key\n"
537  " \"hex\":\"hex\", (string) hex encoded public key\n"
538  " \"type\":\"type\", (string) The output type\n"
539  " \"reqSigs\": n, (numeric) The required signatures\n"
540  " \"addresses\": [ (json array of string)\n"
541  " \"address\" (string) dash address\n"
542  " ,...\n"
543  " ],\n"
544  " \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
545  "}\n"
546  "\nExamples:\n"
547  + HelpExampleCli("decodescript", "\"hexstring\"")
548  + HelpExampleRpc("decodescript", "\"hexstring\"")
549  );
550 
551  RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR));
552 
554  CScript script;
555  if (params[0].get_str().size() > 0){
556  vector<unsigned char> scriptData(ParseHexV(params[0], "argument"));
557  script = CScript(scriptData.begin(), scriptData.end());
558  } else {
559  // Empty scripts are valid
560  }
561  ScriptPubKeyToJSON(script, r, false);
562 
563  UniValue type;
564 
565  type = find_value(r, "type");
566 
567  if (type.isStr() && type.get_str() != "scripthash") {
568  // P2SH cannot be wrapped in a P2SH. If this script is already a P2SH,
569  // don't return the address for a P2SH of the P2SH.
570  r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString()));
571  }
572 
573  return r;
574 }
575 
577 static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::string& strMessage)
578 {
579  UniValue entry(UniValue::VOBJ);
580  entry.push_back(Pair("txid", txin.prevout.hash.ToString()));
581  entry.push_back(Pair("vout", (uint64_t)txin.prevout.n));
582  entry.push_back(Pair("scriptSig", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
583  entry.push_back(Pair("sequence", (uint64_t)txin.nSequence));
584  entry.push_back(Pair("error", strMessage));
585  vErrorsRet.push_back(entry);
586 }
587 
588 UniValue signrawtransaction(const UniValue& params, bool fHelp)
589 {
590  if (fHelp || params.size() < 1 || params.size() > 4)
591  throw runtime_error(
592  "signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
593  "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
594  "The second optional argument (may be null) is an array of previous transaction outputs that\n"
595  "this transaction depends on but may not yet be in the block chain.\n"
596  "The third optional argument (may be null) is an array of base58-encoded private\n"
597  "keys that, if given, will be the only keys used to sign the transaction.\n"
598 #ifdef ENABLE_WALLET
599  + HelpRequiringPassphrase() + "\n"
600 #endif
601 
602  "\nArguments:\n"
603  "1. \"hexstring\" (string, required) The transaction hex string\n"
604  "2. \"prevtxs\" (string, optional) An json array of previous dependent transaction outputs\n"
605  " [ (json array of json objects, or 'null' if none provided)\n"
606  " {\n"
607  " \"txid\":\"id\", (string, required) The transaction id\n"
608  " \"vout\":n, (numeric, required) The output number\n"
609  " \"scriptPubKey\": \"hex\", (string, required) script key\n"
610  " \"redeemScript\": \"hex\" (string, required for P2SH) redeem script\n"
611  " }\n"
612  " ,...\n"
613  " ]\n"
614  "3. \"privatekeys\" (string, optional) A json array of base58-encoded private keys for signing\n"
615  " [ (json array of strings, or 'null' if none provided)\n"
616  " \"privatekey\" (string) private key in base58-encoding\n"
617  " ,...\n"
618  " ]\n"
619  "4. \"sighashtype\" (string, optional, default=ALL) The signature hash type. Must be one of\n"
620  " \"ALL\"\n"
621  " \"NONE\"\n"
622  " \"SINGLE\"\n"
623  " \"ALL|ANYONECANPAY\"\n"
624  " \"NONE|ANYONECANPAY\"\n"
625  " \"SINGLE|ANYONECANPAY\"\n"
626 
627  "\nResult:\n"
628  "{\n"
629  " \"hex\" : \"value\", (string) The hex-encoded raw transaction with signature(s)\n"
630  " \"complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n"
631  " \"errors\" : [ (json array of objects) Script verification errors (if there are any)\n"
632  " {\n"
633  " \"txid\" : \"hash\", (string) The hash of the referenced, previous transaction\n"
634  " \"vout\" : n, (numeric) The index of the output to spent and used as input\n"
635  " \"scriptSig\" : \"hex\", (string) The hex-encoded signature script\n"
636  " \"sequence\" : n, (numeric) Script sequence number\n"
637  " \"error\" : \"text\" (string) Verification or signing error related to the input\n"
638  " }\n"
639  " ,...\n"
640  " ]\n"
641  "}\n"
642 
643  "\nExamples:\n"
644  + HelpExampleCli("signrawtransaction", "\"myhex\"")
645  + HelpExampleRpc("signrawtransaction", "\"myhex\"")
646  );
647 
648 #ifdef ENABLE_WALLET
650 #else
651  LOCK(cs_main);
652 #endif
653  RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
654 
655  vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
656  CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
657  vector<CMutableTransaction> txVariants;
658  while (!ssData.empty()) {
659  try {
661  ssData >> tx;
662  txVariants.push_back(tx);
663  }
664  catch (const std::exception&) {
665  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
666  }
667  }
668 
669  if (txVariants.empty())
670  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Missing transaction");
671 
672  // mergedTx will end up with all the signatures; it
673  // starts as a clone of the rawtx:
674  CMutableTransaction mergedTx(txVariants[0]);
675 
676  // Fetch previous transactions (inputs):
677  CCoinsView viewDummy;
678  CCoinsViewCache view(&viewDummy);
679  {
680  LOCK(mempool.cs);
681  CCoinsViewCache &viewChain = *pcoinsTip;
682  CCoinsViewMemPool viewMempool(&viewChain, mempool);
683  view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view
684 
685  BOOST_FOREACH(const CTxIn& txin, mergedTx.vin) {
686  const uint256& prevHash = txin.prevout.hash;
687  CCoins coins;
688  view.AccessCoins(prevHash); // this is certainly allowed to fail
689  }
690 
691  view.SetBackend(viewDummy); // switch back to avoid locking mempool for too long
692  }
693 
694  bool fGivenKeys = false;
695  CBasicKeyStore tempKeystore;
696  if (params.size() > 2 && !params[2].isNull()) {
697  fGivenKeys = true;
698  UniValue keys = params[2].get_array();
699  for (unsigned int idx = 0; idx < keys.size(); idx++) {
700  UniValue k = keys[idx];
701  CBitcoinSecret vchSecret;
702  bool fGood = vchSecret.SetString(k.get_str());
703  if (!fGood)
704  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
705  CKey key = vchSecret.GetKey();
706  if (!key.IsValid())
707  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
708  tempKeystore.AddKey(key);
709  }
710  }
711 #ifdef ENABLE_WALLET
712  else if (pwalletMain)
714 #endif
715 
716  // Add previous txouts given in the RPC call:
717  if (params.size() > 1 && !params[1].isNull()) {
718  UniValue prevTxs = params[1].get_array();
719  for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
720  const UniValue& p = prevTxs[idx];
721  if (!p.isObject())
722  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
723 
724  UniValue prevOut = p.get_obj();
725 
726  RPCTypeCheckObj(prevOut, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM)("scriptPubKey", UniValue::VSTR));
727 
728  uint256 txid = ParseHashO(prevOut, "txid");
729 
730  int nOut = find_value(prevOut, "vout").get_int();
731  if (nOut < 0)
732  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive");
733 
734  vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
735  CScript scriptPubKey(pkData.begin(), pkData.end());
736 
737  {
738  CCoinsModifier coins = view.ModifyCoins(txid);
739  if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) {
740  string err("Previous output scriptPubKey mismatch:\n");
741  err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + "\nvs:\n"+
742  ScriptToAsmStr(scriptPubKey);
744  }
745  if ((unsigned int)nOut >= coins->vout.size())
746  coins->vout.resize(nOut+1);
747  coins->vout[nOut].scriptPubKey = scriptPubKey;
748  coins->vout[nOut].nValue = 0; // we don't know the actual output value
749  }
750 
751  // if redeemScript given and not using the local wallet (private keys
752  // given), add redeemScript to the tempKeystore so it can be signed:
753  if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
754  RPCTypeCheckObj(prevOut, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM)("scriptPubKey", UniValue::VSTR)("redeemScript",UniValue::VSTR));
755  UniValue v = find_value(prevOut, "redeemScript");
756  if (!v.isNull()) {
757  vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));
758  CScript redeemScript(rsData.begin(), rsData.end());
759  tempKeystore.AddCScript(redeemScript);
760  }
761  }
762  }
763  }
764 
765 #ifdef ENABLE_WALLET
766  const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain);
767 #else
768  const CKeyStore& keystore = tempKeystore;
769 #endif
770 
771  int nHashType = SIGHASH_ALL;
772  if (params.size() > 3 && !params[3].isNull()) {
773  static map<string, int> mapSigHashValues =
774  boost::assign::map_list_of
775  (string("ALL"), int(SIGHASH_ALL))
776  (string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY))
777  (string("NONE"), int(SIGHASH_NONE))
778  (string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY))
779  (string("SINGLE"), int(SIGHASH_SINGLE))
780  (string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY))
781  ;
782  string strHashType = params[3].get_str();
783  if (mapSigHashValues.count(strHashType))
784  nHashType = mapSigHashValues[strHashType];
785  else
786  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
787  }
788 
789  bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
790 
791  // Script verification errors
792  UniValue vErrors(UniValue::VARR);
793 
794  // Sign what we can:
795  for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
796  CTxIn& txin = mergedTx.vin[i];
797  const CCoins* coins = view.AccessCoins(txin.prevout.hash);
798  if (coins == NULL || !coins->IsAvailable(txin.prevout.n)) {
799  TxInErrorToJSON(txin, vErrors, "Input not found or already spent");
800  continue;
801  }
802  const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
803 
804  txin.scriptSig.clear();
805  // Only sign SIGHASH_SINGLE if there's a corresponding output:
806  if (!fHashSingle || (i < mergedTx.vout.size()))
807  SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
808 
809  // ... and merge in other signatures:
810  BOOST_FOREACH(const CMutableTransaction& txv, txVariants) {
811  txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
812  }
813  ScriptError serror = SCRIPT_ERR_OK;
814  if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker(&mergedTx, i), &serror)) {
815  TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
816  }
817  }
818  bool fComplete = vErrors.empty();
819 
821  result.push_back(Pair("hex", EncodeHexTx(mergedTx)));
822  result.push_back(Pair("complete", fComplete));
823  if (!vErrors.empty()) {
824  result.push_back(Pair("errors", vErrors));
825  }
826 
827  return result;
828 }
829 
830 UniValue sendrawtransaction(const UniValue& params, bool fHelp)
831 {
832  if (fHelp || params.size() < 1 || params.size() > 3)
833  throw runtime_error(
834  "sendrawtransaction \"hexstring\" ( allowhighfees instantsend )\n"
835  "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
836  "\nAlso see createrawtransaction and signrawtransaction calls.\n"
837  "\nArguments:\n"
838  "1. \"hexstring\" (string, required) The hex string of the raw transaction)\n"
839  "2. allowhighfees (boolean, optional, default=false) Allow high fees\n"
840  "3. instantsend (boolean, optional, default=false) Use InstantSend to send this transaction\n"
841  "\nResult:\n"
842  "\"hex\" (string) The transaction hash in hex\n"
843  "\nExamples:\n"
844  "\nCreate a transaction\n"
845  + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
846  "Sign the transaction, and get back the hex\n"
847  + HelpExampleCli("signrawtransaction", "\"myhex\"") +
848  "\nSend the transaction (signed hex)\n"
849  + HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
850  "\nAs a json rpc call\n"
851  + HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
852  );
853 
854  LOCK(cs_main);
855  RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL)(UniValue::VBOOL));
856 
857  // parse hex string from parameter
858  CTransaction tx;
859  if (!DecodeHexTx(tx, params[0].get_str()))
860  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
861  uint256 hashTx = tx.GetHash();
862 
863  bool fOverrideFees = false;
864  if (params.size() > 1)
865  fOverrideFees = params[1].get_bool();
866 
867  bool fInstantSend = false;
868  if (params.size() > 2)
869  fInstantSend = params[2].get_bool();
870 
871  CCoinsViewCache &view = *pcoinsTip;
872  const CCoins* existingCoins = view.AccessCoins(hashTx);
873  bool fHaveMempool = mempool.exists(hashTx);
874  bool fHaveChain = existingCoins && existingCoins->nHeight < 1000000000;
875  if (!fHaveMempool && !fHaveChain) {
876  // push to local node and sync with wallets
877  if (fInstantSend && !instantsend.ProcessTxLockRequest(tx, *g_connman)) {
878  throw JSONRPCError(RPC_TRANSACTION_ERROR, "Not a valid InstantSend transaction, see debug.log for more info");
879  }
880  CValidationState state;
881  bool fMissingInputs;
882  if (!AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, false, !fOverrideFees)) {
883  if (state.IsInvalid()) {
885  } else {
886  if (fMissingInputs) {
887  throw JSONRPCError(RPC_TRANSACTION_ERROR, "Missing inputs");
888  }
890  }
891  }
892  } else if (fHaveChain) {
893  throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain");
894  }
895  if(!g_connman)
896  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
897 
898  g_connman->RelayTransaction(tx);
899 
900  return hashTx.GetHex();
901 }
bool SetString(const char *pszSecret)
Definition: base58.cpp:329
Client still warming up.
Definition: protocol.h:55
uint32_t n
Definition: transaction.h:19
void EnsureWalletIsUnlocked()
Definition: rpcwallet.cpp:54
UniValue gettxoutproof(const UniValue &params, bool fHelp)
vector< unsigned char > ParseHexV(const UniValue &v, string strName)
Definition: server.cpp:147
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
Definition: standard.h:69
const uint32_t nLockTime
Definition: transaction.h:235
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: coins.cpp:90
Definition: coins.h:73
enum ScriptError_t ScriptError
std::string GetRejectReason() const
Definition: validation.h:81
uint32_t nSequence
Definition: transaction.h:63
bool IsValid() const
Definition: base58.cpp:247
#define strprintf
Definition: tinyformat.h:1011
unsigned int inputIndex
Definition: spentindex.h:42
CCriticalSection cs_wallet
Definition: wallet.h:672
bool empty() const
Definition: streams.h:123
bool isStr() const
Definition: univalue.h:81
const std::string CURRENCY_UNIT
Definition: amount.cpp:10
#define ENABLE_WALLET
Definition: dash-config.h:30
CCriticalSection cs_main
Definition: validation.cpp:62
uint256 ParseHashO(const UniValue &o, string strKey)
Definition: server.cpp:143
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
Definition: coins.h:245
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
CAmount nValue
Definition: transaction.h:136
uint160 addressHash
Definition: spentindex.h:46
Definition: pubkey.h:27
const_iterator end() const
Definition: streams.h:120
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:586
UniValue getrawtransaction(const UniValue &params, bool fHelp)
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
Definition: standard.cpp:194
CWallet * pwalletMain
std::vector< CTxIn > vin
Definition: transaction.h:306
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, bool fDryRun)
bool IsHex(const string &str)
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry)
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
static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, const std::string &strMessage)
bool push_back(const UniValue &val)
Definition: univalue.cpp:176
bool IsNull() const
Definition: uint256.h:33
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:122
Ran out of memory during operation.
Definition: protocol.h:46
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:280
std::vector< CTransaction > vtx
Definition: block.h:77
std::string ToString() const
Definition: base58.cpp:193
int64_t get_int64() const
Definition: univalue.cpp:327
const char * ScriptErrorString(const ScriptError serror)
Definition: script_error.cpp:8
bool Contains(const CBlockIndex *pindex) const
Definition: chain.h:384
CScript scriptSig
Definition: transaction.h:62
int64_t CAmount
Definition: amount.h:14
bool exists(uint256 hash) const
Definition: txmempool.h:563
iterator end()
Definition: prevector.h:272
CCoinsViewCache * pcoinsTip
Definition: validation.cpp:187
#define LOCK2(cs1, cs2)
Definition: sync.h:169
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
const UniValue & get_obj() const
Definition: univalue.cpp:347
CCriticalSection cs
Definition: txmempool.h:402
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Definition: core_write.cpp:75
const int32_t nVersion
Definition: transaction.h:232
COutPoint prevout
Definition: transaction.h:61
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:202
std::vector< std::string > getKeys() const
Definition: univalue.cpp:289
const_iterator begin() const
Definition: streams.h:118
#define LOCK(cs)
Definition: sync.h:168
uint256 uint256S(const char *str)
Definition: uint256.h:140
UniValue signrawtransaction(const UniValue &params, bool fHelp)
UniValue createrawtransaction(const UniValue &params, bool fHelp)
bool isNull() const
Definition: univalue.h:77
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
int Height() const
Definition: chain.h:397
UniValue decoderawtransaction(const UniValue &params, bool fHelp)
CInstantSend instantsend
Definition: instantx.cpp:30
const char * GetTxnOutputType(txnouttype t)
Definition: standard.cpp:24
void SetBackend(CCoinsView &viewIn)
Definition: coins.cpp:55
CChain chainActive
Definition: validation.cpp:65
std::string ToString() const
Definition: uint256.cpp:65
CCoinsModifier ModifyCoins(const uint256 &txid)
Definition: coins.cpp:99
Unexpected type was passed as parameter.
Definition: protocol.h:44
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:262
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:581
std::string HelpRequiringPassphrase()
Definition: rpcwallet.cpp:35
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:166
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:110
CAmount satoshis
Definition: spentindex.h:44
unsigned int GetRejectCode() const
Definition: validation.h:80
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
CScript scriptPubKey
Definition: transaction.h:137
uint256 ParseHashV(const UniValue &v, string strName)
Definition: server.cpp:132
void RPCTypeCheckObj(const UniValue &o, const map< string, UniValue::VType > &typesExpected, bool fAllowNull)
Definition: server.cpp:91
std::vector< CTxOut > vout
Definition: transaction.h:307
CKey GetKey()
Definition: base58.cpp:314
txnouttype
Definition: standard.h:45
UniValue sendrawtransaction(const UniValue &params, bool fHelp)
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
void RPCTypeCheck(const UniValue &params, const list< UniValue::VType > &typesExpected, bool fAllowNull)
Definition: server.cpp:70
CTxMemPool mempool
static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
Definition: policy.h:35
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
const CChainParams & Params()
static const int PROTOCOL_VERSION
Definition: version.h:13
const uint256 & GetHash() const
Definition: transaction.h:262
bool isNum() const
Definition: univalue.h:82
bool ProcessTxLockRequest(const CTxLockRequest &txLockRequest, CConnman &connman)
Definition: instantx.cpp:80
bool IsCoinBase() const
Definition: transaction.h:284
bool IsInvalid() const
Definition: validation.h:64
std::string GetHex() const
Definition: uint256.cpp:21
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:103
const std::vector< CTxOut > vout
Definition: transaction.h:234
int get_int() const
Definition: univalue.cpp:317
iterator begin()
Definition: prevector.h:270
UniValue verifytxoutproof(const UniValue &params, bool fHelp)
int64_t GetBlockTime() const
Definition: chain.h:223
vector< unsigned char > ParseHexO(const UniValue &o, string strKey)
Definition: server.cpp:156
Invalid IP/Subnet.
Definition: protocol.h:66
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:14
bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::Params &consensusParams, uint256 &hashBlock, bool fAllowSlow)
void clear()
Definition: script.h:639
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Definition: block.h:73
bool empty() const
Definition: univalue.h:67
Definition: key.h:35
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:113
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
UniValue decodescript(const UniValue &params, bool fHelp)
UniValue JSONRPCError(int code, const string &message)
Definition: protocol.cpp:57
BlockMap mapBlockIndex
Definition: validation.cpp:64
size_t size() const
Definition: univalue.h:69
const UniValue & get_array() const
Definition: univalue.cpp:354
std::string get_str() const
Definition: univalue.cpp:310
int nHeight
at which height this transaction was included in the active block chain
Definition: coins.h:83
Database error.
Definition: protocol.h:48
result
Definition: rpcuser.py:37
bool DecodeHexTx(CTransaction &tx, const std::string &strHexTx)
Definition: core_read.cpp:93
const CCoins * AccessCoins(const uint256 &txid) const
Definition: coins.cpp:129