PIVX Core  5.6.99
P2P Digital Currency
rawtransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2022 The PIVX Core developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #include "core_io.h"
9 #include "evo/providertx.h"
10 #include "key_io.h"
11 #include "keystore.h"
13 #include "net.h"
14 #include "policy/policy.h"
15 #include "primitives/transaction.h"
16 #include "rpc/server.h"
17 #include "script/script.h"
18 #include "script/script_error.h"
19 #include "script/sign.h"
20 #include "script/standard.h"
21 #include "uint256.h"
22 #include "utilmoneystr.h"
23 #include "validationinterface.h"
24 #ifdef ENABLE_WALLET
25 #include "sapling/address.h"
26 #include "sapling/key_io_sapling.h"
27 #include "wallet/rpcwallet.h"
28 #include "wallet/wallet.h"
29 #endif
30 
31 #include <future>
32 #include <stdint.h>
33 
34 #include <univalue.h>
35 
36 template <typename Payload>
37 static void PayloadToJSON(const CTransaction& tx, Payload& pl, UniValue& entry)
38 {
39  if (GetTxPayload(tx, pl)) {
40  UniValue payloadObj;
41  pl.ToJson(payloadObj);
42  entry.pushKV("payload", payloadObj);
43  }
44 }
45 
46 static void PayloadToJSON(const CTransaction& tx, UniValue& entry)
47 {
48  switch(tx.nType) {
49  case CTransaction::TxType::PROREG: {
50  ProRegPL pl;
51  PayloadToJSON(tx, pl, entry);
52  break;
53  }
54  case CTransaction::TxType::PROUPSERV: {
55  ProUpServPL pl;
56  PayloadToJSON(tx, pl, entry);
57  break;
58  }
59  case CTransaction::TxType::PROUPREG: {
60  ProUpRegPL pl;
61  PayloadToJSON(tx, pl, entry);
62  break;
63  }
64  case CTransaction::TxType::PROUPREV: {
65  ProUpRevPL pl;
66  PayloadToJSON(tx, pl, entry);
67  break;
68  }
69  }
70 }
71 
72 extern int ComputeNextBlockAndDepth(const CBlockIndex* tip, const CBlockIndex* blockindex, const CBlockIndex*& next);
73 
74 static int ComputeConfirmations(const CBlockIndex* tip, const CBlockIndex* blockindex)
75 {
76  const CBlockIndex* next{nullptr};
77  return ComputeNextBlockAndDepth(tip, blockindex, next);
78 }
79 
80 // pwallet can be nullptr. If not null, the json could include information available only to the wallet.
81 void TxToJSON(CWallet* const pwallet, const CTransaction& tx, const CBlockIndex* tip, const CBlockIndex* blockindex, UniValue& entry)
82 {
83  // Call into TxToUniv() in bitcoin-common to decode the transaction hex.
84  //
85  // Blockchain contextual information (confirmations and blocktime) is not
86  // available to code in bitcoin-common, so we query them here and push the
87  // data into the returned UniValue.
88  TxToUniv(tx, uint256(), entry);
89 
90  // Sapling
91  if (pwallet && tx.IsShieldedTx()) {
92  // Add information that only this wallet knows about the transaction if is possible
93  if (pwallet->HasSaplingSPKM()) {
94  std::vector<libzcash::SaplingPaymentAddress> addresses =
96  UniValue addrs(UniValue::VARR);
97  for (const auto& addr : addresses) {
99  }
100  entry.pushKV("shielded_addresses", addrs);
101  }
102  }
103 
104  // Special txes
105  if (tx.IsSpecialTx()) {
106  PayloadToJSON(tx, entry);
107  }
108 
109  bool chainLock = false;
110  if (blockindex && tip) {
111  entry.pushKV("blockhash", blockindex->GetBlockHash().ToString());
112  int confirmations = ComputeConfirmations(tip, blockindex);
113  if (confirmations != -1) {
114  entry.pushKV("confirmations", confirmations);
115  entry.pushKV("time", blockindex->GetBlockTime());
116  entry.pushKV("blocktime", blockindex->GetBlockTime());
117  chainLock = llmq::chainLocksHandler->HasChainLock(blockindex->nHeight, blockindex->GetBlockHash());
118  } else {
119  entry.pushKV("confirmations", 0);
120  }
121  }
122  entry.pushKV("chainlock", chainLock);
123 }
124 
125 std::string GetSaplingTxHelpInfo()
126 {
127  return " \"valueBalance\": n, (numeric) The net value of spend transfers minus output transfers\n"
128  " \"valueBalanceSat\": n, (numeric) `valueBalance` in sats\n"
129  " \"vShieldSpend\": [ (array of json objects)\n"
130  " {\n"
131  " \"cv\": \"hex\", (string) A value commitment to the value of the input note\n"
132  " \"anchor\": hex, (string) A Merkle root of the Sapling note commitment tree at some block height in the past\n"
133  " \"nullifier\": hex, (string) The nullifier of the input note\n"
134  " \"rk\": hex, (string) The randomized public key for spendAuthSig\n"
135  " \"proof\": hex, (string) A zero-knowledge proof using the spend circuit\n"
136  " \"spendAuthSig\": hex, (string) A signature authorizing this spend\n"
137  " }\n"
138  " ,...\n"
139  " ],\n"
140  " \"vShieldOutput\": [ (array of json objects)\n"
141  " {\n"
142  " \"cv\": hex, (string) A value commitment to the value of the output note\n"
143  " \"cmu\": hex, (string) The u-coordinate of the note commitment for the output note\n"
144  " \"ephemeralKey\": hex, (string) A Jubjub public key\n"
145  " \"encCiphertext\": hex, (string) A ciphertext component for the encrypted output note\n"
146  " \"outCiphertext\": hex, (string) A ciphertext component for the encrypted output note\n"
147  " \"proof\": hex, (string) A zero-knowledge proof using the output circuit\n"
148  " }\n"
149  " ,...\n"
150  " ],\n"
151  " \"bindingSig\": hex, (string) Prove consistency of valueBalance with the value commitments in spend descriptions and output descriptions, and proves knowledge of the randomness used for the spend and output value commitments\n";
152 }
153 
155 {
156  if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
157  throw std::runtime_error(
158  "getrawtransaction \"txid\" ( verbose \"blockhash\" )\n"
159 
160  "\nNOTE: By default this function only works for mempool transactions. If the -txindex option is\n"
161  "enabled, it also works for blockchain transactions. If the block which contains the transaction\n"
162  "is known, its hash can be provided even for nodes without -txindex. Note that if a blockhash is\n"
163  "provided, only that block will be searched and if the transaction is in the mempool or other\n"
164  "blocks, or if this node does not have the given block available, the transaction will not be found.\n"
165  "DEPRECATED: for now, it also works for transactions with unspent outputs.\n"
166 
167  "\nReturn the raw transaction data.\n"
168  "\nIf verbose is 'true', returns an Object with information about 'txid'.\n"
169  "If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n"
170 
171  "\nArguments:\n"
172  "1. \"txid\" (string, required) The transaction id\n"
173  "2. verbose (bool, optional, default=false) If false, return a string, otherwise return a json object\n"
174  "3. \"blockhash\" (string, optional) The block in which to look for the transaction\n"
175 
176  "\nResult (if verbose is not set or set to false):\n"
177  "\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
178 
179  "\nResult (if verbose is set to true):\n"
180  "{\n"
181  " \"in_active_chain\": b, (bool) Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)\n"
182  " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
183  " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
184  " \"size\" : n, (numeric) The serialized transaction size\n"
185  " \"version\" : n, (numeric) The version\n"
186  " \"type\" : n, (numeric) The type\n"
187  " \"locktime\" : ttt, (numeric) The lock time\n"
188  " \"vin\" : [ (array of json objects)\n"
189  " {\n"
190  " \"txid\": \"id\", (string) The transaction id\n"
191  " \"vout\": n, (numeric) \n"
192  " \"scriptSig\": { (json object) The script\n"
193  " \"asm\": \"asm\", (string) asm\n"
194  " \"hex\": \"hex\" (string) hex\n"
195  " },\n"
196  " \"sequence\": n (numeric) The script sequence number\n"
197  " }\n"
198  " ,...\n"
199  " ],\n"
200  " \"vout\" : [ (array of json objects)\n"
201  " {\n"
202  " \"value\" : x.xxx, (numeric) The value in PIV\n"
203  " \"n\" : n, (numeric) index\n"
204  " \"scriptPubKey\" : { (json object)\n"
205  " \"asm\" : \"asm\", (string) the asm\n"
206  " \"hex\" : \"hex\", (string) the hex\n"
207  " \"reqSigs\" : n, (numeric) The required sigs\n"
208  " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
209  " \"addresses\" : [ (json array of string)\n"
210  " \"pivxaddress\" (string) pivx address\n"
211  " ,...\n"
212  " ]\n"
213  " }\n"
214  " }\n"
215  " ,...\n"
216  " ],\n"
218  " \"shielded_addresses\" (json array of string) the shielded addresses involved in this transaction if possible (only for shielded transactions and the tx owner/viewer)\n"
219  " \"extraPayloadSize\" : n (numeric) Size of extra payload. Only present if it's a special TX\n"
220  " \"extraPayload\" : \"hex\" (string) Hex encoded extra payload data. Only present if it's a special TX\n"
221  " \"blockhash\" : \"hash\", (string) the block hash\n"
222  " \"confirmations\" : n, (numeric) The confirmations\n"
223  " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
224  " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
225  "}\n"
226 
227  "\nExamples:\n"
228  + HelpExampleCli("getrawtransaction", "\"mytxid\"")
229  + HelpExampleCli("getrawtransaction", "\"mytxid\" true")
230  + HelpExampleRpc("getrawtransaction", "\"mytxid\", true")
231  + HelpExampleCli("getrawtransaction", "\"mytxid\" false \"myblockhash\"")
232  + HelpExampleCli("getrawtransaction", "\"mytxid\" true \"myblockhash\"")
233  );
234 
235  LOCK(cs_main);
236 
237  bool in_active_chain = true;
238  uint256 hash = ParseHashV(request.params[0], "parameter 1");
239  CBlockIndex* blockindex = nullptr;
240 
241  bool fVerbose = false;
242  if (!request.params[1].isNull()) {
243  fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool();
244  }
245 
246  if (!request.params[2].isNull()) {
247  uint256 blockhash = ParseHashV(request.params[2], "parameter 3");
248  blockindex = LookupBlockIndex(blockhash);
249  if (!blockindex) {
250  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block hash not found");
251  }
252  in_active_chain = chainActive.Contains(blockindex);
253  }
254 
255  CTransactionRef tx;
256  uint256 hash_block;
257  if (!GetTransaction(hash, tx, hash_block, true, blockindex)) {
258  std::string errmsg;
259  if (blockindex) {
260  if (!(blockindex->nStatus & BLOCK_HAVE_DATA)) {
261  throw JSONRPCError(RPC_MISC_ERROR, "Block not available");
262  }
263  errmsg = "No such transaction found in the provided block";
264  } else {
265  errmsg = fTxIndex
266  ? "No such mempool or blockchain transaction"
267  : "No such mempool transaction. Use -txindex to enable blockchain transaction queries";
268  }
269  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errmsg + ". Use gettransaction for wallet transactions.");
270  }
271 
272  if (!fVerbose) {
273  return EncodeHexTx(*tx);
274  }
275 
276  UniValue result(UniValue::VOBJ);
277  if (blockindex) result.pushKV("in_active_chain", in_active_chain);
278  else blockindex = LookupBlockIndex(hash_block);
279  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
280  TxToJSON(pwallet, *tx, chainActive.Tip(), blockindex, result);
281  return result;
282 }
283 
285 {
286  if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
287  throw std::runtime_error(
288  "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...} ( locktime )\n"
289  "\nCreate a transaction spending the given inputs and sending to the given addresses.\n"
290  "Returns hex-encoded raw transaction.\n"
291  "Note that the transaction's inputs are not signed, and\n"
292  "it is not stored in the wallet or transmitted to the network.\n"
293 
294  "\nArguments:\n"
295  "1. \"inputs\" (string, required) A json array of json objects\n"
296  " [\n"
297  " {\n"
298  " \"txid\":\"id\", (string, required) The transaction id\n"
299  " \"vout\":n, (numeric, required) The output number\n"
300  " \"sequence\":n (numeric, optional) The sequence number\n"
301  " }\n"
302  " ,...\n"
303  " ]\n"
304  "2. \"outputs\" (string, required) a json object with addresses as keys and amounts as values\n"
305  " {\n"
306  " \"address\": x.xxx (numeric, required) The key is the pivx address, the value is the pivx amount\n"
307  " ,...\n"
308  " }\n"
309  "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n"
310 
311  "\nResult:\n"
312  "\"transaction\" (string) hex string of the transaction\n"
313 
314  "\nExamples\n" +
315  HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"") + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\""));
316 
317  LOCK(cs_main);
318  RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VOBJ, UniValue::VNUM});
319  if (request.params[0].isNull() || request.params[1].isNull())
320  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
321 
322  UniValue inputs = request.params[0].get_array();
323  UniValue sendTo = request.params[1].get_obj();
324 
325  CMutableTransaction rawTx;
326 
327  if (request.params.size() > 2 && !request.params[2].isNull()) {
328  int64_t nLockTime = request.params[2].get_int64();
329  if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
330  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
331  rawTx.nLockTime = nLockTime;
332  }
333 
334  for (unsigned int idx = 0; idx < inputs.size(); idx++) {
335  const UniValue& input = inputs[idx];
336  const UniValue& o = input.get_obj();
337 
338  uint256 txid = ParseHashO(o, "txid");
339 
340  const UniValue& vout_v = find_value(o, "vout");
341  if (!vout_v.isNum())
342  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
343  int nOutput = vout_v.get_int();
344  if (nOutput < 0)
345  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
346 
347  uint32_t nSequence = (rawTx.nLockTime ? CTxIn::SEQUENCE_FINAL - 1 : CTxIn::SEQUENCE_FINAL);
348 
349  // set the sequence number if passed in the parameters object
350  const UniValue& sequenceObj = find_value(o, "sequence");
351  if (sequenceObj.isNum()) {
352  int64_t seqNr64 = sequenceObj.get_int64();
353  if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL)
354  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
355  else
356  nSequence = (uint32_t)seqNr64;
357  }
358 
359  CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
360 
361  rawTx.vin.push_back(in);
362  }
363 
364  std::set<CTxDestination> setAddress;
365  std::vector<std::string> addrList = sendTo.getKeys();
366  for (const std::string& name_ : addrList) {
367  CTxDestination address = DecodeDestination(name_);
368  if (!IsValidDestination(address))
369  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid PIVX address: ")+name_);
370 
371  if (setAddress.count(address))
372  throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
373  setAddress.insert(address);
374 
375  CScript scriptPubKey = GetScriptForDestination(address);
376  CAmount nAmount = AmountFromValue(sendTo[name_]);
377 
378  CTxOut out(nAmount, scriptPubKey);
379  rawTx.vout.push_back(out);
380  }
381 
382  return EncodeHexTx(rawTx);
383 }
384 
386 {
387  if (request.fHelp || request.params.size() != 1)
388  throw std::runtime_error(
389  "decoderawtransaction \"hexstring\"\n"
390  "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
391 
392  "\nArguments:\n"
393  "1. \"hexstring\" (string, required) The transaction hex string\n"
394 
395  "\nResult:\n"
396  "{\n"
397  " \"txid\" : \"id\", (string) The transaction id\n"
398  " \"size\" : n, (numeric) The transaction size\n"
399  " \"version\" : n, (numeric) The version\n"
400  " \"type\" : n, (numeric) The type\n"
401  " \"locktime\" : ttt, (numeric) The lock time\n"
402  " \"vin\" : [ (array of json objects)\n"
403  " {\n"
404  " \"txid\": \"id\", (string) The transaction id\n"
405  " \"vout\": n, (numeric) The output number\n"
406  " \"scriptSig\": { (json object) The script\n"
407  " \"asm\": \"asm\", (string) asm\n"
408  " \"hex\": \"hex\" (string) hex\n"
409  " },\n"
410  " \"sequence\": n (numeric) The script sequence number\n"
411  " }\n"
412  " ,...\n"
413  " ],\n"
414  " \"vout\" : [ (array of json objects)\n"
415  " {\n"
416  " \"value\" : x.xxx, (numeric) The value in PIV\n"
417  " \"n\" : n, (numeric) index\n"
418  " \"scriptPubKey\" : { (json object)\n"
419  " \"asm\" : \"asm\", (string) the asm\n"
420  " \"hex\" : \"hex\", (string) the hex\n"
421  " \"reqSigs\" : n, (numeric) The required sigs\n"
422  " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
423  " \"addresses\" : [ (json array of string)\n"
424  " \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) pivx address\n"
425  " ,...\n"
426  " ]\n"
427  " }\n"
428  " }\n"
429  " ,...\n"
430  " ],\n"
432  " \"extraPayloadSize\" : n (numeric) Size of extra payload. Only present if it's a special TX\n"
433  " \"extraPayload\" : \"hex\" (string) Hex encoded extra payload data. Only present if it's a special TX\n"
434  "}\n"
435 
436  "\nExamples:\n" +
437  HelpExampleCli("decoderawtransaction", "\"hexstring\"") + HelpExampleRpc("decoderawtransaction", "\"hexstring\""));
438 
439  LOCK(cs_main);
440  RPCTypeCheck(request.params, {UniValue::VSTR});
441 
443 
444  if (!DecodeHexTx(mtx, request.params[0].get_str()))
445  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
446 
447  UniValue result(UniValue::VOBJ);
448  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
449  TxToJSON(pwallet, CTransaction(std::move(mtx)), nullptr, nullptr, result);
450 
451  return result;
452 }
453 
455 {
456  if (request.fHelp || request.params.size() != 1)
457  throw std::runtime_error(
458  "decodescript \"hexstring\"\n"
459  "\nDecode a hex-encoded script.\n"
460 
461  "\nArguments:\n"
462  "1. \"hexstring\" (string) the hex encoded script\n"
463 
464  "\nResult:\n"
465  "{\n"
466  " \"asm\":\"asm\", (string) Script public key\n"
467  " \"hex\":\"hex\", (string) hex encoded public key\n"
468  " \"type\":\"type\", (string) The output type\n"
469  " \"reqSigs\": n, (numeric) The required signatures\n"
470  " \"addresses\": [ (json array of string)\n"
471  " \"address\" (string) pivx address\n"
472  " ,...\n"
473  " ],\n"
474  " \"p2sh\",\"address\" (string) script address\n"
475  "}\n"
476 
477  "\nExamples:\n" +
478  HelpExampleCli("decodescript", "\"hexstring\"") + HelpExampleRpc("decodescript", "\"hexstring\""));
479 
480  LOCK(cs_main);
481  RPCTypeCheck(request.params, {UniValue::VSTR});
482 
484  CScript script;
485  if (request.params[0].get_str().size() > 0) {
486  std::vector<unsigned char> scriptData(ParseHexV(request.params[0], "argument"));
487  script = CScript(scriptData.begin(), scriptData.end());
488  } else {
489  // Empty scripts are valid
490  }
491  ScriptPubKeyToUniv(script, r, false);
492 
493  r.pushKV("p2sh", EncodeDestination(CScriptID(script)));
494  return r;
495 }
496 
498 static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::string& strMessage)
499 {
500  UniValue entry(UniValue::VOBJ);
501  entry.pushKV("txid", txin.prevout.hash.ToString());
502  entry.pushKV("vout", (uint64_t)txin.prevout.n);
503  entry.pushKV("scriptSig", HexStr(txin.scriptSig));
504  entry.pushKV("sequence", (uint64_t)txin.nSequence);
505  entry.pushKV("error", strMessage);
506  vErrorsRet.push_back(entry);
507 }
508 
510 {
511  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
512 
513  if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
514  throw std::runtime_error(
515  "signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
516  "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
517  "The second optional argument (may be null) is an array of previous transaction outputs that\n"
518  "this transaction depends on but may not yet be in the block chain.\n"
519  "The third optional argument (may be null) is an array of base58-encoded private\n"
520  "keys that, if given, will be the only keys used to sign the transaction.\n"
521 #ifdef ENABLE_WALLET
522  + HelpRequiringPassphrase(pwallet) + "\n"
523 #endif
524 
525  "\nArguments:\n"
526  "1. \"hexstring\" (string, required) The transaction hex string\n"
527  "2. \"prevtxs\" (string, optional) An json array of previous dependent transaction outputs\n"
528  " [ (json array of json objects, or 'null' if none provided)\n"
529  " {\n"
530  " \"txid\":\"id\", (string, required) The transaction id\n"
531  " \"vout\":n, (numeric, required) The output number\n"
532  " \"scriptPubKey\": \"hex\", (string, required) script key\n"
533  " \"redeemScript\": \"hex\" (string, required for P2SH) redeem script\n"
534  " \"amount\": value (numeric, required) The amount spent\n"
535  " }\n"
536  " ,...\n"
537  " ]\n"
538  "3. \"privkeys\" (string, optional) A json array of base58-encoded private keys for signing\n"
539  " [ (json array of strings, or 'null' if none provided)\n"
540  " \"privatekey\" (string) private key in base58-encoding\n"
541  " ,...\n"
542  " ]\n"
543  "4. \"sighashtype\" (string, optional, default=ALL) The signature hash type. Must be one of\n"
544  " \"ALL\"\n"
545  " \"NONE\"\n"
546  " \"SINGLE\"\n"
547  " \"ALL|ANYONECANPAY\"\n"
548  " \"NONE|ANYONECANPAY\"\n"
549  " \"SINGLE|ANYONECANPAY\"\n"
550 
551  "\nResult:\n"
552  "{\n"
553  " \"hex\" : \"value\", (string) The hex-encoded raw transaction with signature(s)\n"
554  " \"complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n"
555  " \"errors\" : [ (json array of objects) Script verification errors (if there are any)\n"
556  " {\n"
557  " \"txid\" : \"hash\", (string) The hash of the referenced, previous transaction\n"
558  " \"vout\" : n, (numeric) The index of the output to spent and used as input\n"
559  " \"scriptSig\" : \"hex\", (string) The hex-encoded signature script\n"
560  " \"sequence\" : n, (numeric) Script sequence number\n"
561  " \"error\" : \"text\" (string) Verification or signing error related to the input\n"
562  " }\n"
563  " ,...\n"
564  " ]\n"
565  "}\n"
566 
567  "\nExamples:\n" +
568  HelpExampleCli("signrawtransaction", "\"myhex\"") + HelpExampleRpc("signrawtransaction", "\"myhex\""));
569 
570 #ifdef ENABLE_WALLET
571  LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr);
572 #else
573  LOCK(cs_main);
574 #endif
575  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true);
576 
577  std::vector<unsigned char> txData(ParseHexV(request.params[0], "argument 1"));
578  CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
579  std::vector<CMutableTransaction> txVariants;
580  while (!ssData.empty()) {
581  try {
583  ssData >> tx;
584  txVariants.push_back(tx);
585  } catch (const std::exception&) {
586  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
587  }
588  }
589 
590  if (txVariants.empty())
591  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Missing transaction");
592 
593  // mergedTx will end up with all the signatures; it
594  // starts as a clone of the rawtx:
595  CMutableTransaction mergedTx(txVariants[0]);
596 
597  // Fetch previous transactions (inputs):
598  std::map<COutPoint, std::pair<CScript, CAmount>> mapPrevOut; // todo: check why do we have this for regtest..
599  if (Params().IsRegTestNet()) {
600  for (const CTxIn &txbase : mergedTx.vin)
601  {
602  CTransactionRef tempTx;
603  uint256 hashBlock;
604  if (GetTransaction(txbase.prevout.hash, tempTx, hashBlock, true)) {
605  // Copy results into mapPrevOut:
606  mapPrevOut[txbase.prevout] = std::make_pair(tempTx->vout[txbase.prevout.n].scriptPubKey, tempTx->vout[txbase.prevout.n].nValue);
607  }
608  }
609  }
610  CCoinsView viewDummy;
611  CCoinsViewCache view(&viewDummy);
612  {
613  LOCK(mempool.cs);
614  CCoinsViewCache& viewChain = *pcoinsTip;
615  CCoinsViewMemPool viewMempool(&viewChain, mempool);
616  view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view
617 
618  for (const CTxIn& txin : mergedTx.vin) {
619  view.AccessCoin(txin.prevout); // Load entries from viewChain into view; can fail.
620  }
621 
622  view.SetBackend(viewDummy); // switch back to avoid locking mempool for too long
623  }
624 
625  bool fGivenKeys = false;
626  CBasicKeyStore tempKeystore;
627  if (request.params.size() > 2 && !request.params[2].isNull()) {
628  fGivenKeys = true;
629  UniValue keys = request.params[2].get_array();
630  for (unsigned int idx = 0; idx < keys.size(); idx++) {
631  UniValue k = keys[idx];
632  CKey key = KeyIO::DecodeSecret(k.get_str());
633  if (!key.IsValid())
634  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
635  tempKeystore.AddKey(key);
636  }
637  }
638 #ifdef ENABLE_WALLET
639  else if (pwallet)
640  EnsureWalletIsUnlocked(pwallet);
641 #endif
642 
643  // Add previous txouts given in the RPC call:
644  if (request.params.size() > 1 && !request.params[1].isNull()) {
645  UniValue prevTxs = request.params[1].get_array();
646  for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
647  const UniValue& p = prevTxs[idx];
648  if (!p.isObject())
649  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
650 
651  UniValue prevOut = p.get_obj();
652 
653  RPCTypeCheckObj(prevOut,
654  {
655  {"txid", UniValueType(UniValue::VSTR)},
656  {"vout", UniValueType(UniValue::VNUM)},
657  {"scriptPubKey", UniValueType(UniValue::VSTR)},
658  });
659 
660  uint256 txid = ParseHashO(prevOut, "txid");
661 
662  int nOut = find_value(prevOut, "vout").get_int();
663  if (nOut < 0)
664  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive");
665 
666  COutPoint out(txid, nOut);
667  std::vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
668  CScript scriptPubKey(pkData.begin(), pkData.end());
669 
670  {
671  const Coin& coin = view.AccessCoin(out);
672  if (!coin.IsSpent() && coin.out.scriptPubKey != scriptPubKey) {
673  std::string err("Previous output scriptPubKey mismatch:\n");
674  err = err + ScriptToAsmStr(coin.out.scriptPubKey) + "\nvs:\n"+
675  ScriptToAsmStr(scriptPubKey);
677  }
678 
679  Coin newcoin;
680  newcoin.out.scriptPubKey = scriptPubKey;
681  newcoin.out.nValue = 0;
682  newcoin.nHeight = 1;
683  if (prevOut.exists("amount")) {
684  newcoin.out.nValue = AmountFromValue(find_value(prevOut, "amount"));
685  }
686  view.AddCoin(out, std::move(newcoin), true);
687  }
688 
689  // if redeemScript given and not using the local wallet (private keys
690  // given), add redeemScript to the tempKeystore so it can be signed:
691  if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
692  RPCTypeCheckObj(prevOut,
693  {
694  {"txid", UniValueType(UniValue::VSTR)},
695  {"vout", UniValueType(UniValue::VNUM)},
696  {"scriptPubKey", UniValueType(UniValue::VSTR)},
697  {"redeemScript", UniValueType(UniValue::VSTR)},
698  });
699  UniValue v = find_value(prevOut, "redeemScript");
700  if (!v.isNull()) {
701  std::vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));
702  CScript redeemScript(rsData.begin(), rsData.end());
703  tempKeystore.AddCScript(redeemScript);
704  }
705  }
706  }
707  }
708 
709 #ifdef ENABLE_WALLET
710  const CKeyStore& keystore = ((fGivenKeys || !pwallet) ? tempKeystore : *pwallet);
711 #else
712  const CKeyStore& keystore = tempKeystore;
713 #endif
714 
715  int nHashType = SIGHASH_ALL;
716  if (request.params.size() > 3 && !request.params[3].isNull()) {
717  static std::map<std::string, int> mapSigHashValues = {
718  {std::string("ALL"), int(SIGHASH_ALL)},
719  {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
720  {std::string("NONE"), int(SIGHASH_NONE)},
721  {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
722  {std::string("SINGLE"), int(SIGHASH_SINGLE)},
723  {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
724  };
725  std::string strHashType = request.params[3].get_str();
726  if (mapSigHashValues.count(strHashType))
727  nHashType = mapSigHashValues[strHashType];
728  else
729  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
730  }
731 
732  bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
733 
734  // Script verification errors
735  UniValue vErrors(UniValue::VARR);
736 
737  // Use CTransaction for the constant parts of the
738  // transaction to avoid rehashing.
739  const CTransaction txConst(mergedTx);
740  // Sign what we can:
741  for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
742  CTxIn& txin = mergedTx.vin[i];
743  const Coin& coin = view.AccessCoin(txin.prevout);
744  if (Params().IsRegTestNet()) {
745  if (mapPrevOut.count(txin.prevout) == 0 && coin.IsSpent())
746  {
747  TxInErrorToJSON(txin, vErrors, "Input not found");
748  continue;
749  }
750  } else {
751  if (coin.IsSpent()) {
752  TxInErrorToJSON(txin, vErrors, "Input not found or already spent");
753  continue;
754  }
755  }
756 
757  const CScript& prevPubKey = (Params().IsRegTestNet() && mapPrevOut.count(txin.prevout) != 0 ? mapPrevOut[txin.prevout].first : coin.out.scriptPubKey);
758  const CAmount& amount = (Params().IsRegTestNet() && mapPrevOut.count(txin.prevout) != 0 ? mapPrevOut[txin.prevout].second : coin.out.nValue);
759 
760  txin.scriptSig.clear();
761 
762  // if this is a P2CS script, select which key to use
763  bool fColdStake = false;
764  if (prevPubKey.IsPayToColdStaking()) {
765  // if we have both keys, sign with the spender key
766  fColdStake = !bool(IsMine(keystore, prevPubKey) & ISMINE_SPENDABLE_DELEGATED);
767  }
768 
769  SignatureData sigdata;
770  SigVersion sigversion = mergedTx.GetRequiredSigVersion();
771  // Only sign SIGHASH_SINGLE if there's a corresponding output:
772  if (!fHashSingle || (i < mergedTx.vout.size()))
773  ProduceSignature(MutableTransactionSignatureCreator(&keystore, &mergedTx, i, amount, nHashType),
774  prevPubKey, sigdata, sigversion, fColdStake);
775 
776  // ... and merge in other signatures:
777  for (const CMutableTransaction& txv : txVariants) {
778  sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(txv, i));
779  }
780 
781  UpdateTransaction(mergedTx, i, sigdata);
782 
783  ScriptError serror = SCRIPT_ERR_OK;
784  if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS,
785  TransactionSignatureChecker(&txConst, i, amount), sigversion, &serror)) {
786  TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
787  }
788  }
789  bool fComplete = vErrors.empty();
790 
791  UniValue result(UniValue::VOBJ);
792  result.pushKV("hex", EncodeHexTx(mergedTx));
793  result.pushKV("complete", fComplete);
794  if (!vErrors.empty()) {
795  result.pushKV("errors", vErrors);
796  }
797 
798  return result;
799 }
800 
801 void TryATMP(const CMutableTransaction& mtx, bool fOverrideFees)
802 {
803  const uint256& hashTx = mtx.GetHash();
804  std::promise<void> promise;
805  bool fLimitFree = true;
806 
807  { // cs_main scope
808  LOCK(cs_main);
809  CCoinsViewCache& view = *pcoinsTip;
810  bool fHaveChain = false;
811  for (size_t o = 0; !fHaveChain && o < mtx.vout.size(); o++) {
812  const Coin& existingCoin = view.AccessCoin(COutPoint(hashTx, o));
813  fHaveChain = !existingCoin.IsSpent();
814  }
815  bool fHaveMempool = mempool.exists(hashTx);
816  if (!fHaveMempool && !fHaveChain) {
817  CValidationState state;
818  bool fMissingInputs;
819  if (!AcceptToMemoryPool(mempool, state, MakeTransactionRef(std::move(mtx)), fLimitFree, &fMissingInputs, false, !fOverrideFees)) {
820  if (state.IsInvalid()) {
822  } else {
823  if (fMissingInputs) {
824  throw JSONRPCError(RPC_TRANSACTION_ERROR, "Missing inputs");
825  }
826  throw JSONRPCError(RPC_TRANSACTION_ERROR, strprintf("%s: %s", state.GetRejectReason(), state.GetDebugMessage()));
827  }
828  } else {
829  // If wallet is enabled, ensure that the wallet has been made aware
830  // of the new transaction prior to returning. This prevents a race
831  // where a user might call sendrawtransaction with a transaction
832  // to/from their wallet, immediately call some wallet RPC, and get
833  // a stale result because callbacks have not yet been processed.
835  promise.set_value();
836  });
837  }
838  } else if (fHaveChain) {
839  throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain");
840  }
841 
842  } // cs_main
843 
844  promise.get_future().wait();
845 }
846 
847 void RelayTx(const uint256& hashTx)
848 {
849  if(!g_connman)
850  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
851 
852  CInv inv(MSG_TX, hashTx);
853  g_connman->ForEachNode([&inv](CNode* pnode)
854  {
855  pnode->PushInventory(inv);
856  });
857 }
858 
860 {
861  if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
862  throw std::runtime_error(
863  "sendrawtransaction \"hexstring\" ( allowhighfees )\n"
864  "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
865  "\nAlso see createrawtransaction and signrawtransaction calls.\n"
866 
867  "\nArguments:\n"
868  "1. \"hexstring\" (string, required) The hex string of the raw transaction)\n"
869  "2. allowhighfees (boolean, optional, default=false) Allow high fees\n"
870 
871  "\nResult:\n"
872  "\"hex\" (string) The transaction hash in hex\n"
873 
874  "\nExamples:\n"
875  "\nCreate a transaction\n" +
876  HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
877  "Sign the transaction, and get back the hex\n" + HelpExampleCli("signrawtransaction", "\"myhex\"") +
878  "\nSend the transaction (signed hex)\n" + HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
879  "\nAs a json rpc call\n" + HelpExampleRpc("sendrawtransaction", "\"signedhex\""));
880 
881  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL});
882 
883  // parse hex string from parameter
885  if (!DecodeHexTx(mtx, request.params[0].get_str()))
886  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
887  const uint256& hashTx = mtx.GetHash();
888 
889  bool fOverrideFees = false;
890  if (request.params.size() > 1)
891  fOverrideFees = request.params[1].get_bool();
892 
893  TryATMP(mtx, fOverrideFees);
894  RelayTx(hashTx);
895 
896  return hashTx.GetHex();
897 }
898 
899 // clang-format off
900 static const CRPCCommand commands[] =
901 { // category name actor (function) okSafe argNames
902  // --------------------- ------------------------ ----------------------- ------ --------
903  { "rawtransactions", "createrawtransaction", &createrawtransaction, true, {"inputs","outputs","locktime"} },
904  { "rawtransactions", "decoderawtransaction", &decoderawtransaction, true, {"hexstring"} },
905  { "rawtransactions", "decodescript", &decodescript, true, {"hexstring"} },
906  { "rawtransactions", "getrawtransaction", &getrawtransaction, true, {"txid","verbose","blockhash"} },
907  { "rawtransactions", "sendrawtransaction", &sendrawtransaction, false, {"hexstring","allowhighfees"} },
908  { "rawtransactions", "signrawtransaction", &signrawtransaction, false, {"hexstring","prevtxs","privkeys","sighashtype"} }, /* uses wallet if enabled */
909 };
910 // clang-format on
911 
913 {
914  for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
915  tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
916 }
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
@ BLOCK_HAVE_DATA
Definition: chain.h:117
const CChainParams & Params()
Return the currently selected parameters.
uint256 hash
Definition: transaction.h:35
uint32_t n
Definition: transaction.h:36
bool empty() const
Definition: streams.h:166
Basic key store, that keeps keys in an address->secret map.
Definition: keystore.h:99
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
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
uint256 GetBlockHash() const
Definition: chain.h:215
int64_t GetBlockTime() const
Definition: chain.h:216
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:151
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:175
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:405
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:435
bool IsRegTestNet() const
Definition: chainparams.h:98
void SetBackend(CCoinsView &viewIn)
Definition: coins.cpp:38
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:283
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool potential_overwrite)
Add a coin.
Definition: coins.cpp:94
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to a Coin in the cache, or a pruned one if not found.
Definition: coins.cpp:151
Abstract view on the open txout dataset.
Definition: coins.h:201
CCoinsView that brings transactions from a memorypool into view.
Definition: txmempool.h:729
inv message data
Definition: protocol.h:466
An encapsulated private key.
Definition: key.h:30
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:95
A virtual base class for key stores.
Definition: keystore.h:23
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:14
Information about a peer.
Definition: net.h:669
void PushInventory(const CInv &inv)
Definition: net.h:914
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:72
std::string name
Definition: server.h:137
PIVX RPC command dispatcher.
Definition: server.h:147
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:314
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
bool IsPayToScriptHash() const
Definition: script.cpp:223
void clear()
Definition: script.h:659
bool IsPayToColdStaking() const
Definition: script.cpp:233
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:24
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:244
const int16_t nType
Definition: transaction.h:273
bool IsShieldedTx() const
Definition: transaction.h:319
bool IsSpecialTx() const
Definition: transaction.h:329
An input of a transaction.
Definition: transaction.h:94
uint32_t nSequence
Definition: transaction.h:98
static const uint32_t SEQUENCE_FINAL
Definition: transaction.h:102
CScript scriptSig
Definition: transaction.h:97
COutPoint prevout
Definition: transaction.h:96
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:471
bool exists(uint256 hash) const
Definition: txmempool.h:640
An output of a transaction.
Definition: transaction.h:137
CScript scriptPubKey
Definition: transaction.h:140
CAmount nValue
Definition: transaction.h:139
Capture information about block/transaction validation.
Definition: validation.h:24
std::string GetRejectReason() const
Definition: validation.h:94
bool IsInvalid() const
Definition: validation.h:73
std::string GetDebugMessage() const
Definition: validation.h:95
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
RecursiveMutex cs_wallet
Definition: wallet.h:720
SaplingScriptPubKeyMan * GetSaplingScriptPubKeyMan() const
Definition: wallet.h:712
A UTXO entry.
Definition: coins.h:32
CTxOut out
unspent transaction output
Definition: coins.h:41
bool IsSpent() const
Definition: coins.h:86
uint32_t nHeight
at which height the containing transaction was included in the active block chain
Definition: coins.h:44
UniValue params
Definition: server.h:47
bool fHelp
Definition: server.h:48
std::vector< libzcash::SaplingPaymentAddress > FindMySaplingAddresses(const CTransaction &tx) const
Find all of the addresses in the given tx that have been sent to a SaplingPaymentAddress in this wall...
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:21
@ VSTR
Definition: univalue.h:21
@ VARR
Definition: univalue.h:21
@ VNUM
Definition: univalue.h:21
int64_t get_int64() const
bool isNull() const
Definition: univalue.h:77
const UniValue & get_obj() const
size_t size() const
Definition: univalue.h:68
const std::vector< std::string > & getKeys() const
bool empty() const
Definition: univalue.h:66
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
const UniValue & get_array() const
bool exists(const std::string &key) const
Definition: univalue.h:75
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
bool isNum() const
Definition: univalue.h:82
bool get_bool() const
bool isObject() const
Definition: univalue.h:84
int get_int() const
std::string ToString() const
Definition: uint256.cpp:65
std::string GetHex() const
Definition: uint256.cpp:21
256-bit opaque blob.
Definition: uint256.h:138
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_write.cpp:116
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
Definition: core_write.cpp:123
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
Definition: core_read.cpp:77
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
Definition: core_write.cpp:72
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry)
Definition: core_write.cpp:166
bool HasSaplingSPKM() const
Definition: wallet.cpp:706
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:90
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror)
@ SIGHASH_ANYONECANPAY
Definition: interpreter.h:27
@ SIGHASH_ALL
Definition: interpreter.h:24
@ SIGHASH_NONE
Definition: interpreter.h:25
@ SIGHASH_SINGLE
Definition: interpreter.h:26
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Definition: ismine.cpp:29
@ ISMINE_SPENDABLE_DELEGATED
Indicates that we have the spending key of a P2CS.
Definition: ismine.h:26
@ LOCK
Definition: lockunlock.h:16
std::string EncodePaymentAddress(const libzcash::PaymentAddress &zaddr)
CKey DecodeSecret(const std::string &str)
Definition: key_io.cpp:127
bool IsValidDestination(const CWDestination &address)
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
CWDestination DecodeDestination(const std::string &strAddress)
std::unique_ptr< CChainLocksHandler > chainLocksHandler
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
#define ENABLE_WALLET
Definition: pivx-config.h:42
@ MSG_TX
Definition: protocol.h:436
void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC)
Register raw transaction RPC commands.
std::string GetSaplingTxHelpInfo()
void TryATMP(const CMutableTransaction &mtx, bool fOverrideFees)
UniValue signrawtransaction(const JSONRPCRequest &request)
UniValue getrawtransaction(const JSONRPCRequest &request)
void RelayTx(const uint256 &hashTx)
void TxToJSON(CWallet *const pwallet, const CTransaction &tx, const CBlockIndex *tip, const CBlockIndex *blockindex, UniValue &entry)
int ComputeNextBlockAndDepth(const CBlockIndex *tip, const CBlockIndex *blockindex, const CBlockIndex *&next)
Definition: blockchain.cpp:106
UniValue createrawtransaction(const JSONRPCRequest &request)
UniValue decoderawtransaction(const JSONRPCRequest &request)
UniValue sendrawtransaction(const JSONRPCRequest &request)
UniValue decodescript(const JSONRPCRequest &request)
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:53
@ RPC_MISC_ERROR
General application defined errors.
Definition: protocol.h:41
@ RPC_TRANSACTION_ALREADY_IN_CHAIN
Definition: protocol.h:58
@ RPC_TRANSACTION_REJECTED
Definition: protocol.h:57
@ RPC_TRANSACTION_ERROR
RPC method is deprecated.
Definition: protocol.h:56
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
Definition: protocol.h:46
@ RPC_DESERIALIZATION_ERROR
Database error.
Definition: protocol.h:48
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
Definition: protocol.h:44
@ RPC_CLIENT_P2P_DISABLED
Invalid IP/Subnet.
Definition: protocol.h:67
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: rpcwallet.cpp:39
std::string HelpRequiringPassphrase(CWallet *const pwallet)
Definition: rpcwallet.cpp:54
void EnsureWalletIsUnlocked(CWallet *const pwallet, bool fAllowAnonOnly)
Definition: rpcwallet.cpp:71
const char * ScriptErrorString(const ScriptError serror)
Definition: script_error.cpp:9
enum ScriptError_t ScriptError
@ SCRIPT_ERR_OK
Definition: script_error.h:12
@ SER_NETWORK
Definition: serialize.h:174
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
Definition: server.cpp:151
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:527
void RPCTypeCheck(const UniValue &params, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:63
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:116
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: server.cpp:147
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
Definition: server.cpp:160
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:138
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:532
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
Check for expected keys/value types in an Object.
Definition: server.cpp:89
CRPCTable tableRPC
Definition: server.cpp:565
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
Definition: sign.cpp:186
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn)
Extract signature data from a transaction, and insert it.
Definition: sign.cpp:178
SignatureData CombineSignatures(const CScript &scriptPubKey, const BaseSignatureChecker &checker, const SignatureData &scriptSig1, const SignatureData &scriptSig2)
Combine two script signatures using a generic signature checker, intelligently, possibly with OP_0 pl...
Definition: sign.cpp:337
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata, SigVersion sigversion, bool fColdStake, ScriptError *serror)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:153
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
Definition: standard.cpp:278
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72
A mutable version of CTransaction.
Definition: transaction.h:409
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
Definition: transaction.cpp:96
SigVersion GetRequiredSigVersion() const
Definition: transaction.h:450
std::vector< CTxOut > vout
Definition: transaction.h:411
std::vector< CTxIn > vin
Definition: transaction.h:410
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
Definition: server.h:35
#define LOCK2(cs1, cs2)
Definition: sync.h:221
#define strprintf
Definition: tinyformat.h:1056
SigVersion
Definition: transaction.h:26
bool GetTxPayload(const std::vector< unsigned char > &payload, T &obj)
Definition: transaction.h:464
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:456
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:234
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
#define ARRAYLEN(array)
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
Definition: validation.cpp:671
CTxMemPool mempool(::minRelayTxFee)
bool fTxIndex
Definition: validation.cpp:96
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:206
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectInsaneFee, bool ignoreFees)
(try to) add transaction to memory pool
Definition: validation.cpp:649
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:84
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:345
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...