66 entry.
pushKV(
"confirmations", 0);
75 "\nReturn the raw transaction data.\n" 77 "\nBy default this function only works for mempool transactions. When called with a blockhash\n" 78 "argument, getrawtransaction will return the transaction if the specified block is available and\n" 79 "the transaction is found in that block. When called without a blockhash argument, getrawtransaction\n" 80 "will return the transaction if it is in the mempool, or if -txindex is enabled and the transaction\n" 81 "is in a block in the blockchain.\n" 83 "\nHint: Use gettransaction for wallet transactions.\n" 85 "\nIf verbose is 'true', returns an Object with information about 'txid'.\n" 86 "If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n",
93 RPCResult{
"if verbose is not set or set to false",
99 {
RPCResult::Type::BOOL,
"in_active_chain",
"Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"},
104 {
RPCResult::Type::NUM,
"vsize",
"The virtual transaction size (differs from size for witness transactions)"},
136 {
RPCResult::Type::NUM,
"reqSigs",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
138 {
RPCResult::Type::STR,
"address",
true,
"bitcoin address (only if a well-defined address exists)"},
139 {
RPCResult::Type::ARR,
"addresses",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
157 +
HelpExampleCli(
"getrawtransaction",
"\"mytxid\" false \"myblockhash\"")
158 +
HelpExampleCli(
"getrawtransaction",
"\"mytxid\" true \"myblockhash\"")
165 bool in_active_chain =
true;
169 if (hash ==
Params().GenesisBlock().hashMerkleRoot) {
175 bool fVerbose =
false;
176 if (!request.params[1].isNull()) {
177 fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool();
180 if (!request.params[2].isNull()) {
184 blockindex = chainman.m_blockman.LookupBlockIndex(blockhash);
191 bool f_txindex_ready =
false;
193 f_txindex_ready =
g_txindex->BlockUntilSyncedToCurrentChain();
204 errmsg =
"No such transaction found in the provided block";
206 errmsg =
"No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries";
207 }
else if (!f_txindex_ready) {
208 errmsg =
"No such mempool transaction. Blockchain transactions are still in the process of being indexed";
210 errmsg =
"No such mempool or blockchain transaction";
220 if (blockindex) result.
pushKV(
"in_active_chain", in_active_chain);
230 "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 231 "\nNOTE: By default this function only works sometimes. This is when there is an\n" 232 "unspent output in the utxo for this transaction. To make it always work,\n" 233 "you need to maintain a transaction index, using the -txindex command line option or\n" 234 "specify the block in which the transaction is included manually (by blockhash).\n",
249 std::set<uint256> setTxids;
254 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
255 auto ret = setTxids.insert(
ParseHashV(txids[idx],
"txid"));
264 if (!request.params[1].isNull()) {
266 hashBlock =
ParseHashV(request.params[1],
"blockhash");
267 pblockindex = chainman.m_blockman.LookupBlockIndex(hashBlock);
276 for (
const auto& tx : setTxids) {
288 g_txindex->BlockUntilSyncedToCurrentChain();
293 if (pblockindex ==
nullptr) {
295 if (!tx || hashBlock.
IsNull()) {
298 pblockindex = chainman.m_blockman.LookupBlockIndex(hashBlock);
309 unsigned int ntxFound = 0;
310 for (
const auto& tx : block.
vtx) {
311 if (setTxids.count(tx->GetHash())) {
315 if (ntxFound != setTxids.size()) {
322 std::string strHex =
HexStr(ssMB);
331 "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" 332 "and throwing an RPC error if the block is not in our best chain\n",
339 {
RPCResult::Type::STR_HEX,
"txid",
"The txid(s) which the proof commits to, or empty array if the proof can not be validated."},
351 std::vector<uint256> vMatch;
352 std::vector<unsigned int> vIndex;
353 if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot)
359 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(merkleBlock.header.GetHash());
365 if (pindex->
nTx == merkleBlock.txn.GetNumTransactions()) {
366 for (
const uint256& hash : vMatch) {
379 "\nCreate a transaction spending the given inputs and creating new outputs.\n" 380 "Outputs can be addresses or data.\n" 381 "Returns hex-encoded raw transaction.\n" 382 "Note that the transaction's inputs are not signed, and\n" 383 "it is not stored in the wallet or transmitted to the network.\n",
397 "That is, each address can only appear once and there can only be one 'data' object.\n" 398 "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" 399 " accepted as second parameter.",
415 " Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible."},
421 HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"address\\\":0.01}]\"")
422 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
423 +
HelpExampleRpc(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"[{\\\"address\\\":0.01}]\"")
424 +
HelpExampleRpc(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
437 if (!request.params[3].isNull()) {
438 rbf = request.params[3].isTrue();
450 "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
454 "If iswitness is not present, heuristic tests will be used in decoding.\n" 455 "If true, only witness deserialization will be tried.\n" 456 "If false, only non-witness deserialization will be tried.\n" 457 "This boolean should reflect whether the transaction has inputs\n" 458 "(e.g. fully valid, or on-chain transactions), if known by the caller." 467 {
RPCResult::Type::NUM,
"vsize",
"The virtual transaction size (differs from size for witness transactions)"},
499 {
RPCResult::Type::NUM,
"reqSigs",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
501 {
RPCResult::Type::STR,
"address",
true,
"bitcoin address (only if a well-defined address exists)"},
502 {
RPCResult::Type::ARR,
"addresses",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
517 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL});
521 bool try_witness = request.params[1].isNull() ? true : request.params[1].get_bool();
522 bool try_no_witness = request.params[1].isNull() ? true : !request.params[1].get_bool();
524 if (!
DecodeHexTx(mtx, request.params[0].get_str(), try_no_witness, try_witness)) {
538 std::vector<std::string> ret;
539 using U = std::underlying_type<TxoutType>::type;
543 return Join(ret,
", ");
549 "\nDecode a hex-encoded script.\n",
558 {
RPCResult::Type::STR,
"address",
true,
"bitcoin address (only if a well-defined address exists)"},
559 {
RPCResult::Type::NUM,
"reqSigs",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
560 {
RPCResult::Type::ARR,
"addresses",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
564 {
RPCResult::Type::STR,
"p2sh",
"address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
565 {
RPCResult::Type::OBJ,
"segwit",
"Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness)",
569 {
RPCResult::Type::STR,
"type",
"The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)"},
570 {
RPCResult::Type::STR,
"address",
true,
"bitcoin address (only if a well-defined address exists)"},
571 {
RPCResult::Type::NUM,
"reqSigs",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
572 {
RPCResult::Type::ARR,
"addresses",
true,
"(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
576 {
RPCResult::Type::STR,
"p2sh-segwit",
"address of the P2SH script wrapping this witness redeem script"},
590 if (request.params[0].get_str().size() > 0){
591 std::vector<unsigned char> scriptData(
ParseHexV(request.params[0],
"argument"));
592 script =
CScript(scriptData.begin(), scriptData.end());
608 std::vector<std::vector<unsigned char>> solutions_data;
613 for (
const auto& solution : solutions_data) {
644 "\nCombine multiple partially signed transactions into one transaction.\n" 645 "The combined transaction may be another partially signed transaction or a \n" 646 "fully signed transaction.",
658 HelpExampleCli(
"combinerawtransaction", R
"('["myhex1", "myhex2", "myhex3"]')") 664 std::vector<CMutableTransaction> txVariants(txs.
size());
666 for (
unsigned int idx = 0; idx < txs.
size(); idx++) {
667 if (!
DecodeHexTx(txVariants[idx], txs[idx].get_str())) {
672 if (txVariants.empty()) {
692 for (
const CTxIn& txin : mergedTx.
vin) {
703 for (
unsigned int i = 0; i < mergedTx.
vin.size(); i++) {
713 if (txv.vin.size() > i) {
729 return RPCHelpMan{
"signrawtransactionwithkey",
730 "\nSign inputs for raw transaction (serialized, hex-encoded).\n" 731 "The second argument is an array of base58-encoded private\n" 732 "keys that will be the only keys used to sign the transaction.\n" 733 "The third optional argument (may be null) is an array of previous transaction outputs that\n" 734 "this transaction depends on but may not yet be in the block chain.\n",
761 " \"ALL|ANYONECANPAY\"\n" 762 " \"NONE|ANYONECANPAY\"\n" 763 " \"SINGLE|ANYONECANPAY\"\n" 785 HelpExampleCli(
"signrawtransactionwithkey",
"\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"")
786 +
HelpExampleRpc(
"signrawtransactionwithkey",
"\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"")
790 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR},
true);
793 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
799 for (
unsigned int idx = 0; idx < keys.
size(); ++idx) {
809 std::map<COutPoint, Coin> coins;
829 "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n" 830 "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n" 831 "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n" 832 "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n" 833 "\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n" 834 "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
838 "Reject transactions whose fee rate is higher than the specified value, expressed in " +
CURRENCY_UNIT +
839 "/kvB.\nSet to 0 to accept any fee rate.\n"},
845 "\nCreate a transaction\n" 846 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
847 "Sign the transaction, and get back the hex\n" 849 "\nSend the transaction (signed hex)\n" 851 "\nAs a JSON-RPC call\n" 862 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
867 const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
872 CAmount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
874 std::string err_string;
882 return tx->GetHash().GetHex();
890 "\nReturns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n" 891 "\nIf multiple transactions are passed in, parents must come before children and package policies apply: the transactions cannot conflict with any mempool transactions or each other.\n" 892 "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n" 894 "\nThis checks if transactions violate the consensus or policy rules.\n" 895 "\nSee sendrawtransaction call.\n",
903 "Reject transactions whose fee rate is higher than the specified value, expressed in " +
CURRENCY_UNIT +
"/kvB\n"},
906 RPCResult::Type::ARR,
"",
"The result of the mempool acceptance test for each raw transaction in the input array.\n" 907 "Returns results for each transaction in the same order they were passed in.\n" 908 "It is possible for transactions to not be fully validated ('allowed' unset) if another transaction failed.\n",
914 {
RPCResult::Type::STR,
"package-error",
"Package validation error, if any (only possible if rawtxs had more than 1 transaction)."},
915 {
RPCResult::Type::BOOL,
"allowed",
"Whether this tx would be accepted to the mempool and pass client-specified maxfeerate." 916 "If not present, the tx was not fully validated due to a failure in another tx in the list."},
917 {
RPCResult::Type::NUM,
"vsize",
"Virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted (only present when 'allowed' is true)"},
922 {
RPCResult::Type::STR,
"reject-reason",
"Rejection string (only present when 'allowed' is false)"},
927 "\nCreate a transaction\n" 928 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
929 "Sign the transaction, and get back the hex\n" 931 "\nTest acceptance of the transaction (signed hex)\n" 933 "\nAs a JSON-RPC call\n" 948 const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
952 std::vector<CTransactionRef> txns;
953 txns.reserve(raw_transactions.
size());
954 for (
const auto& rawtx : raw_transactions.
getValues()) {
958 "TX decode failed: " + rawtx.get_str() +
" Make sure the tx has at least one input.");
978 bool exit_early{
false};
979 for (
const auto& tx : txns) {
981 result_inner.
pushKV(
"txid", tx->GetHash().GetHex());
982 result_inner.
pushKV(
"wtxid", tx->GetWitnessHash().GetHex());
986 auto it = package_result.
m_tx_results.find(tx->GetWitnessHash());
987 if (exit_early || it == package_result.
m_tx_results.end()) {
992 const auto& tx_result = it->second;
994 const CAmount fee = tx_result.m_base_fees.value();
997 const CAmount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
998 if (max_raw_tx_fee && fee > max_raw_tx_fee) {
999 result_inner.
pushKV(
"allowed",
false);
1000 result_inner.
pushKV(
"reject-reason",
"max-fee-exceeded");
1005 result_inner.
pushKV(
"allowed",
true);
1006 result_inner.
pushKV(
"vsize", virtual_size);
1009 result_inner.
pushKV(
"fees", fees);
1012 result_inner.
pushKV(
"allowed",
false);
1015 result_inner.
pushKV(
"reject-reason",
"missing-inputs");
1030 "\nReturn a JSON object representing the serialized, base64-encoded partially signed Bitcoin transaction.\n",
1049 {
RPCResult::Type::OBJ,
"non_witness_utxo",
true,
"Decoded network transaction for non-witness UTXOs",
1083 {
RPCResult::Type::OBJ,
"pubkey",
true,
"The public key with the derivation path as the value.",
1157 result.
pushKV(
"tx", tx_univ);
1161 for (
auto entry : psbtx.
unknown) {
1164 result.
pushKV(
"unknown", unknowns);
1168 bool have_all_utxos =
true;
1170 for (
unsigned int i = 0; i < psbtx.
inputs.size(); ++i) {
1174 bool have_a_utxo =
false;
1184 out.
pushKV(
"scriptPubKey", o);
1186 in.
pushKV(
"witness_utxo", out);
1195 in.
pushKV(
"non_witness_utxo", non_wit);
1201 total_in += txout.
nValue;
1204 have_all_utxos =
false;
1207 have_all_utxos =
false;
1216 in.
pushKV(
"partial_signatures", partial_sigs);
1228 in.
pushKV(
"redeem_script", r);
1233 in.
pushKV(
"witness_script", r);
1247 in.
pushKV(
"bip32_derivs", keypaths);
1255 in.
pushKV(
"final_scriptSig", scriptsig);
1262 in.
pushKV(
"final_scriptwitness", txinwitness);
1266 if (input.
unknown.size() > 0) {
1268 for (
auto entry : input.
unknown) {
1271 in.
pushKV(
"unknown", unknowns);
1276 result.
pushKV(
"inputs", inputs);
1281 for (
unsigned int i = 0; i < psbtx.
outputs.size(); ++i) {
1288 out.
pushKV(
"redeem_script", r);
1293 out.
pushKV(
"witness_script", r);
1306 out.
pushKV(
"bip32_derivs", keypaths);
1310 if (output.
unknown.size() > 0) {
1312 for (
auto entry : output.
unknown) {
1315 out.
pushKV(
"unknown", unknowns);
1322 output_value += psbtx.
tx->vout[i].nValue;
1325 have_all_utxos =
false;
1328 result.
pushKV(
"outputs", outputs);
1329 if (have_all_utxos) {
1341 "\nCombine multiple partially signed Bitcoin transactions into one transaction.\n" 1342 "Implements the Combiner role.\n",
1354 HelpExampleCli(
"combinepsbt", R
"('["mybase64_1", "mybase64_2", "mybase64_3"]')") 1361 std::vector<PartiallySignedTransaction> psbtxs;
1366 for (
unsigned int i = 0; i < txs.
size(); ++i) {
1372 psbtxs.push_back(psbtx);
1382 ssTx << merged_psbt;
1391 "Finalize the inputs of a PSBT. If the transaction is fully signed, it will produce a\n" 1392 "network serialized transaction which can be broadcast with sendrawtransaction. Otherwise a PSBT will be\n" 1393 "created which has the final_scriptSig and final_scriptWitness fields filled for inputs that are complete.\n" 1394 "Implements the Finalizer and Extractor roles.\n",
1398 " extract and return the complete transaction in normal network serialization instead of the PSBT."},
1403 {
RPCResult::Type::STR,
"psbt",
"The base64-encoded partially signed transaction if not extracted"},
1413 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL},
true);
1422 bool extract = request.params[1].isNull() || (!request.params[1].isNull() && request.params[1].get_bool());
1429 std::string result_str;
1433 result_str =
HexStr(ssTx);
1434 result.
pushKV(
"hex", result_str);
1438 result.
pushKV(
"psbt", result_str);
1440 result.
pushKV(
"complete", complete);
1450 "\nCreates a transaction in the Partially Signed Transaction format.\n" 1451 "Implements the Creator role.\n",
1465 "That is, each address can only appear once and there can only be one 'data' object.\n" 1466 "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" 1467 " accepted as second parameter.",
1483 " Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible."},
1489 HelpExampleCli(
"createpsbt",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
1503 if (!request.params[3].isNull()) {
1504 rbf = request.params[3].isTrue();
1511 for (
unsigned int i = 0; i < rawTx.
vin.size(); ++i) {
1514 for (
unsigned int i = 0; i < rawTx.
vout.size(); ++i) {
1530 "\nConverts a network serialized transaction to a PSBT. This should be used only with createrawtransaction and fundrawtransaction\n" 1531 "createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
1535 " will continue. If false, RPC will fail if any signatures are present."},
1537 "If iswitness is not present, heuristic tests will be used in decoding.\n" 1538 "If true, only witness deserialization will be tried.\n" 1539 "If false, only non-witness deserialization will be tried.\n" 1540 "This boolean should reflect whether the transaction has inputs\n" 1541 "(e.g. fully valid, or on-chain transactions), if known by the caller." 1548 "\nCreate a transaction\n" 1549 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
1550 "\nConvert the transaction to a PSBT\n" 1555 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL},
true);
1559 bool permitsigdata = request.params[1].isNull() ? false : request.params[1].get_bool();
1560 bool witness_specified = !request.params[2].isNull();
1561 bool iswitness = witness_specified ? request.params[2].get_bool() :
false;
1562 const bool try_witness = witness_specified ? iswitness :
true;
1563 const bool try_no_witness = witness_specified ? !iswitness :
true;
1564 if (!
DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
1580 for (
unsigned int i = 0; i < tx.
vin.size(); ++i) {
1583 for (
unsigned int i = 0; i < tx.
vout.size(); ++i) {
1599 "\nUpdates all segwit inputs and outputs in a PSBT with data from output descriptors, the UTXO set or the mempool.\n",
1611 RPCResult::Type::STR,
"",
"The base64-encoded partially signed transaction with inputs updated" 1618 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR},
true);
1629 if (!request.params[1].isNull()) {
1630 auto descs = request.params[1].get_array();
1631 for (
size_t i = 0; i < descs.size(); ++i) {
1650 for (
const CTxIn& txin : psbtx.
tx->vin) {
1659 for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
1679 for (
unsigned int i = 0; i < psbtx.
tx->vout.size(); ++i) {
1693 "\nJoins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs\n" 1694 "No input in any of the PSBTs can be in more than one of the PSBTs.\n",
1712 std::vector<PartiallySignedTransaction> psbtxs;
1715 if (txs.
size() <= 1) {
1719 uint32_t best_version = 1;
1720 uint32_t best_locktime = 0xffffffff;
1721 for (
unsigned int i = 0; i < txs.
size(); ++i) {
1727 psbtxs.push_back(psbtx);
1729 if (static_cast<uint32_t>(psbtx.
tx->nVersion) > best_version) {
1730 best_version =
static_cast<uint32_t
>(psbtx.
tx->nVersion);
1733 if (psbtx.
tx->nLockTime < best_locktime) {
1734 best_locktime = psbtx.
tx->nLockTime;
1741 merged_psbt.
tx->nVersion =
static_cast<int32_t
>(best_version);
1742 merged_psbt.
tx->nLockTime = best_locktime;
1745 for (
auto& psbt : psbtxs) {
1746 for (
unsigned int i = 0; i < psbt.tx->vin.size(); ++i) {
1747 if (!merged_psbt.
AddInput(psbt.tx->vin[i], psbt.inputs[i])) {
1751 for (
unsigned int i = 0; i < psbt.tx->vout.size(); ++i) {
1752 merged_psbt.
AddOutput(psbt.tx->vout[i], psbt.outputs[i]);
1754 merged_psbt.
unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
1758 std::vector<int> input_indices(merged_psbt.
inputs.size());
1759 std::iota(input_indices.begin(), input_indices.end(), 0);
1760 std::vector<int> output_indices(merged_psbt.
outputs.size());
1761 std::iota(output_indices.begin(), output_indices.end(), 0);
1769 shuffled_psbt.tx->nVersion = merged_psbt.
tx->nVersion;
1770 shuffled_psbt.tx->nLockTime = merged_psbt.
tx->nLockTime;
1771 for (
int i : input_indices) {
1772 shuffled_psbt.AddInput(merged_psbt.
tx->vin[i], merged_psbt.
inputs[i]);
1774 for (
int i : output_indices) {
1775 shuffled_psbt.AddOutput(merged_psbt.
tx->vout[i], merged_psbt.
outputs[i]);
1777 shuffled_psbt.unknown.insert(merged_psbt.
unknown.begin(), merged_psbt.
unknown.end());
1780 ssTx << shuffled_psbt;
1789 "\nAnalyzes and provides information about the current status of a PSBT and its inputs\n",
1802 {
RPCResult::Type::OBJ,
"missing",
true,
"Things that are missing that are required to complete this input",
1806 {
RPCResult::Type::STR_HEX,
"keyid",
"Public key ID, hash160 of the public key, of a public key whose BIP 32 derivation path is missing"},
1810 {
RPCResult::Type::STR_HEX,
"keyid",
"Public key ID, hash160 of the public key, of a public key whose signature is missing"},
1815 {
RPCResult::Type::STR,
"next",
true,
"Role of the next person that this input needs to go to"},
1818 {
RPCResult::Type::NUM,
"estimated_vsize",
true,
"Estimated vsize of the final signed transaction"},
1819 {
RPCResult::Type::STR_AMOUNT,
"estimated_feerate",
true,
"Estimated feerate of the final signed transaction in " +
CURRENCY_UNIT +
"/kvB. Shown only if all UTXO slots in the PSBT have been filled"},
1820 {
RPCResult::Type::STR_AMOUNT,
"fee",
true,
"The transaction fee paid. Shown only if all UTXO slots in the PSBT have been filled"},
1843 for (
const auto& input : psbta.
inputs) {
1847 input_univ.
pushKV(
"has_utxo", input.has_utxo);
1848 input_univ.
pushKV(
"is_final", input.is_final);
1851 if (!input.missing_pubkeys.empty()) {
1853 for (
const CKeyID& pubkey : input.missing_pubkeys) {
1856 missing.
pushKV(
"pubkeys", missing_pubkeys_univ);
1858 if (!input.missing_redeem_script.IsNull()) {
1859 missing.
pushKV(
"redeemscript",
HexStr(input.missing_redeem_script));
1861 if (!input.missing_witness_script.IsNull()) {
1862 missing.
pushKV(
"witnessscript",
HexStr(input.missing_witness_script));
1864 if (!input.missing_sigs.empty()) {
1866 for (
const CKeyID& pubkey : input.missing_sigs) {
1869 missing.
pushKV(
"signatures", missing_sigs_univ);
1871 if (!missing.
getKeys().empty()) {
1872 input_univ.
pushKV(
"missing", missing);
1876 if (!inputs_result.
empty()) result.
pushKV(
"inputs", inputs_result);
1884 if (psbta.
fee != std::nullopt) {
1888 if (!psbta.
error.empty()) {
1924 for (
const auto& c : commands) {
std::shared_ptr< const CTransaction > CTransactionRef
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
bool IsSpent() const
Either this coin never existed (see e.g.
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
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.
CTxMemPool & EnsureMemPool(const NodeContext &node)
static void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry, CChainState &active_chainstate)
const std::vector< UniValue > & getValues() const
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash, SignatureData *out_sigdata)
Signs a PSBTInput, verifying that all provided data matches what is being signed. ...
CChain m_chain
The current chain of blockheaders we consult and build on.
int64_t GetBlockTime() const
uint32_t nStatus
Verification status of this block.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
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.
The package itself is invalid (e.g. too many transactions).
void SetBackend(CCoinsView &viewIn)
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
Provides helpful miscellaneous information about where a PSBT is in the signing workflow.
static RPCHelpMan getrawtransaction()
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
CScriptWitness scriptWitness
Only serialized through CTransaction.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
MempoolAcceptResult AcceptToMemoryPool(CChainState &active_chainstate, CTxMemPool &pool, const CTransactionRef &tx, bool bypass_limits, bool test_accept)
(Try to) add a transaction to the memory pool.
std::vector< PSBTInputAnalysis > inputs
More information about the individual inputs of the transaction.
void ScriptToUniv(const CScript &script, UniValue &out, bool include_address)
transaction was missing some of its inputs
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
static RPCHelpMan combinerawtransaction()
bool MoneyRange(const CAmount &nValue)
int Height() const
Return the maximal height in the chain.
CTxOut out
unspent transaction output
std::map< const uint256, const MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
CChainState stores and provides an API to update our local knowledge of the current best chain...
std::vector< std::vector< unsigned char > > stack
PSBTRole next
Which of the BIP 174 roles needs to handle the transaction next.
std::optional< CFeeRate > estimated_feerate
Estimated feerate (fee / weight) of the transaction.
Holds the results of AnalyzePSBT (miscellaneous information about a PSBT)
const std::string & get_str() const
const UniValue & get_array() const
A version of CTransaction with the PSBT format.
Double ended buffer combining vector and stream-like interfaces.
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
CBlockIndex * LookupBlockIndex(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
A signature creator for transactions.
const std::vector< std::string > & getKeys() const
static RPCHelpMan sendrawtransaction()
static RPCHelpMan decoderawtransaction()
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, bool rbf)
Create a transaction from univalue parameters.
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized...
bool IsSegWitOutput(const SigningProvider &provider, const CScript &script)
Check whether a scriptPubKey is known to be segwit.
std::optional< size_t > estimated_vsize
Estimated weight of the transaction.
Invalid, missing or duplicate parameter.
const UniValue & find_value(const UniValue &obj, const std::string &name)
std::string PSBTRoleName(PSBTRole role)
int64_t CAmount
Amount in satoshis (Can be negative)
static RPCHelpMan createpsbt()
A structure for PSBTs which contains per output information.
static RPCHelpMan verifytxoutproof()
General error during transaction or block submission.
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
std::vector< PSBTOutput > outputs
std::map< CPubKey, KeyOriginInfo > hd_keypaths
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Special type that is a STR with only hex chars.
std::string EncodeBase64(Span< const unsigned char > input)
ChainstateManager & EnsureChainman(const NodeContext &node)
static RPCHelpMan finalizepsbt()
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
UniValue JSONRPCError(int code, const std::string &message)
bool push_back(const UniValue &val)
Special string with only hex chars.
NodeContext struct containing references to chain state and connection state.
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
static RPCHelpMan converttopsbt()
static RPCHelpMan combinepsbt()
static CAmount AmountFromValue(const UniValue &value)
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Abstract view on the open txout dataset.
Validation result for package mempool acceptance.
An input of a transaction.
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
const SigningProvider & DUMMY_SIGNING_PROVIDER
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
An encapsulated public key.
Fillable signing provider that keeps keys in an address->secret map.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const PackageValidationState m_state
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e...
static std::string GetAllOutputTypes()
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
static RPCHelpMan testmempoolaccept()
const std::string CURRENCY_UNIT
static uint32_t ReadBE32(const unsigned char *ptr)
std::string SighashToStr(unsigned char sighash_type)
General application defined errors.
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, bool include_addresses, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr)
bool pushKV(const std::string &key, const UniValue &val)
An output of a transaction.
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
void MergeSignatureData(SignatureData sigdata)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::vector< CTxOut > vout
static RPCHelpMan utxoupdatepsbt()
std::vector< PSBTInput > inputs
Special numeric to denote unix epoch time.
void RegisterRawTransactionRPCCommands(CRPCTable &t)
Register raw transaction RPC commands.
static RPCHelpMan signrawtransactionwithkey()
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Optional arg that is a named argument and has a default value of null.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
Special type that is a NUM or [NUM,NUM].
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
#define extract(n)
Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits.
Optional argument with default value omitted because they are implicitly clear.
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
TransactionError BroadcastTransaction(NodeContext &node, const CTransactionRef tx, std::string &err_string, const CAmount &max_tx_fee, bool relay, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
std::vector< CTransactionRef > vtx
static RPCHelpMan decodescript()
ChainstateManager & EnsureAnyChainman(const std::any &context)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::optional< CAmount > fee
Amount of fee being paid by the transaction.
Special string to represent a floating point amount.
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
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 ...
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
static RPCHelpMan gettxoutproof()
Serialized script, used inside transaction inputs and outputs.
int RPCSerializationFlags()
static const int PROTOCOL_VERSION
network protocol versioning
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
A reference to a CKey: the Hash160 of its serialized public key.
void UpdateInput(CTxIn &input, const SignatureData &data)
Special type representing a floating point amount (can be either NUM or STR)
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
std::string GetHex() const
Only for Witness versions not already defined above.
UniValue ValueFromAmount(const CAmount amount)
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
Fee rate in satoshis per kilobyte: CAmount / kB.
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances...
#define AssertLockNotHeld(cs)
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given size in bytes.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
std::string EncodeDestination(const CTxDestination &dest)
A mutable version of CTransaction.
static RPCHelpMan decodepsbt()
std::string error
Error message.
NodeContext & EnsureAnyNodeContext(const std::any &context)
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
CChainState & ActiveChainstate() const
The most-work chain.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
const Consensus::Params & GetConsensus() const
Special dictionary with keys that are not literals.
CKey DecodeSecret(const std::string &str)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
std::optional< CMutableTransaction > tx
std::string GetRejectReason() const
full block available in blk*.dat
static RPCHelpMan analyzepsbt()
PackageMempoolAcceptResult ProcessNewPackage(CChainState &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Atomically test acceptance of a package.
static RPCHelpMan createrawtransaction()
CCoinsView that brings transactions from a mempool into view.
bool error(const char *fmt, const Args &... args)
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, const Consensus::Params &consensusParams, uint256 &hashBlock)
Return transaction from the block at block_index.
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
unsigned int nTx
Number of transactions in this block.
CChain & ActiveChain() const
virtual bool AddKey(const CKey &key)
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Error parsing or validating structure in raw format.
Special type to denote elision (...)
bool IsValid() const
Check whether this private key is valid.
static RPCHelpMan joinpsbts()
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex, bool include_addresses)
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
bool IsCompressed() const
Check whether this is a compressed public key.
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...