Bitcoin ABC  0.24.10
P2P Digital Currency
rawtransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <blockdb.h>
7 #include <chain.h>
8 #include <chainparams.h>
9 #include <coins.h>
10 #include <config.h>
11 #include <consensus/validation.h>
12 #include <core_io.h>
13 #include <index/txindex.h>
14 #include <key_io.h>
15 #include <merkleblock.h>
16 #include <network.h>
17 #include <node/coin.h>
18 #include <node/context.h>
19 #include <node/psbt.h>
20 #include <node/transaction.h>
21 #include <policy/policy.h>
22 #include <primitives/transaction.h>
23 #include <psbt.h>
24 #include <random.h>
25 #include <rpc/blockchain.h>
27 #include <rpc/server.h>
28 #include <rpc/util.h>
29 #include <script/script.h>
30 #include <script/sign.h>
31 #include <script/signingprovider.h>
32 #include <script/standard.h>
33 #include <txmempool.h>
34 #include <uint256.h>
35 #include <util/bip32.h>
36 #include <util/error.h>
37 #include <util/moneystr.h>
38 #include <util/strencodings.h>
39 #include <util/string.h>
40 #include <validation.h>
41 #include <validationinterface.h>
42 
43 #include <cstdint>
44 #include <numeric>
45 
46 #include <univalue.h>
47 
48 static void TxToJSON(const CTransaction &tx, const BlockHash &hashBlock,
49  UniValue &entry) {
50  // Call into TxToUniv() in bitcoin-common to decode the transaction hex.
51  //
52  // Blockchain contextual information (confirmations and blocktime) is not
53  // available to code in bitcoin-common, so we query them here and push the
54  // data into the returned UniValue.
55  TxToUniv(tx, uint256(), entry, true, RPCSerializationFlags());
56 
57  if (!hashBlock.IsNull()) {
58  LOCK(cs_main);
59 
60  entry.pushKV("blockhash", hashBlock.GetHex());
61  CBlockIndex *pindex = LookupBlockIndex(hashBlock);
62  if (pindex) {
63  if (::ChainActive().Contains(pindex)) {
64  entry.pushKV("confirmations",
65  1 + ::ChainActive().Height() - pindex->nHeight);
66  entry.pushKV("time", pindex->GetBlockTime());
67  entry.pushKV("blocktime", pindex->GetBlockTime());
68  } else {
69  entry.pushKV("confirmations", 0);
70  }
71  }
72  }
73 }
74 
76  return RPCHelpMan{
77  "getrawtransaction",
78  "By default this function only works for mempool transactions. When "
79  "called with a blockhash\n"
80  "argument, getrawtransaction will return the transaction if the "
81  "specified block is available and\n"
82  "the transaction is found in that block. When called without a "
83  "blockhash argument, getrawtransaction\n"
84  "will return the transaction if it is in the mempool, or if -txindex "
85  "is enabled and the transaction\n"
86  "is in a block in the blockchain.\n"
87 
88  "\nReturn the raw transaction data.\n"
89  "\nIf verbose is 'true', returns an Object with information about "
90  "'txid'.\n"
91  "If verbose is 'false' or omitted, returns a string that is "
92  "serialized, hex-encoded data for 'txid'.\n",
93  {
95  "The transaction id"},
96  {"verbose", RPCArg::Type::BOOL, /* default */ "false",
97  "If false, return a string, otherwise return a json object"},
98  {"blockhash", RPCArg::Type::STR_HEX,
100  "The block in which to look for the transaction"},
101  },
102  {
103  RPCResult{"if verbose is not set or set to false",
104  RPCResult::Type::STR, "data",
105  "The serialized, hex-encoded data for 'txid'"},
106  RPCResult{
107  "if verbose is set to true",
109  "",
110  "",
111  {
112  {RPCResult::Type::BOOL, "in_active_chain",
113  "Whether specified block is in the active chain or not "
114  "(only present with explicit \"blockhash\" argument)"},
115  {RPCResult::Type::STR_HEX, "hex",
116  "The serialized, hex-encoded data for 'txid'"},
117  {RPCResult::Type::STR_HEX, "txid",
118  "The transaction id (same as provided)"},
119  {RPCResult::Type::STR_HEX, "hash", "The transaction hash"},
120  {RPCResult::Type::NUM, "size",
121  "The serialized transaction size"},
122  {RPCResult::Type::NUM, "version", "The version"},
123  {RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
125  "vin",
126  "",
127  {
129  "",
130  "",
131  {
132  {RPCResult::Type::STR_HEX, "txid",
133  "The transaction id"},
134  {RPCResult::Type::STR, "vout", ""},
136  "scriptSig",
137  "The script",
138  {
139  {RPCResult::Type::STR, "asm", "asm"},
140  {RPCResult::Type::STR_HEX, "hex", "hex"},
141  }},
142  {RPCResult::Type::NUM, "sequence",
143  "The script sequence number"},
144  }},
145  }},
147  "vout",
148  "",
149  {
151  "",
152  "",
153  {
154  {RPCResult::Type::NUM, "value",
155  "The value in " + Currency::get().ticker},
156  {RPCResult::Type::NUM, "n", "index"},
158  "scriptPubKey",
159  "",
160  {
161  {RPCResult::Type::STR, "asm", "the asm"},
162  {RPCResult::Type::STR, "hex", "the hex"},
163  {RPCResult::Type::NUM, "reqSigs",
164  "The required sigs"},
165  {RPCResult::Type::STR, "type",
166  "The type, eg 'pubkeyhash'"},
168  "addresses",
169  "",
170  {
171  {RPCResult::Type::STR, "address",
172  "bitcoin address"},
173  }},
174  }},
175  }},
176  }},
177  {RPCResult::Type::STR_HEX, "blockhash", "the block hash"},
178  {RPCResult::Type::NUM, "confirmations",
179  "The confirmations"},
180  {RPCResult::Type::NUM_TIME, "blocktime",
181  "The block time expressed in " + UNIX_EPOCH_TIME},
182  {RPCResult::Type::NUM, "time", "Same as \"blocktime\""},
183  }},
184  },
185  RPCExamples{HelpExampleCli("getrawtransaction", "\"mytxid\"") +
186  HelpExampleCli("getrawtransaction", "\"mytxid\" true") +
187  HelpExampleRpc("getrawtransaction", "\"mytxid\", true") +
188  HelpExampleCli("getrawtransaction",
189  "\"mytxid\" false \"myblockhash\"") +
190  HelpExampleCli("getrawtransaction",
191  "\"mytxid\" true \"myblockhash\"")},
192  [&](const RPCHelpMan &self, const Config &config,
193  const JSONRPCRequest &request) -> UniValue {
194  const NodeContext &node = EnsureNodeContext(request.context);
195 
196  bool in_active_chain = true;
197  TxId txid = TxId(ParseHashV(request.params[0], "parameter 1"));
198  CBlockIndex *blockindex = nullptr;
199 
200  const CChainParams &params = config.GetChainParams();
201  if (txid == params.GenesisBlock().hashMerkleRoot) {
202  // Special exception for the genesis block coinbase transaction
203  throw JSONRPCError(
205  "The genesis block coinbase is not considered an "
206  "ordinary transaction and cannot be retrieved");
207  }
208 
209  // Accept either a bool (true) or a num (>=1) to indicate verbose
210  // output.
211  bool fVerbose = false;
212  if (!request.params[1].isNull()) {
213  fVerbose = request.params[1].isNum()
214  ? (request.params[1].get_int() != 0)
215  : request.params[1].get_bool();
216  }
217 
218  if (!request.params[2].isNull()) {
219  LOCK(cs_main);
220 
221  BlockHash blockhash(
222  ParseHashV(request.params[2], "parameter 3"));
223  blockindex = LookupBlockIndex(blockhash);
224  if (!blockindex) {
226  "Block hash not found");
227  }
228  in_active_chain = ::ChainActive().Contains(blockindex);
229  }
230 
231  bool f_txindex_ready = false;
232  if (g_txindex && !blockindex) {
233  f_txindex_ready = g_txindex->BlockUntilSyncedToCurrentChain();
234  }
235 
236  BlockHash hash_block;
237  const CTransactionRef tx =
238  GetTransaction(blockindex, node.mempool.get(), txid,
239  params.GetConsensus(), hash_block);
240  if (!tx) {
241  std::string errmsg;
242  if (blockindex) {
243  if (!blockindex->nStatus.hasData()) {
245  "Block not available");
246  }
247  errmsg = "No such transaction found in the provided block";
248  } else if (!g_txindex) {
249  errmsg =
250  "No such mempool transaction. Use -txindex or provide "
251  "a block hash to enable blockchain transaction queries";
252  } else if (!f_txindex_ready) {
253  errmsg = "No such mempool transaction. Blockchain "
254  "transactions are still in the process of being "
255  "indexed";
256  } else {
257  errmsg = "No such mempool or blockchain transaction";
258  }
259  throw JSONRPCError(
261  errmsg + ". Use gettransaction for wallet transactions.");
262  }
263 
264  if (!fVerbose) {
265  return EncodeHexTx(*tx, RPCSerializationFlags());
266  }
267 
268  UniValue result(UniValue::VOBJ);
269  if (blockindex) {
270  result.pushKV("in_active_chain", in_active_chain);
271  }
272  TxToJSON(*tx, hash_block, result);
273  return result;
274  },
275  };
276 }
277 
279  return RPCHelpMan{
280  "gettxoutproof",
281  "Returns a hex-encoded proof that \"txid\" was included in a block.\n"
282  "\nNOTE: By default this function only works sometimes. "
283  "This is when there is an\n"
284  "unspent output in the utxo for this transaction. To make it always "
285  "work,\n"
286  "you need to maintain a transaction index, using the -txindex command "
287  "line option or\n"
288  "specify the block in which the transaction is included manually (by "
289  "blockhash).\n",
290  {
291  {
292  "txids",
295  "The txids to filter",
296  {
298  "A transaction hash"},
299  },
300  },
301  {"blockhash", RPCArg::Type::STR_HEX,
303  "If specified, looks for txid in the block with this hash"},
304  },
305  RPCResult{
306  RPCResult::Type::STR, "data",
307  "A string that is a serialized, hex-encoded data for the proof."},
308  RPCExamples{""},
309  [&](const RPCHelpMan &self, const Config &config,
310  const JSONRPCRequest &request) -> UniValue {
311  std::set<TxId> setTxIds;
312  TxId oneTxId;
313  UniValue txids = request.params[0].get_array();
314  for (unsigned int idx = 0; idx < txids.size(); idx++) {
315  const UniValue &utxid = txids[idx];
316  TxId txid(ParseHashV(utxid, "txid"));
317  if (setTxIds.count(txid)) {
318  throw JSONRPCError(
320  std::string("Invalid parameter, duplicated txid: ") +
321  utxid.get_str());
322  }
323 
324  setTxIds.insert(txid);
325  oneTxId = txid;
326  }
327 
328  CBlockIndex *pblockindex = nullptr;
329 
330  BlockHash hashBlock;
331  if (!request.params[1].isNull()) {
332  LOCK(cs_main);
333  hashBlock =
334  BlockHash(ParseHashV(request.params[1], "blockhash"));
335  pblockindex = LookupBlockIndex(hashBlock);
336  if (!pblockindex) {
338  "Block not found");
339  }
340  } else {
341  LOCK(cs_main);
342  // Loop through txids and try to find which block they're in.
343  // Exit loop once a block is found.
344  for (const auto &txid : setTxIds) {
345  const Coin &coin =
346  AccessByTxid(::ChainstateActive().CoinsTip(), txid);
347  if (!coin.IsSpent()) {
348  pblockindex = ::ChainActive()[coin.GetHeight()];
349  break;
350  }
351  }
352  }
353 
354  // Allow txindex to catch up if we need to query it and before we
355  // acquire cs_main.
356  if (g_txindex && !pblockindex) {
357  g_txindex->BlockUntilSyncedToCurrentChain();
358  }
359 
360  const Consensus::Params &params =
361  config.GetChainParams().GetConsensus();
362 
363  LOCK(cs_main);
364 
365  if (pblockindex == nullptr) {
366  const CTransactionRef tx = GetTransaction(
367  /* block_index */ nullptr,
368  /* mempool */ nullptr, oneTxId, Params().GetConsensus(),
369  hashBlock);
370  if (!tx || hashBlock.IsNull()) {
372  "Transaction not yet in block");
373  }
374 
375  pblockindex = LookupBlockIndex(hashBlock);
376  if (!pblockindex) {
378  "Transaction index corrupt");
379  }
380  }
381 
382  CBlock block;
383  if (!ReadBlockFromDisk(block, pblockindex, params)) {
385  "Can't read block from disk");
386  }
387 
388  unsigned int ntxFound = 0;
389  for (const auto &tx : block.vtx) {
390  if (setTxIds.count(tx->GetId())) {
391  ntxFound++;
392  }
393  }
394 
395  if (ntxFound != setTxIds.size()) {
397  "Not all transactions found in specified or "
398  "retrieved block");
399  }
400 
402  CMerkleBlock mb(block, setTxIds);
403  ssMB << mb;
404  std::string strHex = HexStr(ssMB);
405  return strHex;
406  },
407  };
408 }
409 
411  return RPCHelpMan{
412  "verifytxoutproof",
413  "Verifies that a proof points to a transaction in a block, returning "
414  "the transaction it commits to\n"
415  "and throwing an RPC error if the block is not in our best chain\n",
416  {
418  "The hex-encoded proof generated by gettxoutproof"},
419  },
421  "",
422  "",
423  {
424  {RPCResult::Type::STR_HEX, "txid",
425  "The txid(s) which the proof commits to, or empty array "
426  "if the proof can not be validated."},
427  }},
428  RPCExamples{""},
429  [&](const RPCHelpMan &self, const Config &config,
430  const JSONRPCRequest &request) -> UniValue {
431  CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK,
433  CMerkleBlock merkleBlock;
434  ssMB >> merkleBlock;
435 
437 
438  std::vector<uint256> vMatch;
439  std::vector<size_t> vIndex;
440  if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) !=
441  merkleBlock.header.hashMerkleRoot) {
442  return res;
443  }
444 
445  LOCK(cs_main);
446 
447  const CBlockIndex *pindex =
448  LookupBlockIndex(merkleBlock.header.GetHash());
449  if (!pindex || !::ChainActive().Contains(pindex) ||
450  pindex->nTx == 0) {
452  "Block not found in chain");
453  }
454 
455  // Check if proof is valid, only add results if so
456  if (pindex->nTx == merkleBlock.txn.GetNumTransactions()) {
457  for (const uint256 &hash : vMatch) {
458  res.push_back(hash.GetHex());
459  }
460  }
461 
462  return res;
463  },
464  };
465 }
466 
468  return RPCHelpMan{
469  "createrawtransaction",
470  "Create a transaction spending the given inputs and creating new "
471  "outputs.\n"
472  "Outputs can be addresses or data.\n"
473  "Returns hex-encoded raw transaction.\n"
474  "Note that the transaction's inputs are not signed, and\n"
475  "it is not stored in the wallet or transmitted to the network.\n",
476  {
477  {
478  "inputs",
481  "The inputs",
482  {
483  {
484  "",
487  "",
488  {
489  {"txid", RPCArg::Type::STR_HEX,
490  RPCArg::Optional::NO, "The transaction id"},
492  "The output number"},
493  {"sequence", RPCArg::Type::NUM, /* default */
494  "depends on the value of the 'locktime' argument",
495  "The sequence number"},
496  },
497  },
498  },
499  },
500  {
501  "outputs",
504  "The outputs (key-value pairs), where none of "
505  "the keys are duplicated.\n"
506  "That is, each address can only appear once and there can only "
507  "be one 'data' object.\n"
508  "For compatibility reasons, a dictionary, which holds the "
509  "key-value pairs directly, is also\n"
510  " accepted as second parameter.",
511  {
512  {
513  "",
516  "",
517  {
518  {"address", RPCArg::Type::AMOUNT,
520  "A key-value pair. The key (string) is the "
521  "bitcoin address, the value (float or string) is "
522  "the amount in " +
524  },
525  },
526  {
527  "",
530  "",
531  {
532  {"data", RPCArg::Type::STR_HEX,
534  "A key-value pair. The key must be \"data\", the "
535  "value is hex-encoded data"},
536  },
537  },
538  },
539  },
540  {"locktime", RPCArg::Type::NUM, /* default */ "0",
541  "Raw locktime. Non-0 value also locktime-activates inputs"},
542  },
543  RPCResult{RPCResult::Type::STR_HEX, "transaction",
544  "hex string of the transaction"},
545  RPCExamples{
546  HelpExampleCli("createrawtransaction",
547  "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
548  "\" \"[{\\\"address\\\":10000.00}]\"") +
549  HelpExampleCli("createrawtransaction",
550  "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
551  "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
552  HelpExampleRpc("createrawtransaction",
553  "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
554  "\", \"[{\\\"address\\\":10000.00}]\"") +
555  HelpExampleRpc("createrawtransaction",
556  "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
557  "\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")},
558  [&](const RPCHelpMan &self, const Config &config,
559  const JSONRPCRequest &request) -> UniValue {
560  RPCTypeCheck(request.params,
561  {UniValue::VARR,
562  UniValueType(), // ARR or OBJ, checked later
563  UniValue::VNUM},
564  true);
565 
566  CMutableTransaction rawTx =
567  ConstructTransaction(config.GetChainParams(), request.params[0],
568  request.params[1], request.params[2]);
569 
570  return EncodeHexTx(CTransaction(rawTx));
571  },
572  };
573 }
574 
576  return RPCHelpMan{
577  "decoderawtransaction",
578  "Return a JSON object representing the serialized, hex-encoded "
579  "transaction.\n",
580  {
582  "The transaction hex string"},
583  },
584  RPCResult{
586  "",
587  "",
588  {
589  {RPCResult::Type::STR_HEX, "txid", "The transaction id"},
590  {RPCResult::Type::STR_HEX, "hash", "The transaction hash"},
591  {RPCResult::Type::NUM, "size", "The transaction size"},
592  {RPCResult::Type::NUM, "version", "The version"},
593  {RPCResult::Type::NUM_TIME, "locktime", "The lock time"},
595  "vin",
596  "",
597  {
599  "",
600  "",
601  {
602  {RPCResult::Type::STR_HEX, "txid",
603  "The transaction id"},
604  {RPCResult::Type::NUM, "vout", "The output number"},
606  "scriptSig",
607  "The script",
608  {
609  {RPCResult::Type::STR, "asm", "asm"},
610  {RPCResult::Type::STR_HEX, "hex", "hex"},
611  }},
612  {RPCResult::Type::NUM, "sequence",
613  "The script sequence number"},
614  }},
615  }},
617  "vout",
618  "",
619  {
621  "",
622  "",
623  {
624  {RPCResult::Type::NUM, "value",
625  "The value in " + Currency::get().ticker},
626  {RPCResult::Type::NUM, "n", "index"},
628  "scriptPubKey",
629  "",
630  {
631  {RPCResult::Type::STR, "asm", "the asm"},
632  {RPCResult::Type::STR_HEX, "hex", "the hex"},
633  {RPCResult::Type::NUM, "reqSigs",
634  "The required sigs"},
635  {RPCResult::Type::STR, "type",
636  "The type, eg 'pubkeyhash'"},
638  "addresses",
639  "",
640  {
641  {RPCResult::Type::STR, "address",
642  "bitcoin address"},
643  }},
644  }},
645  }},
646  }},
647  }},
648  RPCExamples{HelpExampleCli("decoderawtransaction", "\"hexstring\"") +
649  HelpExampleRpc("decoderawtransaction", "\"hexstring\"")},
650  [&](const RPCHelpMan &self, const Config &config,
651  const JSONRPCRequest &request) -> UniValue {
652  RPCTypeCheck(request.params, {UniValue::VSTR});
653 
655 
656  if (!DecodeHexTx(mtx, request.params[0].get_str())) {
658  "TX decode failed");
659  }
660 
661  UniValue result(UniValue::VOBJ);
662  TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false);
663 
664  return result;
665  },
666  };
667 }
668 
670  return RPCHelpMan{
671  "decodescript",
672  "Decode a hex-encoded script.\n",
673  {
675  "the hex-encoded script"},
676  },
677  RPCResult{
679  "",
680  "",
681  {
682  {RPCResult::Type::STR, "asm", "Script public key"},
683  {RPCResult::Type::STR, "type",
684  "The output type (e.g. " + GetAllOutputTypes() + ")"},
685  {RPCResult::Type::NUM, "reqSigs", "The required signatures"},
687  "addresses",
688  "",
689  {
690  {RPCResult::Type::STR, "address", "bitcoin address"},
691  }},
692  {RPCResult::Type::STR, "p2sh",
693  "address of P2SH script wrapping this redeem script (not "
694  "returned if the script is already a P2SH)"},
695  }},
696  RPCExamples{HelpExampleCli("decodescript", "\"hexstring\"") +
697  HelpExampleRpc("decodescript", "\"hexstring\"")},
698  [&](const RPCHelpMan &self, const Config &config,
699  const JSONRPCRequest &request) -> UniValue {
700  RPCTypeCheck(request.params, {UniValue::VSTR});
701 
703  CScript script;
704  if (request.params[0].get_str().size() > 0) {
705  std::vector<uint8_t> scriptData(
706  ParseHexV(request.params[0], "argument"));
707  script = CScript(scriptData.begin(), scriptData.end());
708  } else {
709  // Empty scripts are valid.
710  }
711 
712  ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
713 
714  UniValue type;
715  type = find_value(r, "type");
716 
717  if (type.isStr() && type.get_str() != "scripthash") {
718  // P2SH cannot be wrapped in a P2SH. If this script is already a
719  // P2SH, don't return the address for a P2SH of the P2SH.
720  r.pushKV("p2sh", EncodeDestination(ScriptHash(script), config));
721  }
722 
723  return r;
724  },
725  };
726 }
727 
729  return RPCHelpMan{
730  "combinerawtransaction",
731  "Combine multiple partially signed transactions into one "
732  "transaction.\n"
733  "The combined transaction may be another partially signed transaction "
734  "or a \n"
735  "fully signed transaction.",
736  {
737  {
738  "txs",
741  "The hex strings of partially signed "
742  "transactions",
743  {
744  {"hexstring", RPCArg::Type::STR_HEX,
746  "A hex-encoded raw transaction"},
747  },
748  },
749  },
751  "The hex-encoded raw transaction with signature(s)"},
752  RPCExamples{HelpExampleCli("combinerawtransaction",
753  R"('["myhex1", "myhex2", "myhex3"]')")},
754  [&](const RPCHelpMan &self, const Config &config,
755  const JSONRPCRequest &request) -> UniValue {
756  UniValue txs = request.params[0].get_array();
757  std::vector<CMutableTransaction> txVariants(txs.size());
758 
759  for (unsigned int idx = 0; idx < txs.size(); idx++) {
760  if (!DecodeHexTx(txVariants[idx], txs[idx].get_str())) {
761  throw JSONRPCError(
763  strprintf("TX decode failed for tx %d", idx));
764  }
765  }
766 
767  if (txVariants.empty()) {
769  "Missing transactions");
770  }
771 
772  // mergedTx will end up with all the signatures; it
773  // starts as a clone of the rawtx:
774  CMutableTransaction mergedTx(txVariants[0]);
775 
776  // Fetch previous transactions (inputs):
777  CCoinsView viewDummy;
778  CCoinsViewCache view(&viewDummy);
779  {
780  const CTxMemPool &mempool = EnsureMemPool(request.context);
781  LOCK(cs_main);
782  LOCK(mempool.cs);
784  CCoinsViewMemPool viewMempool(&viewChain, mempool);
785  // temporarily switch cache backend to db+mempool view
786  view.SetBackend(viewMempool);
787 
788  for (const CTxIn &txin : mergedTx.vin) {
789  // Load entries from viewChain into view; can fail.
790  view.AccessCoin(txin.prevout);
791  }
792 
793  // switch back to avoid locking mempool for too long
794  view.SetBackend(viewDummy);
795  }
796 
797  // Use CTransaction for the constant parts of the
798  // transaction to avoid rehashing.
799  const CTransaction txConst(mergedTx);
800  // Sign what we can:
801  for (size_t i = 0; i < mergedTx.vin.size(); i++) {
802  CTxIn &txin = mergedTx.vin[i];
803  const Coin &coin = view.AccessCoin(txin.prevout);
804  if (coin.IsSpent()) {
806  "Input not found or already spent");
807  }
808  SignatureData sigdata;
809 
810  const CTxOut &txout = coin.GetTxOut();
811 
812  // ... and merge in other signatures:
813  for (const CMutableTransaction &txv : txVariants) {
814  if (txv.vin.size() > i) {
815  sigdata.MergeSignatureData(
816  DataFromTransaction(txv, i, txout));
817  }
818  }
821  &mergedTx, i, txout.nValue),
822  txout.scriptPubKey, sigdata);
823 
824  UpdateInput(txin, sigdata);
825  }
826 
827  return EncodeHexTx(CTransaction(mergedTx));
828  },
829  };
830 }
831 
833  return RPCHelpMan{
834  "signrawtransactionwithkey",
835  "Sign inputs for raw transaction (serialized, hex-encoded).\n"
836  "The second argument is an array of base58-encoded private\n"
837  "keys that will be the only keys used to sign the transaction.\n"
838  "The third optional argument (may be null) is an array of previous "
839  "transaction outputs that\n"
840  "this transaction depends on but may not yet be in the block chain.\n",
841  {
843  "The transaction hex string"},
844  {
845  "privkeys",
848  "The base58-encoded private keys for signing",
849  {
851  "private key in base58-encoding"},
852  },
853  },
854  {
855  "prevtxs",
858  "The previous dependent transaction outputs",
859  {
860  {
861  "",
864  "",
865  {
866  {"txid", RPCArg::Type::STR_HEX,
867  RPCArg::Optional::NO, "The transaction id"},
869  "The output number"},
870  {"scriptPubKey", RPCArg::Type::STR_HEX,
871  RPCArg::Optional::NO, "script key"},
872  {"redeemScript", RPCArg::Type::STR_HEX,
874  "(required for P2SH) redeem script"},
875  {"amount", RPCArg::Type::AMOUNT,
876  RPCArg::Optional::NO, "The amount spent"},
877  },
878  },
879  },
880  },
881  {"sighashtype", RPCArg::Type::STR, /* default */ "ALL|FORKID",
882  "The signature hash type. Must be one of:\n"
883  " \"ALL|FORKID\"\n"
884  " \"NONE|FORKID\"\n"
885  " \"SINGLE|FORKID\"\n"
886  " \"ALL|FORKID|ANYONECANPAY\"\n"
887  " \"NONE|FORKID|ANYONECANPAY\"\n"
888  " \"SINGLE|FORKID|ANYONECANPAY\""},
889  },
890  RPCResult{
892  "",
893  "",
894  {
895  {RPCResult::Type::STR_HEX, "hex",
896  "The hex-encoded raw transaction with signature(s)"},
897  {RPCResult::Type::BOOL, "complete",
898  "If the transaction has a complete set of signatures"},
900  "errors",
901  /* optional */ true,
902  "Script verification errors (if there are any)",
903  {
905  "",
906  "",
907  {
908  {RPCResult::Type::STR_HEX, "txid",
909  "The hash of the referenced, previous transaction"},
910  {RPCResult::Type::NUM, "vout",
911  "The index of the output to spent and used as "
912  "input"},
913  {RPCResult::Type::STR_HEX, "scriptSig",
914  "The hex-encoded signature script"},
915  {RPCResult::Type::NUM, "sequence",
916  "Script sequence number"},
917  {RPCResult::Type::STR, "error",
918  "Verification or signing error related to the "
919  "input"},
920  }},
921  }},
922  }},
923  RPCExamples{
924  HelpExampleCli("signrawtransactionwithkey",
925  "\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"") +
926  HelpExampleRpc("signrawtransactionwithkey",
927  "\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"")},
928  [&](const RPCHelpMan &self, const Config &config,
929  const JSONRPCRequest &request) -> UniValue {
930  RPCTypeCheck(request.params,
931  {UniValue::VSTR, UniValue::VARR, UniValue::VARR,
932  UniValue::VSTR},
933  true);
934 
936  if (!DecodeHexTx(mtx, request.params[0].get_str())) {
938  "TX decode failed");
939  }
940 
941  FillableSigningProvider keystore;
942  const UniValue &keys = request.params[1].get_array();
943  for (size_t idx = 0; idx < keys.size(); ++idx) {
944  UniValue k = keys[idx];
945  CKey key = DecodeSecret(k.get_str());
946  if (!key.IsValid()) {
948  "Invalid private key");
949  }
950  keystore.AddKey(key);
951  }
952 
953  // Fetch previous transactions (inputs):
954  std::map<COutPoint, Coin> coins;
955  for (const CTxIn &txin : mtx.vin) {
956  // Create empty map entry keyed by prevout.
957  coins[txin.prevout];
958  }
959  NodeContext &node = EnsureNodeContext(request.context);
960  FindCoins(node, coins);
961 
962  // Parse the prevtxs array
963  ParsePrevouts(request.params[2], &keystore, coins);
964 
965  UniValue result(UniValue::VOBJ);
966  SignTransaction(mtx, &keystore, coins, request.params[3], result);
967  return result;
968  },
969  };
970 }
971 
973  return RPCHelpMan{
974  "sendrawtransaction",
975  "Submits raw transaction (serialized, hex-encoded) to local node and "
976  "network.\n"
977  "\nAlso see createrawtransaction and "
978  "signrawtransactionwithkey calls.\n",
979  {
981  "The hex string of the raw transaction"},
982  {"maxfeerate", RPCArg::Type::AMOUNT,
983  /* default */
985  "Reject transactions whose fee rate is higher than the specified "
986  "value, expressed in " +
988  "/kB\nSet to 0 to accept any fee rate.\n"},
989  },
990  RPCResult{RPCResult::Type::STR_HEX, "", "The transaction hash in hex"},
991  RPCExamples{
992  "\nCreate a transaction\n" +
994  "createrawtransaction",
995  "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" "
996  "\"{\\\"myaddress\\\":10000}\"") +
997  "Sign the transaction, and get back the hex\n" +
998  HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
999  "\nSend the transaction (signed hex)\n" +
1000  HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
1001  "\nAs a JSON-RPC call\n" +
1002  HelpExampleRpc("sendrawtransaction", "\"signedhex\"")},
1003  [&](const RPCHelpMan &self, const Config &config,
1004  const JSONRPCRequest &request) -> UniValue {
1005  RPCTypeCheck(request.params,
1006  {
1007  UniValue::VSTR,
1008  // VNUM or VSTR, checked inside AmountFromValue()
1009  UniValueType(),
1010  });
1011 
1012  // parse hex string from parameter
1013  CMutableTransaction mtx;
1014  if (!DecodeHexTx(mtx, request.params[0].get_str())) {
1016  "TX decode failed");
1017  }
1018 
1019  CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
1020 
1021  const CFeeRate max_raw_tx_fee_rate =
1022  request.params[1].isNull()
1024  : CFeeRate(AmountFromValue(request.params[1]));
1025 
1026  int64_t virtual_size = GetVirtualTransactionSize(*tx);
1027  Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
1028 
1029  std::string err_string;
1031  NodeContext &node = EnsureNodeContext(request.context);
1033  node, config, tx, err_string, max_raw_tx_fee, /*relay*/ true,
1034  /*wait_callback*/ true);
1035  if (err != TransactionError::OK) {
1036  throw JSONRPCTransactionError(err, err_string);
1037  }
1038 
1039  return tx->GetHash().GetHex();
1040  },
1041  };
1042 }
1043 
1045  return RPCHelpMan{
1046  "testmempoolaccept",
1047  "Returns result of mempool acceptance tests indicating if raw"
1048  " transaction (serialized, hex-encoded) would be accepted"
1049  " by mempool.\n"
1050  "\nThis checks if the transaction violates the consensus or policy "
1051  "rules.\n"
1052  "\nSee sendrawtransaction call.\n",
1053  {
1054  {
1055  "rawtxs",
1058  "An array of hex strings of raw transactions.\n"
1059  " Length must be one for now.",
1060  {
1062  ""},
1063  },
1064  },
1065  {"maxfeerate", RPCArg::Type::AMOUNT,
1066  /* default */
1068  "Reject transactions whose fee rate is higher than the specified "
1069  "value, expressed in " +
1070  Currency::get().ticker + "/kB\n"},
1071  },
1072  RPCResult{
1074  "",
1075  "The result of the mempool acceptance test for each raw "
1076  "transaction in the input array.\n"
1077  "Length is exactly one for now.",
1078  {
1080  "",
1081  "",
1082  {
1083  {RPCResult::Type::STR_HEX, "txid",
1084  "The transaction hash in hex"},
1085  {RPCResult::Type::BOOL, "allowed",
1086  "If the mempool allows this tx to be inserted"},
1087  {RPCResult::Type::NUM, "size", "The transaction size"},
1089  "fees",
1090  "Transaction fees (only present if 'allowed' is true)",
1091  {
1092  {RPCResult::Type::STR_AMOUNT, "base",
1093  "transaction fee in " + Currency::get().ticker},
1094  }},
1095  {RPCResult::Type::STR, "reject-reason",
1096  "Rejection string (only present when 'allowed' is "
1097  "false)"},
1098  }},
1099  }},
1100  RPCExamples{
1101  "\nCreate a transaction\n" +
1103  "createrawtransaction",
1104  "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" "
1105  "\"{\\\"myaddress\\\":10000}\"") +
1106  "Sign the transaction, and get back the hex\n" +
1107  HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
1108  "\nTest acceptance of the transaction (signed hex)\n" +
1109  HelpExampleCli("testmempoolaccept", R"('["signedhex"]')") +
1110  "\nAs a JSON-RPC call\n" +
1111  HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")},
1112  [&](const RPCHelpMan &self, const Config &config,
1113  const JSONRPCRequest &request) -> UniValue {
1114  RPCTypeCheck(request.params,
1115  {
1116  UniValue::VARR,
1117  // VNUM or VSTR, checked inside AmountFromValue()
1118  UniValueType(),
1119  });
1120 
1121  if (request.params[0].get_array().size() != 1) {
1122  throw JSONRPCError(
1124  "Array must contain exactly one raw transaction for now");
1125  }
1126 
1127  CMutableTransaction mtx;
1128  if (!DecodeHexTx(mtx, request.params[0].get_array()[0].get_str())) {
1130  "TX decode failed");
1131  }
1132  CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
1133  const TxId &txid = tx->GetId();
1134 
1135  const CFeeRate max_raw_tx_fee_rate =
1136  request.params[1].isNull()
1138  : CFeeRate(AmountFromValue(request.params[1]));
1139 
1140  CTxMemPool &mempool = EnsureMemPool(request.context);
1141  int64_t virtual_size = GetVirtualTransactionSize(*tx);
1142  Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
1143 
1144  UniValue result(UniValue::VARR);
1145  UniValue result_0(UniValue::VOBJ);
1146  result_0.pushKV("txid", txid.GetHex());
1147 
1148  TxValidationState state;
1149  bool test_accept_res;
1150  Amount fee = Amount::zero();
1151  {
1152  LOCK(cs_main);
1153  test_accept_res = AcceptToMemoryPool(
1154  config, mempool, state, std::move(tx),
1155  false /* bypass_limits */, true /* test_accept */, &fee);
1156  }
1157 
1158  // Check that fee does not exceed maximum fee
1159  if (test_accept_res && max_raw_tx_fee != Amount::zero() &&
1160  fee > max_raw_tx_fee) {
1161  result_0.pushKV("allowed", false);
1162  result_0.pushKV("reject-reason", "max-fee-exceeded");
1163  result.push_back(std::move(result_0));
1164  return result;
1165  }
1166  result_0.pushKV("allowed", test_accept_res);
1167 
1168  // Only return the fee and size if the transaction would pass ATMP.
1169  // These can be used to calculate the feerate.
1170  if (test_accept_res) {
1171  result_0.pushKV("size", virtual_size);
1172  UniValue fees(UniValue::VOBJ);
1173  fees.pushKV("base", fee);
1174  result_0.pushKV("fees", fees);
1175  } else {
1176  if (state.IsInvalid()) {
1177  if (state.GetResult() ==
1179  result_0.pushKV("reject-reason", "missing-inputs");
1180  } else {
1181  result_0.pushKV(
1182  "reject-reason",
1183  strprintf("%s", state.GetRejectReason()));
1184  }
1185  } else {
1186  result_0.pushKV("reject-reason", state.GetRejectReason());
1187  }
1188  }
1189 
1190  result.push_back(std::move(result_0));
1191  return result;
1192  },
1193  };
1194 }
1195 
1197  return RPCHelpMan{
1198  "decodepsbt",
1199  "Return a JSON object representing the serialized, base64-encoded "
1200  "partially signed Bitcoin transaction.\n",
1201  {
1203  "The PSBT base64 string"},
1204  },
1205  RPCResult{
1207  "",
1208  "",
1209  {
1211  "tx",
1212  "The decoded network-serialized unsigned transaction.",
1213  {
1215  "The layout is the same as the output of "
1216  "decoderawtransaction."},
1217  }},
1219  "unknown",
1220  "The unknown global fields",
1221  {
1222  {RPCResult::Type::STR_HEX, "key",
1223  "(key-value pair) An unknown key-value pair"},
1224  }},
1226  "inputs",
1227  "",
1228  {
1230  "",
1231  "",
1232  {
1234  "utxo",
1235  /* optional */ true,
1236  "Transaction output for UTXOs",
1237  {
1238  {RPCResult::Type::NUM, "amount",
1239  "The value in " + Currency::get().ticker},
1241  "scriptPubKey",
1242  "",
1243  {
1244  {RPCResult::Type::STR, "asm", "The asm"},
1245  {RPCResult::Type::STR_HEX, "hex",
1246  "The hex"},
1247  {RPCResult::Type::STR, "type",
1248  "The type, eg 'pubkeyhash'"},
1249  {RPCResult::Type::STR, "address",
1250  " Bitcoin address if there is one"},
1251  }},
1252  }},
1254  "partial_signatures",
1255  /* optional */ true,
1256  "",
1257  {
1258  {RPCResult::Type::STR, "pubkey",
1259  "The public key and signature that corresponds "
1260  "to it."},
1261  }},
1262  {RPCResult::Type::STR, "sighash", /* optional */ true,
1263  "The sighash type to be used"},
1265  "redeem_script",
1266  /* optional */ true,
1267  "",
1268  {
1269  {RPCResult::Type::STR, "asm", "The asm"},
1270  {RPCResult::Type::STR_HEX, "hex", "The hex"},
1271  {RPCResult::Type::STR, "type",
1272  "The type, eg 'pubkeyhash'"},
1273  }},
1275  "bip32_derivs",
1276  /* optional */ true,
1277  "",
1278  {
1280  "pubkey",
1281  /* optional */ true,
1282  "The public key with the derivation path as "
1283  "the value.",
1284  {
1285  {RPCResult::Type::STR, "master_fingerprint",
1286  "The fingerprint of the master key"},
1287  {RPCResult::Type::STR, "path", "The path"},
1288  }},
1289  }},
1291  "final_scriptsig",
1292  /* optional */ true,
1293  "",
1294  {
1295  {RPCResult::Type::STR, "asm", "The asm"},
1296  {RPCResult::Type::STR, "hex", "The hex"},
1297  }},
1299  "unknown",
1300  "The unknown global fields",
1301  {
1302  {RPCResult::Type::STR_HEX, "key",
1303  "(key-value pair) An unknown key-value pair"},
1304  }},
1305  }},
1306  }},
1308  "outputs",
1309  "",
1310  {
1312  "",
1313  "",
1314  {
1316  "redeem_script",
1317  /* optional */ true,
1318  "",
1319  {
1320  {RPCResult::Type::STR, "asm", "The asm"},
1321  {RPCResult::Type::STR_HEX, "hex", "The hex"},
1322  {RPCResult::Type::STR, "type",
1323  "The type, eg 'pubkeyhash'"},
1324  }},
1326  "bip32_derivs",
1327  /* optional */ true,
1328  "",
1329  {
1331  "",
1332  "",
1333  {
1334  {RPCResult::Type::STR, "pubkey",
1335  "The public key this path corresponds to"},
1336  {RPCResult::Type::STR, "master_fingerprint",
1337  "The fingerprint of the master key"},
1338  {RPCResult::Type::STR, "path", "The path"},
1339  }},
1340  }},
1342  "unknown",
1343  "The unknown global fields",
1344  {
1345  {RPCResult::Type::STR_HEX, "key",
1346  "(key-value pair) An unknown key-value pair"},
1347  }},
1348  }},
1349  }},
1350  {RPCResult::Type::STR_AMOUNT, "fee", /* optional */ true,
1351  "The transaction fee paid if all UTXOs slots in the PSBT have "
1352  "been filled."},
1353  }},
1354  RPCExamples{HelpExampleCli("decodepsbt", "\"psbt\"")},
1355  [&](const RPCHelpMan &self, const Config &config,
1356  const JSONRPCRequest &request) -> UniValue {
1357  RPCTypeCheck(request.params, {UniValue::VSTR});
1358 
1359  // Unserialize the transactions
1361  std::string error;
1362  if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
1364  strprintf("TX decode failed %s", error));
1365  }
1366 
1367  UniValue result(UniValue::VOBJ);
1368 
1369  // Add the decoded tx
1370  UniValue tx_univ(UniValue::VOBJ);
1371  TxToUniv(CTransaction(*psbtx.tx), uint256(), tx_univ, false);
1372  result.pushKV("tx", tx_univ);
1373 
1374  // Unknown data
1375  if (psbtx.unknown.size() > 0) {
1376  UniValue unknowns(UniValue::VOBJ);
1377  for (auto entry : psbtx.unknown) {
1378  unknowns.pushKV(HexStr(entry.first), HexStr(entry.second));
1379  }
1380  result.pushKV("unknown", unknowns);
1381  }
1382 
1383  // inputs
1384  Amount total_in = Amount::zero();
1385  bool have_all_utxos = true;
1386  UniValue inputs(UniValue::VARR);
1387  for (size_t i = 0; i < psbtx.inputs.size(); ++i) {
1388  const PSBTInput &input = psbtx.inputs[i];
1390  // UTXOs
1391  if (!input.utxo.IsNull()) {
1392  const CTxOut &txout = input.utxo;
1393 
1394  UniValue out(UniValue::VOBJ);
1395 
1396  out.pushKV("amount", txout.nValue);
1397  if (MoneyRange(txout.nValue) &&
1398  MoneyRange(total_in + txout.nValue)) {
1399  total_in += txout.nValue;
1400  } else {
1401  // Hack to just not show fee later
1402  have_all_utxos = false;
1403  }
1404 
1406  ScriptToUniv(txout.scriptPubKey, o, true);
1407  out.pushKV("scriptPubKey", o);
1408  in.pushKV("utxo", out);
1409  } else {
1410  have_all_utxos = false;
1411  }
1412 
1413  // Partial sigs
1414  if (!input.partial_sigs.empty()) {
1415  UniValue partial_sigs(UniValue::VOBJ);
1416  for (const auto &sig : input.partial_sigs) {
1417  partial_sigs.pushKV(HexStr(sig.second.first),
1418  HexStr(sig.second.second));
1419  }
1420  in.pushKV("partial_signatures", partial_sigs);
1421  }
1422 
1423  // Sighash
1424  uint8_t sighashbyte =
1425  input.sighash_type.getRawSigHashType() & 0xff;
1426  if (sighashbyte > 0) {
1427  in.pushKV("sighash", SighashToStr(sighashbyte));
1428  }
1429 
1430  // Redeem script
1431  if (!input.redeem_script.empty()) {
1433  ScriptToUniv(input.redeem_script, r, false);
1434  in.pushKV("redeem_script", r);
1435  }
1436 
1437  // keypaths
1438  if (!input.hd_keypaths.empty()) {
1439  UniValue keypaths(UniValue::VARR);
1440  for (auto entry : input.hd_keypaths) {
1441  UniValue keypath(UniValue::VOBJ);
1442  keypath.pushKV("pubkey", HexStr(entry.first));
1443 
1444  keypath.pushKV(
1445  "master_fingerprint",
1446  strprintf("%08x",
1447  ReadBE32(entry.second.fingerprint)));
1448  keypath.pushKV("path",
1449  WriteHDKeypath(entry.second.path));
1450  keypaths.push_back(keypath);
1451  }
1452  in.pushKV("bip32_derivs", keypaths);
1453  }
1454 
1455  // Final scriptSig
1456  if (!input.final_script_sig.empty()) {
1457  UniValue scriptsig(UniValue::VOBJ);
1458  scriptsig.pushKV(
1459  "asm", ScriptToAsmStr(input.final_script_sig, true));
1460  scriptsig.pushKV("hex", HexStr(input.final_script_sig));
1461  in.pushKV("final_scriptSig", scriptsig);
1462  }
1463 
1464  // Unknown data
1465  if (input.unknown.size() > 0) {
1466  UniValue unknowns(UniValue::VOBJ);
1467  for (auto entry : input.unknown) {
1468  unknowns.pushKV(HexStr(entry.first),
1469  HexStr(entry.second));
1470  }
1471  in.pushKV("unknown", unknowns);
1472  }
1473 
1474  inputs.push_back(in);
1475  }
1476  result.pushKV("inputs", inputs);
1477 
1478  // outputs
1479  Amount output_value = Amount::zero();
1480  UniValue outputs(UniValue::VARR);
1481  for (size_t i = 0; i < psbtx.outputs.size(); ++i) {
1482  const PSBTOutput &output = psbtx.outputs[i];
1483  UniValue out(UniValue::VOBJ);
1484  // Redeem script
1485  if (!output.redeem_script.empty()) {
1487  ScriptToUniv(output.redeem_script, r, false);
1488  out.pushKV("redeem_script", r);
1489  }
1490 
1491  // keypaths
1492  if (!output.hd_keypaths.empty()) {
1493  UniValue keypaths(UniValue::VARR);
1494  for (auto entry : output.hd_keypaths) {
1495  UniValue keypath(UniValue::VOBJ);
1496  keypath.pushKV("pubkey", HexStr(entry.first));
1497  keypath.pushKV(
1498  "master_fingerprint",
1499  strprintf("%08x",
1500  ReadBE32(entry.second.fingerprint)));
1501  keypath.pushKV("path",
1502  WriteHDKeypath(entry.second.path));
1503  keypaths.push_back(keypath);
1504  }
1505  out.pushKV("bip32_derivs", keypaths);
1506  }
1507 
1508  // Unknown data
1509  if (output.unknown.size() > 0) {
1510  UniValue unknowns(UniValue::VOBJ);
1511  for (auto entry : output.unknown) {
1512  unknowns.pushKV(HexStr(entry.first),
1513  HexStr(entry.second));
1514  }
1515  out.pushKV("unknown", unknowns);
1516  }
1517 
1518  outputs.push_back(out);
1519 
1520  // Fee calculation
1521  if (MoneyRange(psbtx.tx->vout[i].nValue) &&
1522  MoneyRange(output_value + psbtx.tx->vout[i].nValue)) {
1523  output_value += psbtx.tx->vout[i].nValue;
1524  } else {
1525  // Hack to just not show fee later
1526  have_all_utxos = false;
1527  }
1528  }
1529  result.pushKV("outputs", outputs);
1530  if (have_all_utxos) {
1531  result.pushKV("fee", total_in - output_value);
1532  }
1533 
1534  return result;
1535  },
1536  };
1537 }
1538 
1540  return RPCHelpMan{
1541  "combinepsbt",
1542  "Combine multiple partially signed Bitcoin transactions into one "
1543  "transaction.\n"
1544  "Implements the Combiner role.\n",
1545  {
1546  {
1547  "txs",
1550  "The base64 strings of partially signed transactions",
1551  {
1553  "A base64 string of a PSBT"},
1554  },
1555  },
1556  },
1558  "The base64-encoded partially signed transaction"},
1560  "combinepsbt", R"('["mybase64_1", "mybase64_2", "mybase64_3"]')")},
1561  [&](const RPCHelpMan &self, const Config &config,
1562  const JSONRPCRequest &request) -> UniValue {
1563  RPCTypeCheck(request.params, {UniValue::VARR}, true);
1564 
1565  // Unserialize the transactions
1566  std::vector<PartiallySignedTransaction> psbtxs;
1567  UniValue txs = request.params[0].get_array();
1568  if (txs.empty()) {
1570  "Parameter 'txs' cannot be empty");
1571  }
1572  for (size_t i = 0; i < txs.size(); ++i) {
1574  std::string error;
1575  if (!DecodeBase64PSBT(psbtx, txs[i].get_str(), error)) {
1577  strprintf("TX decode failed %s", error));
1578  }
1579  psbtxs.push_back(psbtx);
1580  }
1581 
1582  PartiallySignedTransaction merged_psbt;
1583  const TransactionError error = CombinePSBTs(merged_psbt, psbtxs);
1584  if (error != TransactionError::OK) {
1586  }
1587 
1589  ssTx << merged_psbt;
1590  return EncodeBase64(MakeUCharSpan(ssTx));
1591  },
1592  };
1593 }
1594 
1596  return RPCHelpMan{
1597  "finalizepsbt",
1598  "Finalize the inputs of a PSBT. If the transaction is fully signed, it "
1599  "will produce a\n"
1600  "network serialized transaction which can be broadcast with "
1601  "sendrawtransaction. Otherwise a PSBT will be\n"
1602  "created which has the final_scriptSigfields filled for inputs that "
1603  "are complete.\n"
1604  "Implements the Finalizer and Extractor roles.\n",
1605  {
1607  "A base64 string of a PSBT"},
1608  {"extract", RPCArg::Type::BOOL, /* default */ "true",
1609  "If true and the transaction is complete,\n"
1610  " extract and return the complete "
1611  "transaction in normal network serialization instead of the "
1612  "PSBT."},
1613  },
1615  "",
1616  "",
1617  {
1618  {RPCResult::Type::STR, "psbt",
1619  "The base64-encoded partially signed transaction if not "
1620  "extracted"},
1621  {RPCResult::Type::STR_HEX, "hex",
1622  "The hex-encoded network transaction if extracted"},
1623  {RPCResult::Type::BOOL, "complete",
1624  "If the transaction has a complete set of signatures"},
1625  }},
1626  RPCExamples{HelpExampleCli("finalizepsbt", "\"psbt\"")},
1627  [&](const RPCHelpMan &self, const Config &config,
1628  const JSONRPCRequest &request) -> UniValue {
1629  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL},
1630  true);
1631 
1632  // Unserialize the transactions
1634  std::string error;
1635  if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
1637  strprintf("TX decode failed %s", error));
1638  }
1639 
1640  bool extract =
1641  request.params[1].isNull() ||
1642  (!request.params[1].isNull() && request.params[1].get_bool());
1643 
1644  CMutableTransaction mtx;
1645  bool complete = FinalizeAndExtractPSBT(psbtx, mtx);
1646 
1647  UniValue result(UniValue::VOBJ);
1649  std::string result_str;
1650 
1651  if (complete && extract) {
1652  ssTx << mtx;
1653  result_str = HexStr(ssTx);
1654  result.pushKV("hex", result_str);
1655  } else {
1656  ssTx << psbtx;
1657  result_str = EncodeBase64(ssTx.str());
1658  result.pushKV("psbt", result_str);
1659  }
1660  result.pushKV("complete", complete);
1661 
1662  return result;
1663  },
1664  };
1665 }
1666 
1668  return RPCHelpMan{
1669  "createpsbt",
1670  "Creates a transaction in the Partially Signed Transaction format.\n"
1671  "Implements the Creator role.\n",
1672  {
1673  {
1674  "inputs",
1677  "The json objects",
1678  {
1679  {
1680  "",
1683  "",
1684  {
1685  {"txid", RPCArg::Type::STR_HEX,
1686  RPCArg::Optional::NO, "The transaction id"},
1688  "The output number"},
1689  {"sequence", RPCArg::Type::NUM, /* default */
1690  "depends on the value of the 'locktime' argument",
1691  "The sequence number"},
1692  },
1693  },
1694  },
1695  },
1696  {
1697  "outputs",
1700  "The outputs (key-value pairs), where none of "
1701  "the keys are duplicated.\n"
1702  "That is, each address can only appear once and there can only "
1703  "be one 'data' object.\n"
1704  "For compatibility reasons, a dictionary, which holds the "
1705  "key-value pairs directly, is also\n"
1706  " accepted as second parameter.",
1707  {
1708  {
1709  "",
1712  "",
1713  {
1714  {"address", RPCArg::Type::AMOUNT,
1716  "A key-value pair. The key (string) is the "
1717  "bitcoin address, the value (float or string) is "
1718  "the amount in " +
1719  Currency::get().ticker},
1720  },
1721  },
1722  {
1723  "",
1726  "",
1727  {
1728  {"data", RPCArg::Type::STR_HEX,
1730  "A key-value pair. The key must be \"data\", the "
1731  "value is hex-encoded data"},
1732  },
1733  },
1734  },
1735  },
1736  {"locktime", RPCArg::Type::NUM, /* default */ "0",
1737  "Raw locktime. Non-0 value also locktime-activates inputs"},
1738  },
1740  "The resulting raw transaction (base64-encoded string)"},
1742  "createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
1743  "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")},
1744  [&](const RPCHelpMan &self, const Config &config,
1745  const JSONRPCRequest &request) -> UniValue {
1746  RPCTypeCheck(request.params,
1747  {
1748  UniValue::VARR,
1749  UniValueType(), // ARR or OBJ, checked later
1750  UniValue::VNUM,
1751  },
1752  true);
1753 
1754  CMutableTransaction rawTx =
1755  ConstructTransaction(config.GetChainParams(), request.params[0],
1756  request.params[1], request.params[2]);
1757 
1758  // Make a blank psbt
1760  psbtx.tx = rawTx;
1761  for (size_t i = 0; i < rawTx.vin.size(); ++i) {
1762  psbtx.inputs.push_back(PSBTInput());
1763  }
1764  for (size_t i = 0; i < rawTx.vout.size(); ++i) {
1765  psbtx.outputs.push_back(PSBTOutput());
1766  }
1767 
1768  // Serialize the PSBT
1770  ssTx << psbtx;
1771 
1772  return EncodeBase64(MakeUCharSpan(ssTx));
1773  },
1774  };
1775 }
1776 
1778  return RPCHelpMan{
1779  "converttopsbt",
1780  "Converts a network serialized transaction to a PSBT. "
1781  "This should be used only with createrawtransaction and "
1782  "fundrawtransaction\n"
1783  "createpsbt and walletcreatefundedpsbt should be used for new "
1784  "applications.\n",
1785  {
1787  "The hex string of a raw transaction"},
1788  {"permitsigdata", RPCArg::Type::BOOL, /* default */ "false",
1789  "If true, any signatures in the input will be discarded and "
1790  "conversion.\n"
1791  " will continue. If false, RPC will "
1792  "fail if any signatures are present."},
1793  },
1795  "The resulting raw transaction (base64-encoded string)"},
1796  RPCExamples{
1797  "\nCreate a transaction\n" +
1798  HelpExampleCli("createrawtransaction",
1799  "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
1800  "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
1801  "\nConvert the transaction to a PSBT\n" +
1802  HelpExampleCli("converttopsbt", "\"rawtransaction\"")},
1803  [&](const RPCHelpMan &self, const Config &config,
1804  const JSONRPCRequest &request) -> UniValue {
1805  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL},
1806  true);
1807 
1808  // parse hex string from parameter
1810  bool permitsigdata = request.params[1].isNull()
1811  ? false
1812  : request.params[1].get_bool();
1813  if (!DecodeHexTx(tx, request.params[0].get_str())) {
1815  "TX decode failed");
1816  }
1817 
1818  // Remove all scriptSigs from inputs
1819  for (CTxIn &input : tx.vin) {
1820  if (!input.scriptSig.empty() && !permitsigdata) {
1822  "Inputs must not have scriptSigs");
1823  }
1824  input.scriptSig.clear();
1825  }
1826 
1827  // Make a blank psbt
1829  psbtx.tx = tx;
1830  for (size_t i = 0; i < tx.vin.size(); ++i) {
1831  psbtx.inputs.push_back(PSBTInput());
1832  }
1833  for (size_t i = 0; i < tx.vout.size(); ++i) {
1834  psbtx.outputs.push_back(PSBTOutput());
1835  }
1836 
1837  // Serialize the PSBT
1839  ssTx << psbtx;
1840 
1841  return EncodeBase64(MakeUCharSpan(ssTx));
1842  },
1843  };
1844 }
1845 
1847  return RPCHelpMan{
1848  "utxoupdatepsbt",
1849  "Updates all inputs and outputs in a PSBT with data from output "
1850  "descriptors, the UTXO set or the mempool.\n",
1851  {
1853  "A base64 string of a PSBT"},
1854  {"descriptors",
1857  "An array of either strings or objects",
1858  {
1860  "An output descriptor"},
1861  {"",
1864  "An object with an output descriptor and extra information",
1865  {
1867  "An output descriptor"},
1868  {"range", RPCArg::Type::RANGE, "1000",
1869  "Up to what index HD chains should be explored (either "
1870  "end or [begin,end])"},
1871  }},
1872  }},
1873  },
1875  "The base64-encoded partially signed transaction with inputs "
1876  "updated"},
1877  RPCExamples{HelpExampleCli("utxoupdatepsbt", "\"psbt\"")},
1878  [&](const RPCHelpMan &self, const Config &config,
1879  const JSONRPCRequest &request) -> UniValue {
1880  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR},
1881  true);
1882 
1883  // Unserialize the transactions
1885  std::string error;
1886  if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
1888  strprintf("TX decode failed %s", error));
1889  }
1890 
1891  // Parse descriptors, if any.
1892  FlatSigningProvider provider;
1893  if (!request.params[1].isNull()) {
1894  auto descs = request.params[1].get_array();
1895  for (size_t i = 0; i < descs.size(); ++i) {
1896  EvalDescriptorStringOrObject(descs[i], provider);
1897  }
1898  }
1899  // We don't actually need private keys further on; hide them as a
1900  // precaution.
1901  HidingSigningProvider public_provider(&provider, /* nosign */ true,
1902  /* nobip32derivs */ false);
1903 
1904  // Fetch previous transactions (inputs):
1905  CCoinsView viewDummy;
1906  CCoinsViewCache view(&viewDummy);
1907  {
1908  const CTxMemPool &mempool = EnsureMemPool(request.context);
1909  LOCK2(cs_main, mempool.cs);
1910  CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
1911  CCoinsViewMemPool viewMempool(&viewChain, mempool);
1912  // temporarily switch cache backend to db+mempool view
1913  view.SetBackend(viewMempool);
1914 
1915  for (const CTxIn &txin : psbtx.tx->vin) {
1916  // Load entries from viewChain into view; can fail.
1917  view.AccessCoin(txin.prevout);
1918  }
1919 
1920  // switch back to avoid locking mempool for too long
1921  view.SetBackend(viewDummy);
1922  }
1923 
1924  // Fill the inputs
1925  for (size_t i = 0; i < psbtx.tx->vin.size(); ++i) {
1926  PSBTInput &input = psbtx.inputs.at(i);
1927 
1928  if (!input.utxo.IsNull()) {
1929  continue;
1930  }
1931 
1932  // Update script/keypath information using descriptor data.
1933  // Note that SignPSBTInput does a lot more than just
1934  // constructing ECDSA signatures we don't actually care about
1935  // those here, in fact.
1936  SignPSBTInput(public_provider, psbtx, i,
1937  /* sighash_type */ SigHashType().withForkId());
1938  }
1939 
1940  // Update script/keypath information using descriptor data.
1941  for (unsigned int i = 0; i < psbtx.tx->vout.size(); ++i) {
1942  UpdatePSBTOutput(public_provider, psbtx, i);
1943  }
1944 
1946  ssTx << psbtx;
1947  return EncodeBase64(MakeUCharSpan(ssTx));
1948  },
1949  };
1950 }
1951 
1953  return RPCHelpMan{
1954  "joinpsbts",
1955  "Joins multiple distinct PSBTs with different inputs and outputs "
1956  "into one PSBT with inputs and outputs from all of the PSBTs\n"
1957  "No input in any of the PSBTs can be in more than one of the PSBTs.\n",
1958  {{"txs",
1961  "The base64 strings of partially signed transactions",
1963  "A base64 string of a PSBT"}}}},
1965  "The base64-encoded partially signed transaction"},
1966  RPCExamples{HelpExampleCli("joinpsbts", "\"psbt\"")},
1967  [&](const RPCHelpMan &self, const Config &config,
1968  const JSONRPCRequest &request) -> UniValue {
1969  RPCTypeCheck(request.params, {UniValue::VARR}, true);
1970 
1971  // Unserialize the transactions
1972  std::vector<PartiallySignedTransaction> psbtxs;
1973  UniValue txs = request.params[0].get_array();
1974 
1975  if (txs.size() <= 1) {
1976  throw JSONRPCError(
1978  "At least two PSBTs are required to join PSBTs.");
1979  }
1980 
1981  uint32_t best_version = 1;
1982  uint32_t best_locktime = 0xffffffff;
1983  for (size_t i = 0; i < txs.size(); ++i) {
1985  std::string error;
1986  if (!DecodeBase64PSBT(psbtx, txs[i].get_str(), error)) {
1988  strprintf("TX decode failed %s", error));
1989  }
1990  psbtxs.push_back(psbtx);
1991  // Choose the highest version number
1992  if (static_cast<uint32_t>(psbtx.tx->nVersion) > best_version) {
1993  best_version = static_cast<uint32_t>(psbtx.tx->nVersion);
1994  }
1995  // Choose the lowest lock time
1996  if (psbtx.tx->nLockTime < best_locktime) {
1997  best_locktime = psbtx.tx->nLockTime;
1998  }
1999  }
2000 
2001  // Create a blank psbt where everything will be added
2002  PartiallySignedTransaction merged_psbt;
2003  merged_psbt.tx = CMutableTransaction();
2004  merged_psbt.tx->nVersion = static_cast<int32_t>(best_version);
2005  merged_psbt.tx->nLockTime = best_locktime;
2006 
2007  // Merge
2008  for (auto &psbt : psbtxs) {
2009  for (size_t i = 0; i < psbt.tx->vin.size(); ++i) {
2010  if (!merged_psbt.AddInput(psbt.tx->vin[i],
2011  psbt.inputs[i])) {
2012  throw JSONRPCError(
2014  strprintf("Input %s:%d exists in multiple PSBTs",
2015  psbt.tx->vin[i]
2016  .prevout.GetTxId()
2017  .ToString()
2018  .c_str(),
2019  psbt.tx->vin[i].prevout.GetN()));
2020  }
2021  }
2022  for (size_t i = 0; i < psbt.tx->vout.size(); ++i) {
2023  merged_psbt.AddOutput(psbt.tx->vout[i], psbt.outputs[i]);
2024  }
2025  merged_psbt.unknown.insert(psbt.unknown.begin(),
2026  psbt.unknown.end());
2027  }
2028 
2029  // Generate list of shuffled indices for shuffling inputs and
2030  // outputs of the merged PSBT
2031  std::vector<int> input_indices(merged_psbt.inputs.size());
2032  std::iota(input_indices.begin(), input_indices.end(), 0);
2033  std::vector<int> output_indices(merged_psbt.outputs.size());
2034  std::iota(output_indices.begin(), output_indices.end(), 0);
2035 
2036  // Shuffle input and output indices lists
2037  Shuffle(input_indices.begin(), input_indices.end(),
2038  FastRandomContext());
2039  Shuffle(output_indices.begin(), output_indices.end(),
2040  FastRandomContext());
2041 
2042  PartiallySignedTransaction shuffled_psbt;
2043  shuffled_psbt.tx = CMutableTransaction();
2044  shuffled_psbt.tx->nVersion = merged_psbt.tx->nVersion;
2045  shuffled_psbt.tx->nLockTime = merged_psbt.tx->nLockTime;
2046  for (int i : input_indices) {
2047  shuffled_psbt.AddInput(merged_psbt.tx->vin[i],
2048  merged_psbt.inputs[i]);
2049  }
2050  for (int i : output_indices) {
2051  shuffled_psbt.AddOutput(merged_psbt.tx->vout[i],
2052  merged_psbt.outputs[i]);
2053  }
2054  shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(),
2055  merged_psbt.unknown.end());
2056 
2058  ssTx << shuffled_psbt;
2059  return EncodeBase64(MakeUCharSpan(ssTx));
2060  },
2061  };
2062 }
2063 
2065  return RPCHelpMan{
2066  "analyzepsbt",
2067  "Analyzes and provides information about the current status of a "
2068  "PSBT and its inputs\n",
2070  "A base64 string of a PSBT"}},
2071  RPCResult{
2073  "",
2074  "",
2075  {
2077  "inputs",
2078  "",
2079  {
2081  "",
2082  "",
2083  {
2084  {RPCResult::Type::BOOL, "has_utxo",
2085  "Whether a UTXO is provided"},
2086  {RPCResult::Type::BOOL, "is_final",
2087  "Whether the input is finalized"},
2089  "missing",
2090  /* optional */ true,
2091  "Things that are missing that are required to "
2092  "complete this input",
2093  {
2095  "pubkeys",
2096  /* optional */ true,
2097  "",
2098  {
2099  {RPCResult::Type::STR_HEX, "keyid",
2100  "Public key ID, hash160 of the public "
2101  "key, of a public key whose BIP 32 "
2102  "derivation path is missing"},
2103  }},
2105  "signatures",
2106  /* optional */ true,
2107  "",
2108  {
2109  {RPCResult::Type::STR_HEX, "keyid",
2110  "Public key ID, hash160 of the public "
2111  "key, of a public key whose signature is "
2112  "missing"},
2113  }},
2114  {RPCResult::Type::STR_HEX, "redeemscript",
2115  /* optional */ true,
2116  "Hash160 of the redeemScript that is missing"},
2117  }},
2118  {RPCResult::Type::STR, "next", /* optional */ true,
2119  "Role of the next person that this input needs to "
2120  "go to"},
2121  }},
2122  }},
2123  {RPCResult::Type::NUM, "estimated_vsize", /* optional */ true,
2124  "Estimated vsize of the final signed transaction"},
2125  {RPCResult::Type::STR_AMOUNT, "estimated_feerate",
2126  /* optional */ true,
2127  "Estimated feerate of the final signed transaction in " +
2128  Currency::get().ticker +
2129  "/kB. Shown only if all UTXO slots in the PSBT have been "
2130  "filled"},
2131  {RPCResult::Type::STR_AMOUNT, "fee", /* optional */ true,
2132  "The transaction fee paid. Shown only if all UTXO slots in "
2133  "the PSBT have been filled"},
2134  {RPCResult::Type::STR, "next",
2135  "Role of the next person that this psbt needs to go to"},
2136  {RPCResult::Type::STR, "error", /* optional */ true,
2137  "Error message (if there is one)"},
2138  }},
2139  RPCExamples{HelpExampleCli("analyzepsbt", "\"psbt\"")},
2140  [&](const RPCHelpMan &self, const Config &config,
2141  const JSONRPCRequest &request) -> UniValue {
2142  RPCTypeCheck(request.params, {UniValue::VSTR});
2143 
2144  // Unserialize the transaction
2146  std::string error;
2147  if (!DecodeBase64PSBT(psbtx, request.params[0].get_str(), error)) {
2149  strprintf("TX decode failed %s", error));
2150  }
2151 
2152  PSBTAnalysis psbta = AnalyzePSBT(psbtx);
2153 
2154  UniValue result(UniValue::VOBJ);
2155  UniValue inputs_result(UniValue::VARR);
2156  for (const auto &input : psbta.inputs) {
2157  UniValue input_univ(UniValue::VOBJ);
2158  UniValue missing(UniValue::VOBJ);
2159 
2160  input_univ.pushKV("has_utxo", input.has_utxo);
2161  input_univ.pushKV("is_final", input.is_final);
2162  input_univ.pushKV("next", PSBTRoleName(input.next));
2163 
2164  if (!input.missing_pubkeys.empty()) {
2165  UniValue missing_pubkeys_univ(UniValue::VARR);
2166  for (const CKeyID &pubkey : input.missing_pubkeys) {
2167  missing_pubkeys_univ.push_back(HexStr(pubkey));
2168  }
2169  missing.pushKV("pubkeys", missing_pubkeys_univ);
2170  }
2171  if (!input.missing_redeem_script.IsNull()) {
2172  missing.pushKV("redeemscript",
2173  HexStr(input.missing_redeem_script));
2174  }
2175  if (!input.missing_sigs.empty()) {
2176  UniValue missing_sigs_univ(UniValue::VARR);
2177  for (const CKeyID &pubkey : input.missing_sigs) {
2178  missing_sigs_univ.push_back(HexStr(pubkey));
2179  }
2180  missing.pushKV("signatures", missing_sigs_univ);
2181  }
2182  if (!missing.getKeys().empty()) {
2183  input_univ.pushKV("missing", missing);
2184  }
2185  inputs_result.push_back(input_univ);
2186  }
2187  if (!inputs_result.empty()) {
2188  result.pushKV("inputs", inputs_result);
2189  }
2190  if (psbta.estimated_vsize != std::nullopt) {
2191  result.pushKV("estimated_vsize", (int)*psbta.estimated_vsize);
2192  }
2193  if (psbta.estimated_feerate != std::nullopt) {
2194  result.pushKV("estimated_feerate",
2195  psbta.estimated_feerate->GetFeePerK());
2196  }
2197  if (psbta.fee != std::nullopt) {
2198  result.pushKV("fee", *psbta.fee);
2199  }
2200  result.pushKV("next", PSBTRoleName(psbta.next));
2201  if (!psbta.error.empty()) {
2202  result.pushKV("error", psbta.error);
2203  }
2204 
2205  return result;
2206  },
2207  };
2208 }
2209 
2211  // clang-format off
2212  static const CRPCCommand commands[] = {
2213  // category actor (function)
2214  // ------------------ ----------------------
2215  { "rawtransactions", getrawtransaction, },
2216  { "rawtransactions", createrawtransaction, },
2217  { "rawtransactions", decoderawtransaction, },
2218  { "rawtransactions", decodescript, },
2219  { "rawtransactions", sendrawtransaction, },
2220  { "rawtransactions", combinerawtransaction, },
2221  { "rawtransactions", signrawtransactionwithkey, },
2222  { "rawtransactions", testmempoolaccept, },
2223  { "rawtransactions", decodepsbt, },
2224  { "rawtransactions", combinepsbt, },
2225  { "rawtransactions", finalizepsbt, },
2226  { "rawtransactions", createpsbt, },
2227  { "rawtransactions", converttopsbt, },
2228  { "rawtransactions", utxoupdatepsbt, },
2229  { "rawtransactions", joinpsbts, },
2230  { "rawtransactions", analyzepsbt, },
2231  { "blockchain", gettxoutproof, },
2232  { "blockchain", verifytxoutproof, },
2233  };
2234  // clang-format on
2235  for (const auto &c : commands) {
2236  t.appendCommand(c.name, &c);
2237  }
2238 }
CBlockIndex::GetBlockTime
int64_t GetBlockTime() const
Definition: blockindex.h:160
WriteHDKeypath
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
Definition: bip32.cpp:66
CCoinsViewBacked::SetBackend
void SetBackend(CCoinsView &viewIn)
Definition: coins.cpp:45
CTxIn
An input of a transaction.
Definition: transaction.h:61
RPC_MISC_ERROR
@ RPC_MISC_ERROR
General application defined errors std::exception thrown in command handling.
Definition: protocol.h:38
combinepsbt
static RPCHelpMan combinepsbt()
Definition: rawtransaction.cpp:1539
ScriptToUniv
void ScriptToUniv(const CScript &script, UniValue &out, bool include_address)
Definition: core_write.cpp:171
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:244
policy.h
SighashToStr
std::string SighashToStr(uint8_t sighash_type)
Definition: core_write.cpp:85
merkleblock.h
MoneyRange
bool MoneyRange(const Amount nValue)
Definition: amount.h:176
RPCResult::Type::ELISION
@ ELISION
Special type to denote elision (...)
bip32.h
CombinePSBTs
TransactionError CombinePSBTs(PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial sign...
Definition: psbt.cpp:263
CTxOut::nValue
Amount nValue
Definition: transaction.h:132
HelpExampleCli
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:157
finalizepsbt
static RPCHelpMan finalizepsbt()
Definition: rawtransaction.cpp:1595
PSBTInput::partial_sigs
std::map< CKeyID, SigPair > partial_sigs
Definition: psbt.h:50
UniValue::VOBJ
@ VOBJ
Definition: univalue.h:27
MakeTransactionRef
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:320
g_txindex
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:20
createrawtransaction
static RPCHelpMan createrawtransaction()
Definition: rawtransaction.cpp:467
RPC_INTERNAL_ERROR
@ RPC_INTERNAL_ERROR
Definition: protocol.h:33
CBlockHeader::hashMerkleRoot
uint256 hashMerkleRoot
Definition: block.h:27
ConstructTransaction
CMutableTransaction ConstructTransaction(const CChainParams &params, const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime)
Create a transaction from univalue parameters.
Definition: rawtransaction_util.cpp:21
ParseHexV
std::vector< uint8_t > ParseHexV(const UniValue &v, std::string strName)
Definition: util.cpp:120
ChainActive
CChain & ChainActive()
Please prefer the identical ChainstateManager::ActiveChain.
Definition: validation.cpp:86
GetAllOutputTypes
std::string GetAllOutputTypes()
Definition: util.cpp:286
EnsureNodeContext
NodeContext & EnsureNodeContext(const util::Ref &context)
Definition: blockchain.cpp:56
psbt.h
key_io.h
CBlockIndex::nTx
unsigned int nTx
Number of transactions in this block.
Definition: blockindex.h:54
NodeContext::mempool
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:38
SignatureData::MergeSignatureData
void MergeSignatureData(SignatureData sigdata)
Definition: sign.cpp:334
RPC_VERIFY_ERROR
@ RPC_VERIFY_ERROR
General error during transaction or block submission.
Definition: protocol.h:52
signrawtransactionwithkey
static RPCHelpMan signrawtransactionwithkey()
Definition: rawtransaction.cpp:832
moneystr.h
RPCHelpMan
Definition: util.h:334
MakeUCharSpan
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(MakeSpan(std::forward< V >(v))))
Like MakeSpan, but for (const) uint8_t member types only.
Definition: span.h:280
transaction.h
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition: signingprovider.h:76
string.h
PSBTAnalysis
Holds the results of AnalyzePSBT (miscellaneous information about a PSBT)
Definition: psbt.h:34
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:495
CMerkleBlock
Used to create a Merkle proof (usually from a subset of transactions), which consists of a block head...
Definition: merkleblock.h:147
RPC_INVALID_PARAMETER
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
Definition: protocol.h:46
uint256.h
DEFAULT_MAX_RAW_TX_FEE_RATE
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
Definition: transaction.h:24
ParseHashV
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
Definition: util.cpp:99
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:36
RPCArg::Optional::NO
@ NO
Required arg.
validationinterface.h
RPCArg::Type::STR
@ STR
validation.h
PartiallySignedTransaction::inputs
std::vector< PSBTInput > inputs
Definition: psbt.h:337
RPCArg::Type::ARR
@ ARR
PartiallySignedTransaction::AddInput
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
Definition: psbt.cpp:37
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:47
MutableTransactionSignatureCreator
A signature creator for transactions.
Definition: sign.h:38
verifytxoutproof
static RPCHelpMan verifytxoutproof()
Definition: rawtransaction.cpp:410
PSBTOutput::redeem_script
CScript redeem_script
Definition: psbt.h:235
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:59
RPCResult::Type::NUM
@ NUM
ChainstateActive
CChainState & ChainstateActive()
Please prefer the identical ChainstateManager::ActiveChainstate.
Definition: validation.cpp:80
CCoinsViewCache::AccessCoin
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Definition: coins.cpp:180
CBlockIndex::nStatus
BlockStatus nStatus
Verification status of this block. See enum BlockStatus.
Definition: blockindex.h:76
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
FinalizeAndExtractPSBT
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
Definition: psbt.cpp:246
chainparams.h
PSBTAnalysis::inputs
std::vector< PSBTInputAnalysis > inputs
More information about the individual inputs of the transaction.
Definition: psbt.h:42
DUMMY_SIGNING_PROVIDER
const SigningProvider & DUMMY_SIGNING_PROVIDER
Definition: signingprovider.cpp:11
CScript::clear
void clear()
Definition: script.h:553
context.h
core_io.h
UniValue::pushKV
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
CFeeRate
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
DecodeBase64PSBT
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:295
extract
#define extract(n)
Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits.
Definition: scalar_4x64_impl.h:235
UniValue
Definition: univalue.h:23
TxToJSON
static void TxToJSON(const CTransaction &tx, const BlockHash &hashBlock, UniValue &entry)
Definition: rawtransaction.cpp:48
FillableSigningProvider::AddKey
virtual bool AddKey(const CKey &key)
Definition: signingprovider.h:110
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
SignPSBTInput
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, SigHashType sighash, SignatureData *out_sigdata, bool use_dummy)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
Definition: psbt.cpp:185
PSBTAnalysis::next
PSBTRole next
Which of the BIP 174 roles needs to handle the transaction next.
Definition: psbt.h:44
Amount::zero
static constexpr Amount zero()
Definition: amount.h:42
txmempool.h
PSBTAnalysis::estimated_feerate
std::optional< CFeeRate > estimated_feerate
Estimated feerate (fee / weight) of the transaction.
Definition: psbt.h:38
ScriptPubKeyToUniv
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
Definition: core_write.cpp:186
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:165
txindex.h
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:175
transaction.h
RPCArg::Type::NUM
@ NUM
utxoupdatepsbt
RPCHelpMan utxoupdatepsbt()
Definition: rawtransaction.cpp:1846
TxValidationState
Definition: validation.h:137
signingprovider.h
FindCoins
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
Definition: coin.cpp:11
combinerawtransaction
static RPCHelpMan combinerawtransaction()
Definition: rawtransaction.cpp:728
ParsePrevouts
void ParsePrevouts(const UniValue &prevTxsUnival, FillableSigningProvider *keystore, std::map< COutPoint, Coin > &coins)
Parse a prevtxs UniValue array and get the map of coins from it.
Definition: rawtransaction_util.cpp:174
UniValue::get_str
const std::string & get_str() const
Definition: univalue_get.cpp:98
RPC_DESERIALIZATION_ERROR
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
Definition: protocol.h:50
strencodings.h
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:59
Config
Definition: config.h:17
CFeeRate::GetFeePerK
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
CTxOut::IsNull
bool IsNull() const
Definition: transaction.h:147
UniValue::isStr
bool isStr() const
Definition: univalue.h:93
TransactionError
TransactionError
Definition: error.h:22
sig
SchnorrSig sig
Definition: processor.cpp:322
blockdb.h
random.h
coin.h
GetTransaction
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const TxId &txid, const Consensus::Params &consensusParams, BlockHash &hashBlock)
Return transaction from the block at block_index.
Definition: validation.cpp:786
PSBTInput::unknown
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
Definition: psbt.h:51
PSBTInput::final_script_sig
CScript final_script_sig
Definition: psbt.h:48
RPCArg::Type::OBJ
@ OBJ
AnalyzePSBT
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
Provides helpful miscellaneous information about where a PSBT is in the signing workflow.
Definition: psbt.cpp:15
CTxMemPool::cs
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:577
SignatureData
Definition: sign.h:66
AssertLockNotHeld
#define AssertLockNotHeld(cs)
Definition: sync.h:92
RPCArg::Optional::OMITTED_NAMED_ARG
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
BlockStatus::hasData
bool hasData() const
Definition: blockstatus.h:54
PSBTInput::hd_keypaths
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:49
CTxOut
An output of a transaction.
Definition: transaction.h:130
RPCArg::Type::STR_HEX
@ STR_HEX
Special type that is a STR with only hex chars.
cs_main
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:103
RPCResult::Type::OBJ
@ OBJ
CRPCCommand
Definition: server.h:147
Coin
A UTXO entry.
Definition: coins.h:27
CTxOut::scriptPubKey
CScript scriptPubKey
Definition: transaction.h:133
testmempoolaccept
static RPCHelpMan testmempoolaccept()
Definition: rawtransaction.cpp:1044
decodescript
static RPCHelpMan decodescript()
Definition: rawtransaction.cpp:669
DecodeHexTx
NODISCARD bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
Definition: core_read.cpp:196
decoderawtransaction
static RPCHelpMan decoderawtransaction()
Definition: rawtransaction.cpp:575
univalue.h
CFeeRate::GetFee
Amount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
Definition: feerate.cpp:51
analyzepsbt
RPCHelpMan analyzepsbt()
Definition: rawtransaction.cpp:2064
Currency::get
static const Currency & get()
Definition: amount.cpp:19
RPCResult::Type::STR_HEX
@ STR_HEX
Special string with only hex chars.
joinpsbts
RPCHelpMan joinpsbts()
Definition: rawtransaction.cpp:1952
decodepsbt
static RPCHelpMan decodepsbt()
Definition: rawtransaction.cpp:1196
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:94
PSBTOutput::unknown
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
Definition: psbt.h:237
sign.h
PartiallySignedTransaction::tx
std::optional< CMutableTransaction > tx
Definition: psbt.h:336
base_blob::GetHex
std::string GetHex() const
Definition: uint256.cpp:16
standard.h
RPCExamples
Definition: util.h:326
SigHashType
Signature hash type wrapper class.
Definition: sighashtype.h:37
Shuffle
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
Definition: random.h:251
error.h
ReadBlockFromDisk
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &params)
Functions for disk access for blocks.
Definition: blockdb.cpp:33
UpdatePSBTOutput
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
Definition: psbt.cpp:163
PSBTOutput
A structure for PSBTs which contains per output information.
Definition: psbt.h:234
UniValue::getKeys
const std::vector< std::string > & getKeys() const
Definition: univalue_get.cpp:77
EnsureMemPool
CTxMemPool & EnsureMemPool(const util::Ref &context)
Definition: blockchain.cpp:63
RPCResult::Type::STR
@ STR
EvalDescriptorStringOrObject
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
Definition: util.cpp:928
DecodeSecret
CKey DecodeSecret(const std::string &str)
Definition: key_io.cpp:80
CChainParams::GenesisBlock
const CBlock & GenesisBlock() const
Definition: chainparams.h:64
uint256
256-bit opaque blob.
Definition: uint256.h:127
PSBTInput::sighash_type
SigHashType sighash_type
Definition: psbt.h:52
RPCResult::Type::NUM_TIME
@ NUM_TIME
Special numeric to denote unix epoch time.
RPCResult::Type::ARR
@ ARR
TxId
A TxId is the identifier of a transaction.
Definition: txid.h:14
getrawtransaction
static RPCHelpMan getrawtransaction()
Definition: rawtransaction.cpp:75
Amount
Definition: amount.h:19
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
HelpExampleRpc
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:162
PartiallySignedTransaction::AddOutput
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
Definition: psbt.cpp:49
RPCArg::Type::RANGE
@ RANGE
Special type that is a NUM or [NUM,NUM].
coins.h
SigHashType::getRawSigHashType
uint32_t getRawSigHashType() const
Definition: sighashtype.h:83
ValidationState::GetResult
Result GetResult() const
Definition: validation.h:121
JSONRPCTransactionError
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Definition: util.cpp:314
BlockHash
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
CRPCTable
RPC command dispatcher.
Definition: server.h:184
EncodeHexTx
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
Definition: core_write.cpp:165
RPC_INVALID_ADDRESS_OR_KEY
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
Definition: protocol.h:42
ProduceSignature
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:197
CBlock
Definition: block.h:55
AmountFromValue
Amount AmountFromValue(const UniValue &value)
Definition: util.cpp:81
Currency::ticker
std::string ticker
Definition: amount.h:160
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
TxToUniv
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, bool include_hex=true, int serialize_flags=0)
Definition: core_write.cpp:213
CRPCTable::appendCommand
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:322
base_blob::IsNull
bool IsNull() const
Definition: uint256.h:30
CBlock::vtx
std::vector< CTransactionRef > vtx
Definition: block.h:58
PSBTAnalysis::fee
std::optional< Amount > fee
Amount of fee being paid by the transaction.
Definition: psbt.h:40
PSBTInput
A structure for PSBTs which contain per-input information.
Definition: psbt.h:45
PartiallySignedTransaction::unknown
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
Definition: psbt.h:339
RPCResult::Type::BOOL
@ BOOL
CKey
An encapsulated secp256k1 private key.
Definition: key.h:28
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:231
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:281
RPCTypeCheck
void RPCTypeCheck(const UniValue &params, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: util.cpp:25
TxValidationResult::TX_MISSING_INPUTS
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
createpsbt
static RPCHelpMan createpsbt()
Definition: rawtransaction.cpp:1667
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:52
PartiallySignedTransaction
A version of CTransaction with the PSBT format.
Definition: psbt.h:335
LOCK
#define LOCK(cs)
Definition: sync.h:241
sendrawtransaction
static RPCHelpMan sendrawtransaction()
Definition: rawtransaction.cpp:972
TransactionError::OK
@ OK
No error.
FormatMoney
std::string FormatMoney(const Amount amt)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
RPCArg::Type::BOOL
@ BOOL
PSBTInput::utxo
CTxOut utxo
Definition: psbt.h:46
RPCSerializationFlags
int RPCSerializationFlags()
Retrieves any serialization flags requested in command line argument.
Definition: server.cpp:600
RPCArg::Optional::OMITTED
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
EncodeDestination
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
Definition: key_io.cpp:170
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:63
RegisterRawTransactionRPCCommands
void RegisterRawTransactionRPCCommands(CRPCTable &t)
Register raw transaction RPC commands.
Definition: rawtransaction.cpp:2210
CTxIn::scriptSig
CScript scriptSig
Definition: transaction.h:64
CCoinsViewMemPool
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:953
converttopsbt
static RPCHelpMan converttopsbt()
Definition: rawtransaction.cpp:1777
UniValue::push_back
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
network.h
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:508
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:319
PartiallySignedTransaction::outputs
std::vector< PSBTOutput > outputs
Definition: psbt.h:338
CChain::Contains
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:184
Coin::GetHeight
uint32_t GetHeight() const
Definition: coins.h:44
UniValue::empty
bool empty() const
Definition: univalue.h:78
LookupBlockIndex
CBlockIndex * LookupBlockIndex(const BlockHash &hash)
Definition: validation.cpp:150
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
prevector::empty
bool empty() const
Definition: prevector.h:388
config.h
RPCResult::Type::OBJ_DYN
@ OBJ_DYN
Special dictionary with keys that are not literals.
UniValue::size
size_t size() const
Definition: univalue.h:80
script.h
ValidationState::GetRejectReason
std::string GetRejectReason() const
Definition: validation.h:122
RPCArg::Type::AMOUNT
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
JSONRPCRequest
Definition: request.h:33
util.h
RPCResult
Definition: util.h:247
GetVirtualTransactionSize
int64_t GetVirtualTransactionSize(int64_t nSize, int64_t nSigOpCount, unsigned int bytes_per_sigop)
Compute the virtual transaction size (size, or more if sigops are too dense).
Definition: policy.cpp:162
UpdateInput
void UpdateInput(CTxIn &input, const SignatureData &data)
Definition: sign.cpp:330
blockchain.h
EncodeBase64
std::string EncodeBase64(Span< const uint8_t > input)
Definition: strencodings.cpp:137
find_value
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:234
PSBTInput::redeem_script
CScript redeem_script
Definition: psbt.h:47
PSBTAnalysis::estimated_vsize
std::optional< size_t > estimated_vsize
Estimated weight of the transaction.
Definition: psbt.h:36
SignTransaction
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
Definition: rawtransaction_util.cpp:262
BroadcastTransaction
TransactionError BroadcastTransaction(NodeContext &node, const Config &config, const CTransactionRef tx, std::string &err_string, const Amount max_tx_fee, bool relay, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
Definition: transaction.cpp:33
HidingSigningProvider
Definition: signingprovider.h:41
PSBTRoleName
std::string PSBTRoleName(const PSBTRole role)
Definition: psbt.cpp:278
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
Coin::IsSpent
bool IsSpent() const
Definition: coins.h:46
RPCResult::Type::STR_AMOUNT
@ STR_AMOUNT
Special string to represent a floating point amount.
UniValue::get_array
const UniValue & get_array() const
Definition: univalue_get.cpp:142
AcceptToMemoryPool
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, TxValidationState &state, const CTransactionRef &tx, bool bypass_limits, bool test_accept, Amount *fee_out)
(try to) add transaction to memory pool
Definition: validation.cpp:779
UniValue::VARR
@ VARR
Definition: univalue.h:27
NodeContext
NodeContext struct containing references to chain state and connection state.
Definition: context.h:36
server.h
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
CDataStream::str
std::string str() const
Definition: streams.h:271
HexStr
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: strencodings.cpp:656
DataFromTransaction
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
Definition: sign.cpp:274
Coin::GetTxOut
CTxOut & GetTxOut()
Definition: coins.h:48
AccessByTxid
const Coin & AccessByTxid(const CCoinsViewCache &view, const TxId &txid)
Utility function to find any unspent output with a given txid.
Definition: coins.cpp:315
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:280
CChainState::CoinsTip
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:837
ScriptHash
Definition: standard.h:114
gettxoutproof
static RPCHelpMan gettxoutproof()
Definition: rawtransaction.cpp:278
PSBTOutput::hd_keypaths
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:236
FastRandomContext
Fast randomness source.
Definition: random.h:129
UNIX_EPOCH_TIME
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
Definition: util.cpp:21
ValidationState::IsInvalid
bool IsInvalid() const
Definition: validation.h:119
ScriptToAsmStr
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
Definition: core_write.cpp:102
FlatSigningProvider
Definition: signingprovider.h:58
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:278
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11
PSBTAnalysis::error
std::string error
Error message.
Definition: psbt.h:46
ReadBE32
static uint32_t ReadBE32(const uint8_t *ptr)
Definition: common.h:56
rawtransaction_util.h