7 #include <chainparams.h>
75 entry.
pushKV(
"confirmations",
81 entry.
pushKV(
"confirmations", 0);
90 "\nReturn the raw transaction data.\n"
91 "\nBy default, this call only returns a transaction if it is in the "
92 "mempool. If -txindex is enabled\n"
93 "and no blockhash argument is passed, it will return the transaction "
94 "if it is in the mempool or any block.\n"
95 "If a blockhash argument is passed, it will return the transaction if\n"
96 "the specified block is available and the transaction is in that "
98 "\nIf verbose is 'true', returns an Object with information about "
100 "If verbose is 'false' or omitted, returns a string that is "
101 "serialized, hex-encoded data for 'txid'.\n",
104 "The transaction id"},
108 "If false, return a string, otherwise return a json object",
112 "The block in which to look for the transaction"},
115 RPCResult{
"if verbose is not set or set to false",
117 "The serialized, hex-encoded data for 'txid'"},
119 "if verbose is set to true",
125 "Whether specified block is in the active chain or not "
126 "(only present with explicit \"blockhash\" argument)"},
128 "The serialized, hex-encoded data for 'txid'"},
130 "The transaction id (same as provided)"},
133 "The serialized transaction size"},
145 "The transaction id"},
155 "The script sequence number"},
176 "The required sigs"},
178 "The type, eg 'pubkeyhash'"},
191 "The confirmations"},
201 "\"mytxid\" false \"myblockhash\"") +
203 "\"mytxid\" true \"myblockhash\"")},
209 bool in_active_chain =
true;
218 "The genesis block coinbase is not considered an "
219 "ordinary transaction and cannot be retrieved");
224 bool fVerbose =
false;
225 if (!request.params[1].isNull()) {
226 fVerbose = request.params[1].isNum()
227 ? (request.params[1].getInt<
int>() != 0)
228 : request.params[1].get_bool();
231 if (!request.params[2].isNull()) {
235 ParseHashV(request.params[2],
"parameter 3"));
239 "Block hash not found");
244 bool f_txindex_ready =
false;
246 f_txindex_ready =
g_txindex->BlockUntilSyncedToCurrentChain();
257 return !blockindex->nStatus.hasData())) {
259 "Block not available");
261 errmsg =
"No such transaction found in the provided block";
264 "No such mempool transaction. Use -txindex or provide "
265 "a block hash to enable blockchain transaction queries";
266 }
else if (!f_txindex_ready) {
267 errmsg =
"No such mempool transaction. Blockchain "
268 "transactions are still in the process of being "
271 errmsg =
"No such mempool or blockchain transaction";
275 errmsg +
". Use gettransaction for wallet transactions.");
284 result.
pushKV(
"in_active_chain", in_active_chain);
286 TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
294 "createrawtransaction",
295 "Create a transaction spending the given inputs and creating new "
297 "Outputs can be addresses or data.\n"
298 "Returns hex-encoded raw transaction.\n"
299 "Note that the transaction's inputs are not signed, and\n"
300 "it is not stored in the wallet or transmitted to the network.\n",
317 "The output number"},
320 "'locktime' argument"},
321 "The sequence number"},
329 "The outputs (key-value pairs), where none of "
330 "the keys are duplicated.\n"
331 "That is, each address can only appear once and there can only "
332 "be one 'data' object.\n"
333 "For compatibility reasons, a dictionary, which holds the "
334 "key-value pairs directly, is also\n"
335 " accepted as second parameter.",
344 "A key-value pair. The key (string) is the "
345 "bitcoin address, the value (float or string) is "
357 "A key-value pair. The key must be \"data\", the "
358 "value is hex-encoded data"},
364 "Raw locktime. Non-0 value also locktime-activates inputs"},
367 "hex string of the transaction"},
370 "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
371 "\" \"[{\\\"address\\\":10000.00}]\"") +
373 "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
374 "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
376 "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
377 "\", \"[{\\\"address\\\":10000.00}]\"") +
379 "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
380 "\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")},
385 request.params[1], request.params[2]);
394 "decoderawtransaction",
395 "Return a JSON object representing the serialized, hex-encoded "
399 "The transaction hex string"},
420 "The transaction id"},
430 "The script sequence number"},
451 "The required sigs"},
453 "The type, eg 'pubkeyhash'"},
471 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
487 "Decode a hex-encoded script.\n",
490 "the hex-encoded script"},
508 "address of P2SH script wrapping this redeem script (not "
509 "returned if the script is already a P2SH)"},
517 if (request.params[0].get_str().size() > 0) {
518 std::vector<uint8_t> scriptData(
519 ParseHexV(request.params[0],
"argument"));
520 script =
CScript(scriptData.begin(), scriptData.end());
543 "combinerawtransaction",
544 "Combine multiple partially signed transactions into one "
546 "The combined transaction may be another partially signed transaction "
548 "fully signed transaction.",
554 "The hex strings of partially signed "
559 "A hex-encoded raw transaction"},
564 "The hex-encoded raw transaction with signature(s)"},
566 R
"('["myhex1", "myhex2", "myhex3"]')")},
570 std::vector<CMutableTransaction> txVariants(txs.
size());
572 for (
unsigned int idx = 0; idx < txs.
size(); idx++) {
573 if (!
DecodeHexTx(txVariants[idx], txs[idx].get_str())) {
576 strprintf(
"TX decode failed for tx %d", idx));
580 if (txVariants.empty()) {
582 "Missing transactions");
598 chainman.ActiveChainstate().CoinsTip();
603 for (
const CTxIn &txin : mergedTx.
vin) {
616 for (
size_t i = 0; i < mergedTx.
vin.size(); i++) {
621 "Input not found or already spent");
629 if (txv.vin.size() > i) {
636 &mergedTx, i, txout.
nValue),
649 "signrawtransactionwithkey",
650 "Sign inputs for raw transaction (serialized, hex-encoded).\n"
651 "The second argument is an array of base58-encoded private\n"
652 "keys that will be the only keys used to sign the transaction.\n"
653 "The third optional argument (may be null) is an array of previous "
654 "transaction outputs that\n"
655 "this transaction depends on but may not yet be in the block chain.\n",
658 "The transaction hex string"},
663 "The base58-encoded private keys for signing",
666 "private key in base58-encoding"},
673 "The previous dependent transaction outputs",
684 "The output number"},
689 "(required for P2SH) redeem script"},
697 "The signature hash type. Must be one of:\n"
700 " \"SINGLE|FORKID\"\n"
701 " \"ALL|FORKID|ANYONECANPAY\"\n"
702 " \"NONE|FORKID|ANYONECANPAY\"\n"
703 " \"SINGLE|FORKID|ANYONECANPAY\""},
711 "The hex-encoded raw transaction with signature(s)"},
713 "If the transaction has a complete set of signatures"},
717 "Script verification errors (if there are any)",
724 "The hash of the referenced, previous transaction"},
726 "The index of the output to spent and used as "
729 "The hex-encoded signature script"},
731 "Script sequence number"},
733 "Verification or signing error related to the "
740 "\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"") +
742 "\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"")},
746 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
753 for (
size_t idx = 0; idx < keys.
size(); ++idx) {
758 "Invalid private key");
764 std::map<COutPoint, Coin> coins;
784 "sendrawtransaction",
785 "Submits raw transaction (serialized, hex-encoded) to local node and "
787 "\nAlso see createrawtransaction and "
788 "signrawtransactionwithkey calls.\n",
791 "The hex string of the raw transaction"},
795 "Reject transactions whose fee rate is higher than the specified "
796 "value, expressed in " +
798 "/kB\nSet to 0 to accept any fee rate.\n"},
802 "\nCreate a transaction\n" +
804 "createrawtransaction",
805 "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" "
806 "\"{\\\"myaddress\\\":10000}\"") +
807 "Sign the transaction, and get back the hex\n" +
809 "\nSend the transaction (signed hex)\n" +
811 "\nAs a JSON-RPC call\n" +
817 if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
824 const CFeeRate max_raw_tx_fee_rate =
825 request.params[1].isNull()
830 Amount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
832 std::string err_string;
836 node, tx, err_string, max_raw_tx_fee,
true,
845 return tx->GetHash().GetHex();
853 "\nReturns result of mempool acceptance tests indicating if raw "
854 "transaction(s) (serialized, hex-encoded) would be accepted by "
856 "\nIf multiple transactions are passed in, parents must come before "
857 "children and package policies apply: the transactions cannot conflict "
858 "with any mempool transactions or each other.\n"
859 "\nIf one transaction fails, other transactions may not be fully "
860 "validated (the 'allowed' key will be blank).\n"
861 "\nThe maximum number of transactions allowed is " +
864 "\nThis checks if transactions violate the consensus or policy "
866 "\nSee sendrawtransaction call.\n",
872 "An array of hex strings of raw transactions.",
881 "Reject transactions whose fee rate is higher than the specified "
882 "value, expressed in " +
888 "The result of the mempool acceptance test for each raw "
889 "transaction in the input array.\n"
890 "Returns results for each transaction in the same order they were "
892 "Transactions that cannot be fully validated due to failures in "
893 "other transactions will not contain an 'allowed' result.\n",
900 "The transaction hash in hex"},
902 "Package validation error, if any (only possible if "
903 "rawtxs had more than 1 transaction)."},
905 "Whether this tx would be accepted to the mempool and "
906 "pass client-specified maxfeerate. "
907 "If not present, the tx was not fully validated due to a "
908 "failure in another tx in the list."},
912 "Transaction fees (only present if 'allowed' is true)",
918 "Rejection string (only present when 'allowed' is "
923 "\nCreate a transaction\n" +
925 "createrawtransaction",
926 "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" "
927 "\"{\\\"myaddress\\\":10000}\"") +
928 "Sign the transaction, and get back the hex\n" +
930 "\nTest acceptance of the transaction (signed hex)\n" +
932 "\nAs a JSON-RPC call\n" +
937 if (raw_transactions.
size() < 1 ||
940 "Array must contain between 1 and " +
945 const CFeeRate max_raw_tx_fee_rate =
946 request.params[1].isNull()
950 std::vector<CTransactionRef> txns;
951 txns.reserve(raw_transactions.
size());
952 for (
const auto &rawtx : raw_transactions.
getValues()) {
956 "TX decode failed: " + rawtx.get_str());
964 Chainstate &chainstate = chainman.ActiveChainstate();
967 if (txns.size() > 1) {
983 bool exit_early{
false};
984 for (
const auto &tx : txns) {
986 result_inner.
pushKV(
"txid", tx->GetId().GetHex());
993 auto it = package_result.
m_tx_results.find(tx->GetId());
994 if (exit_early || it == package_result.
m_tx_results.end()) {
999 const auto &tx_result = it->second;
1004 if (tx_result.m_result_type ==
1006 const Amount fee = tx_result.m_base_fees.value();
1008 const int64_t virtual_size = tx_result.m_vsize.value();
1009 const Amount max_raw_tx_fee =
1010 max_raw_tx_fee_rate.
GetFee(virtual_size);
1012 fee > max_raw_tx_fee) {
1013 result_inner.
pushKV(
"allowed",
false);
1014 result_inner.
pushKV(
"reject-reason",
1015 "max-fee-exceeded");
1021 result_inner.
pushKV(
"allowed",
true);
1022 result_inner.
pushKV(
"size", virtual_size);
1024 fees.
pushKV(
"base", fee);
1025 result_inner.
pushKV(
"fees", fees);
1028 result_inner.
pushKV(
"allowed",
false);
1032 result_inner.
pushKV(
"reject-reason",
"missing-inputs");
1034 result_inner.
pushKV(
"reject-reason",
1048 "Return a JSON object representing the serialized, base64-encoded "
1049 "partially signed Bitcoin transaction.\n",
1052 "The PSBT base64 string"},
1061 "The decoded network-serialized unsigned transaction.",
1064 "The layout is the same as the output of "
1065 "decoderawtransaction."},
1069 "The unknown global fields",
1072 "(key-value pair) An unknown key-value pair"},
1085 "Transaction output for UTXOs",
1097 "The type, eg 'pubkeyhash'"},
1099 " Bitcoin address if there is one"},
1103 "partial_signatures",
1108 "The public key and signature that corresponds "
1112 "The sighash type to be used"},
1121 "The type, eg 'pubkeyhash'"},
1131 "The public key with the derivation path as "
1135 "The fingerprint of the master key"},
1149 "The unknown global fields",
1152 "(key-value pair) An unknown key-value pair"},
1172 "The type, eg 'pubkeyhash'"},
1184 "The public key this path corresponds to"},
1186 "The fingerprint of the master key"},
1192 "The unknown global fields",
1195 "(key-value pair) An unknown key-value pair"},
1200 "The transaction fee paid if all UTXOs slots in the PSBT have "
1219 result.
pushKV(
"tx", tx_univ);
1222 if (psbtx.
unknown.size() > 0) {
1224 for (
auto entry : psbtx.
unknown) {
1227 result.
pushKV(
"unknown", unknowns);
1232 bool have_all_utxos =
true;
1234 for (
size_t i = 0; i < psbtx.
inputs.size(); ++i) {
1246 total_in += txout.
nValue;
1249 have_all_utxos =
false;
1254 out.
pushKV(
"scriptPubKey", o);
1257 have_all_utxos =
false;
1267 in.
pushKV(
"partial_signatures", partial_sigs);
1271 uint8_t sighashbyte =
1273 if (sighashbyte > 0) {
1281 in.
pushKV(
"redeem_script", r);
1292 "master_fingerprint",
1294 ReadBE32(entry.second.fingerprint)));
1299 in.
pushKV(
"bip32_derivs", keypaths);
1308 in.
pushKV(
"final_scriptSig", scriptsig);
1312 if (input.
unknown.size() > 0) {
1314 for (
auto entry : input.
unknown) {
1318 in.
pushKV(
"unknown", unknowns);
1323 result.
pushKV(
"inputs", inputs);
1328 for (
size_t i = 0; i < psbtx.
outputs.size(); ++i) {
1335 out.
pushKV(
"redeem_script", r);
1345 "master_fingerprint",
1347 ReadBE32(entry.second.fingerprint)));
1352 out.
pushKV(
"bip32_derivs", keypaths);
1356 if (output.
unknown.size() > 0) {
1358 for (
auto entry : output.
unknown) {
1362 out.
pushKV(
"unknown", unknowns);
1370 output_value += psbtx.
tx->vout[i].nValue;
1373 have_all_utxos =
false;
1376 result.
pushKV(
"outputs", outputs);
1377 if (have_all_utxos) {
1378 result.
pushKV(
"fee", total_in - output_value);
1389 "Combine multiple partially signed Bitcoin transactions into one "
1391 "Implements the Combiner role.\n",
1397 "The base64 strings of partially signed transactions",
1400 "A base64 string of a PSBT"},
1405 "The base64-encoded partially signed transaction"},
1407 "combinepsbt", R
"('["mybase64_1", "mybase64_2", "mybase64_3"]')")},
1411 std::vector<PartiallySignedTransaction> psbtxs;
1415 "Parameter 'txs' cannot be empty");
1417 for (
size_t i = 0; i < txs.
size(); ++i) {
1424 psbtxs.push_back(psbtx);
1434 ssTx << merged_psbt;
1443 "Finalize the inputs of a PSBT. If the transaction is fully signed, it "
1445 "network serialized transaction which can be broadcast with "
1446 "sendrawtransaction. Otherwise a PSBT will be\n"
1447 "created which has the final_scriptSigfields filled for inputs that "
1449 "Implements the Finalizer and Extractor roles.\n",
1452 "A base64 string of a PSBT"},
1454 "If true and the transaction is complete,\n"
1455 " extract and return the complete "
1456 "transaction in normal network serialization instead of the "
1464 "The base64-encoded partially signed transaction if not "
1467 "The hex-encoded network transaction if extracted"},
1469 "If the transaction has a complete set of signatures"},
1483 request.params[1].isNull() ||
1484 (!request.params[1].isNull() && request.params[1].get_bool());
1491 std::string result_str;
1495 result_str =
HexStr(ssTx);
1496 result.
pushKV(
"hex", result_str);
1500 result.
pushKV(
"psbt", result_str);
1502 result.
pushKV(
"complete", complete);
1512 "Creates a transaction in the Partially Signed Transaction format.\n"
1513 "Implements the Creator role.\n",
1530 "The output number"},
1533 "'locktime' argument"},
1534 "The sequence number"},
1542 "The outputs (key-value pairs), where none of "
1543 "the keys are duplicated.\n"
1544 "That is, each address can only appear once and there can only "
1545 "be one 'data' object.\n"
1546 "For compatibility reasons, a dictionary, which holds the "
1547 "key-value pairs directly, is also\n"
1548 " accepted as second parameter.",
1557 "A key-value pair. The key (string) is the "
1558 "bitcoin address, the value (float or string) is "
1570 "A key-value pair. The key must be \"data\", the "
1571 "value is hex-encoded data"},
1577 "Raw locktime. Non-0 value also locktime-activates inputs"},
1580 "The resulting raw transaction (base64-encoded string)"},
1582 "createpsbt",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
1583 "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")},
1588 request.params[1], request.params[2]);
1593 for (
size_t i = 0; i < rawTx.
vin.size(); ++i) {
1596 for (
size_t i = 0; i < rawTx.
vout.size(); ++i) {
1612 "Converts a network serialized transaction to a PSBT. "
1613 "This should be used only with createrawtransaction and "
1614 "fundrawtransaction\n"
1615 "createpsbt and walletcreatefundedpsbt should be used for new "
1619 "The hex string of a raw transaction"},
1621 "If true, any signatures in the input will be discarded and "
1623 " will continue. If false, RPC will "
1624 "fail if any signatures are present."},
1627 "The resulting raw transaction (base64-encoded string)"},
1629 "\nCreate a transaction\n" +
1631 "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]"
1632 "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
1633 "\nConvert the transaction to a PSBT\n" +
1639 bool permitsigdata = request.params[1].isNull()
1641 : request.params[1].get_bool();
1642 if (!
DecodeHexTx(tx, request.params[0].get_str())) {
1644 "TX decode failed");
1651 "Inputs must not have scriptSigs");
1659 for (
size_t i = 0; i < tx.
vin.size(); ++i) {
1662 for (
size_t i = 0; i < tx.
vout.size(); ++i) {
1678 "Updates all inputs and outputs in a PSBT with data from output "
1679 "descriptors, the UTXO set or the mempool.\n",
1682 "A base64 string of a PSBT"},
1686 "An array of either strings or objects",
1689 "An output descriptor"},
1693 "An object with an output descriptor and extra information",
1696 "An output descriptor"},
1698 "Up to what index HD chains should be explored (either "
1699 "end or [begin,end])"},
1704 "The base64-encoded partially signed transaction with inputs "
1719 if (!request.params[1].isNull()) {
1720 auto descs = request.params[1].get_array();
1721 for (
size_t i = 0; i < descs.size(); ++i) {
1739 chainman.ActiveChainstate().CoinsTip();
1744 for (
const CTxIn &txin : psbtx.
tx->vin) {
1754 for (
size_t i = 0; i < psbtx.
tx->vin.size(); ++i) {
1770 for (
unsigned int i = 0; i < psbtx.
tx->vout.size(); ++i) {
1784 "Joins multiple distinct PSBTs with different inputs and outputs "
1785 "into one PSBT with inputs and outputs from all of the PSBTs\n"
1786 "No input in any of the PSBTs can be in more than one of the PSBTs.\n",
1790 "The base64 strings of partially signed transactions",
1792 "A base64 string of a PSBT"}}}},
1794 "The base64-encoded partially signed transaction"},
1799 std::vector<PartiallySignedTransaction> psbtxs;
1802 if (txs.
size() <= 1) {
1805 "At least two PSBTs are required to join PSBTs.");
1808 uint32_t best_version = 1;
1809 uint32_t best_locktime = 0xffffffff;
1810 for (
size_t i = 0; i < txs.
size(); ++i) {
1817 psbtxs.push_back(psbtx);
1819 if (
static_cast<uint32_t
>(psbtx.
tx->nVersion) > best_version) {
1820 best_version =
static_cast<uint32_t
>(psbtx.
tx->nVersion);
1823 if (psbtx.
tx->nLockTime < best_locktime) {
1824 best_locktime = psbtx.
tx->nLockTime;
1831 merged_psbt.
tx->nVersion =
static_cast<int32_t
>(best_version);
1832 merged_psbt.
tx->nLockTime = best_locktime;
1835 for (
auto &psbt : psbtxs) {
1836 for (
size_t i = 0; i < psbt.tx->vin.size(); ++i) {
1837 if (!merged_psbt.
AddInput(psbt.tx->vin[i],
1841 strprintf(
"Input %s:%d exists in multiple PSBTs",
1846 psbt.tx->vin[i].prevout.GetN()));
1849 for (
size_t i = 0; i < psbt.tx->vout.size(); ++i) {
1850 merged_psbt.
AddOutput(psbt.tx->vout[i], psbt.outputs[i]);
1852 merged_psbt.
unknown.insert(psbt.unknown.begin(),
1853 psbt.unknown.end());
1858 std::vector<int> input_indices(merged_psbt.
inputs.size());
1859 std::iota(input_indices.begin(), input_indices.end(), 0);
1860 std::vector<int> output_indices(merged_psbt.
outputs.size());
1861 std::iota(output_indices.begin(), output_indices.end(), 0);
1864 Shuffle(input_indices.begin(), input_indices.end(),
1866 Shuffle(output_indices.begin(), output_indices.end(),
1871 shuffled_psbt.
tx->nVersion = merged_psbt.
tx->nVersion;
1872 shuffled_psbt.
tx->nLockTime = merged_psbt.
tx->nLockTime;
1873 for (
int i : input_indices) {
1874 shuffled_psbt.
AddInput(merged_psbt.
tx->vin[i],
1877 for (
int i : output_indices) {
1885 ssTx << shuffled_psbt;
1894 "Analyzes and provides information about the current status of a "
1895 "PSBT and its inputs\n",
1897 "A base64 string of a PSBT"}},
1912 "Whether a UTXO is provided"},
1914 "Whether the input is finalized"},
1918 "Things that are missing that are required to "
1919 "complete this input",
1927 "Public key ID, hash160 of the public "
1928 "key, of a public key whose BIP 32 "
1929 "derivation path is missing"},
1937 "Public key ID, hash160 of the public "
1938 "key, of a public key whose signature is "
1943 "Hash160 of the redeemScript that is missing"},
1946 "Role of the next person that this input needs to "
1951 "Estimated vsize of the final signed transaction"},
1954 "Estimated feerate of the final signed transaction in " +
1956 "/kB. Shown only if all UTXO slots in the PSBT have been "
1959 "The transaction fee paid. Shown only if all UTXO slots in "
1960 "the PSBT have been filled"},
1962 "Role of the next person that this psbt needs to go to"},
1964 "Error message (if there is one)"},
1981 for (
const auto &input : psbta.
inputs) {
1985 input_univ.
pushKV(
"has_utxo", input.has_utxo);
1986 input_univ.
pushKV(
"is_final", input.is_final);
1989 if (!input.missing_pubkeys.empty()) {
1991 for (
const CKeyID &pubkey : input.missing_pubkeys) {
1994 missing.
pushKV(
"pubkeys", missing_pubkeys_univ);
1996 if (!input.missing_redeem_script.IsNull()) {
1997 missing.
pushKV(
"redeemscript",
1998 HexStr(input.missing_redeem_script));
2000 if (!input.missing_sigs.empty()) {
2002 for (
const CKeyID &pubkey : input.missing_sigs) {
2005 missing.
pushKV(
"signatures", missing_sigs_univ);
2007 if (!missing.
getKeys().empty()) {
2008 input_univ.
pushKV(
"missing", missing);
2012 if (!inputs_result.
empty()) {
2013 result.
pushKV(
"inputs", inputs_result);
2019 result.
pushKV(
"estimated_feerate",
2022 if (psbta.
fee != std::nullopt) {
2026 if (!psbta.
error.empty()) {
2058 for (
const auto &c : commands) {
bool MoneyRange(const Amount nValue)
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
#define CHECK_NONFATAL(condition)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
int64_t GetBlockTime() const
int nHeight
height of the entry in the chain. The genesis block has height 0
int Height() const
Return the maximal height in the chain.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const CBlock & GenesisBlock() const
void SetBackend(CCoinsView &viewIn)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Abstract view on the open txout dataset.
CCoinsView that brings transactions from a mempool into view.
Double ended buffer combining vector and stream-like interfaces.
Fee rate in satoshis per kilobyte: Amount / kB.
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Amount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
An encapsulated secp256k1 private key.
bool IsValid() const
Check whether this private key is valid.
A reference to a CKey: the Hash160 of its serialized public key.
A mutable version of CTransaction.
std::vector< CTxOut > vout
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
An output of a transaction.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
CChain m_chain
The current chain of blockheaders we consult and build on.
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
MempoolAcceptResult ProcessTransaction(const CTransactionRef &tx, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the memory pool.
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKey(const CKey &key)
A signature creator for transactions.
Signature hash type wrapper class.
uint32_t getRawSigHashType() const
void push_back(UniValue val)
const std::string & get_str() const
const UniValue & find_value(std::string_view key) const
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
const UniValue & get_array() const
void pushKV(std::string key, UniValue val)
std::string GetRejectReason() const
std::string GetHex() const
CBlockIndex * LookupBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
void ScriptToUniv(const CScript &script, UniValue &out, bool include_address)
void TxToUniv(const CTransaction &tx, const BlockHash &hashBlock, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr)
std::string SighashToStr(uint8_t sighash_type)
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
static uint32_t ReadBE32(const uint8_t *ptr)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
CKey DecodeSecret(const std::string &str)
bool error(const char *fmt, const Args &...args)
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
Provides helpful miscellaneous information about where a PSBT is in the signing workflow.
TransactionError BroadcastTransaction(const NodeContext &node, 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.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const TxId &txid, BlockHash &hashBlock, const BlockManager &blockman)
Return transaction with a given txid.
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
int64_t GetVirtualTransactionSize(int64_t nSize, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
Compute the virtual transaction size (size, or more if sigChecks are too dense).
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
std::string PSBTRoleName(const PSBTRole role)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
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...
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.
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
static RPCHelpMan getrawtransaction()
static RPCHelpMan sendrawtransaction()
static RPCHelpMan converttopsbt()
static RPCHelpMan decoderawtransaction()
static RPCHelpMan combinepsbt()
static RPCHelpMan decodepsbt()
static RPCHelpMan decodescript()
static RPCHelpMan createpsbt()
RPCHelpMan utxoupdatepsbt()
static RPCHelpMan combinerawtransaction()
static void TxToJSON(const CTransaction &tx, const BlockHash &hashBlock, UniValue &entry, Chainstate &active_chainstate)
static RPCHelpMan testmempoolaccept()
static RPCHelpMan signrawtransactionwithkey()
static RPCHelpMan createrawtransaction()
static RPCHelpMan finalizepsbt()
void RegisterRawTransactionRPCCommands(CRPCTable &t)
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.
CMutableTransaction ConstructTransaction(const CChainParams ¶ms, const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime)
Create a transaction from univalue parameters.
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.
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_MISC_ERROR
General application defined errors std::exception thrown in command handling.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_VERIFY_ERROR
General error during transaction or block submission.
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::vector< uint8_t > ParseHexV(const UniValue &v, std::string strName)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Amount AmountFromValue(const UniValue &value)
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 ...
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
std::string GetAllOutputTypes()
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
#define extract(n)
Extract the lowest 64 bits of (c0,c1,c2) into n, and left shift the number 64 bits.
int RPCSerializationFlags()
Retrieves any serialization flags requested in command line argument.
NodeContext & EnsureAnyNodeContext(const std::any &context)
CTxMemPool & EnsureMemPool(const NodeContext &node)
ChainstateManager & EnsureChainman(const NodeContext &node)
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void UpdateInput(CTxIn &input, const SignatureData &data)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
const SigningProvider & DUMMY_SIGNING_PROVIDER
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::string EncodeBase64(Span< const uint8_t > input)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
static constexpr Amount zero() noexcept
A BlockHash is a unqiue identifier for a block.
static const Currency & get()
@ MEMPOOL_ENTRY
Valid, transaction was already in the mempool.
@ VALID
Fully validated, valid.
A structure for PSBTs which contains per output information.
std::map< CPubKey, KeyOriginInfo > hd_keypaths
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
Validation result for package mempool acceptance.
std::map< const TxId, const MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
const PackageValidationState m_state
A version of CTransaction with the PSBT format.
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
std::vector< PSBTInput > inputs
std::optional< CMutableTransaction > tx
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
std::vector< PSBTOutput > outputs
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ OBJ_USER_KEYS
Special type where the user must set the keys e.g.
@ STR_HEX
Special type that is a STR with only hex chars.
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
std::string DefaultHint
Hint for default value.
@ OMITTED
The arg is optional for one of two reasons:
@ ELISION
Special type to denote elision (...)
@ NUM_TIME
Special numeric to denote unix epoch time.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
void MergeSignatureData(SignatureData sigdata)
A TxId is the identifier of a transaction.
NodeContext struct containing references to chain state and connection state.
Holds the results of AnalyzePSBT (miscellaneous information about a PSBT)
std::vector< PSBTInputAnalysis > inputs
More information about the individual inputs of the transaction.
std::string error
Error message.
std::optional< Amount > fee
Amount of fee being paid by the transaction.
std::optional< size_t > estimated_vsize
Estimated weight of the transaction.
std::optional< CFeeRate > estimated_feerate
Estimated feerate (fee / weight) of the transaction.
PSBTRole next
Which of the BIP 174 roles needs to handle the transaction next.
#define AssertLockNotHeld(cs)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Validate (and maybe submit) a package to the mempool.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
static const int PROTOCOL_VERSION
network protocol versioning