67                entry.
pushKV(
"confirmations", 0);
 
   76                "\nReturn the raw transaction data.\n" 
   78                "\nBy default, this call only returns a transaction if it is in the mempool. If -txindex is enabled\n" 
   79                "and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.\n" 
   80                "If a blockhash argument is passed, it will return the transaction if\n" 
   81                "the specified block is available and the transaction is in that block.\n" 
   82                "\nHint: Use gettransaction for wallet transactions.\n" 
   84                "\nIf verbose is 'true', returns an Object with information about 'txid'.\n" 
   85                "If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n",
 
   92                    RPCResult{
"if verbose is not set or set to false",
 
   98                             {
RPCResult::Type::BOOL, 
"in_active_chain",  
true, 
"Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"},
 
  103                             {
RPCResult::Type::NUM, 
"vsize", 
"The virtual transaction size (differs from size for witness transactions)"},
 
  136                                         {
RPCResult::Type::STR, 
"address",  
true, 
"The Bitcoin address (only if a well-defined address exists)"},
 
  151            + 
HelpExampleCli(
"getrawtransaction", 
"\"mytxid\" false \"myblockhash\"")
 
  152            + 
HelpExampleCli(
"getrawtransaction", 
"\"mytxid\" true \"myblockhash\"")
 
  159    bool in_active_chain = 
true;
 
  163    if (hash == 
Params().GenesisBlock().hashMerkleRoot) {
 
  169    bool fVerbose = 
false;
 
  170    if (!request.params[1].isNull()) {
 
  171        fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool();
 
  174    if (!request.params[2].isNull()) {
 
  178        blockindex = chainman.m_blockman.LookupBlockIndex(blockhash);
 
  185    bool f_txindex_ready = 
false;
 
  187        f_txindex_ready = 
g_txindex->BlockUntilSyncedToCurrentChain();
 
  198            errmsg = 
"No such transaction found in the provided block";
 
  200            errmsg = 
"No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries";
 
  201        } 
else if (!f_txindex_ready) {
 
  202            errmsg = 
"No such mempool transaction. Blockchain transactions are still in the process of being indexed";
 
  204            errmsg = 
"No such mempool or blockchain transaction";
 
  214    if (blockindex) result.
pushKV(
"in_active_chain", in_active_chain);
 
  224                "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 
  225                "\nNOTE: By default this function only works sometimes. This is when there is an\n" 
  226                "unspent output in the utxo for this transaction. To make it always work,\n" 
  227                "you need to maintain a transaction index, using the -txindex command line option or\n" 
  228                "specify the block in which the transaction is included manually (by blockhash).\n",
 
  243    std::set<uint256> setTxids;
 
  248    for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
 
  249        auto ret = setTxids.insert(
ParseHashV(txids[idx], 
"txid"));
 
  258    if (!request.params[1].isNull()) {
 
  260        hashBlock = 
ParseHashV(request.params[1], 
"blockhash");
 
  261        pblockindex = chainman.m_blockman.LookupBlockIndex(hashBlock);
 
  270        for (
const auto& tx : setTxids) {
 
  282        g_txindex->BlockUntilSyncedToCurrentChain();
 
  287    if (pblockindex == 
nullptr) {
 
  289        if (!tx || hashBlock.
IsNull()) {
 
  292        pblockindex = chainman.m_blockman.LookupBlockIndex(hashBlock);
 
  303    unsigned int ntxFound = 0;
 
  304    for (
const auto& tx : block.
vtx) {
 
  305        if (setTxids.count(tx->GetHash())) {
 
  309    if (ntxFound != setTxids.size()) {
 
  316    std::string strHex = 
HexStr(ssMB);
 
  325                "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" 
  326                "and throwing an RPC error if the block is not in our best chain\n",
 
  333                        {
RPCResult::Type::STR_HEX, 
"txid", 
"The txid(s) which the proof commits to, or empty array if the proof can not be validated."},
 
  345    std::vector<uint256> vMatch;
 
  346    std::vector<unsigned int> vIndex;
 
  360        for (
const uint256& hash : vMatch) {
 
  373                "\nCreate a transaction spending the given inputs and creating new outputs.\n" 
  374                "Outputs can be addresses or data.\n" 
  375                "Returns hex-encoded raw transaction.\n" 
  376                "Note that the transaction's inputs are not signed, and\n" 
  377                "it is not stored in the wallet or transmitted to the network.\n",
 
  391                            "That is, each address can only appear once and there can only be one 'data' object.\n" 
  392                            "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" 
  393                            "                             accepted as second parameter.",
 
  409            "                             Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible."},
 
  415                    HelpExampleCli(
"createrawtransaction", 
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"address\\\":0.01}]\"")
 
  416            + 
HelpExampleCli(
"createrawtransaction", 
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
 
  417            + 
HelpExampleRpc(
"createrawtransaction", 
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"[{\\\"address\\\":0.01}]\"")
 
  418            + 
HelpExampleRpc(
"createrawtransaction", 
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
 
  431    if (!request.params[3].isNull()) {
 
  432        rbf = request.params[3].isTrue();
 
  444                "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
 
  448                        "If iswitness is not present, heuristic tests will be used in decoding.\n" 
  449                        "If true, only witness deserialization will be tried.\n" 
  450                        "If false, only non-witness deserialization will be tried.\n" 
  451                        "This boolean should reflect whether the transaction has inputs\n" 
  452                        "(e.g. fully valid, or on-chain transactions), if known by the caller." 
  461                        {
RPCResult::Type::NUM, 
"vsize", 
"The virtual transaction size (differs from size for witness transactions)"},
 
  495                                    {
RPCResult::Type::STR, 
"address",  
true, 
"The Bitcoin address (only if a well-defined address exists)"},
 
  507    RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL});
 
  511    bool try_witness = request.params[1].isNull() ? true : request.params[1].get_bool();
 
  512    bool try_no_witness = request.params[1].isNull() ? true : !request.params[1].get_bool();
 
  514    if (!
DecodeHexTx(mtx, request.params[0].get_str(), try_no_witness, try_witness)) {
 
  528    std::vector<std::string> ret;
 
  529    using U = std::underlying_type<TxoutType>::type;
 
  533    return Join(ret, 
", ");
 
  539                "\nDecode a hex-encoded script.\n",
 
  548                        {
RPCResult::Type::STR, 
"address",  
true, 
"The Bitcoin address (only if a well-defined address exists)"},
 
  549                        {
RPCResult::Type::STR, 
"p2sh",  
true, 
"address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
 
  550                        {
RPCResult::Type::OBJ, 
"segwit",  
true, 
"Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness)",
 
  554                            {
RPCResult::Type::STR, 
"type", 
"The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)"},
 
  555                            {
RPCResult::Type::STR, 
"address",  
true, 
"The Bitcoin address (only if a well-defined address exists)"},
 
  556                            {
RPCResult::Type::STR, 
"p2sh-segwit", 
"address of the P2SH script wrapping this witness redeem script"},
 
  570    if (request.params[0].get_str().size() > 0){
 
  571        std::vector<unsigned char> scriptData(
ParseHexV(request.params[0], 
"argument"));
 
  572        script = 
CScript(scriptData.begin(), scriptData.end());
 
  588            std::vector<std::vector<unsigned char>> solutions_data;
 
  593                for (
const auto& solution : solutions_data) {
 
  594                    if ((solution.size() != 1) && !
CPubKey(solution).IsCompressed()) {
 
  624                "\nCombine multiple partially signed transactions into one transaction.\n" 
  625                "The combined transaction may be another partially signed transaction or a \n" 
  626                "fully signed transaction.",
 
  638                    HelpExampleCli(
"combinerawtransaction", R
"('["myhex1", "myhex2", "myhex3"]')") 
  644    std::vector<CMutableTransaction> txVariants(txs.
size());
 
  646    for (
unsigned int idx = 0; idx < txs.
size(); idx++) {
 
  647        if (!
DecodeHexTx(txVariants[idx], txs[idx].get_str())) {
 
  652    if (txVariants.empty()) {
 
  672        for (
const CTxIn& txin : mergedTx.
vin) {
 
  683    for (
unsigned int i = 0; i < mergedTx.
vin.size(); i++) {
 
  693            if (txv.vin.size() > i) {
 
  709    return RPCHelpMan{
"signrawtransactionwithkey",
 
  710                "\nSign inputs for raw transaction (serialized, hex-encoded).\n" 
  711                "The second argument is an array of base58-encoded private\n" 
  712                "keys that will be the only keys used to sign the transaction.\n" 
  713                "The third optional argument (may be null) is an array of previous transaction outputs that\n" 
  714                "this transaction depends on but may not yet be in the block chain.\n",
 
  741            "       \"ALL|ANYONECANPAY\"\n" 
  742            "       \"NONE|ANYONECANPAY\"\n" 
  743            "       \"SINGLE|ANYONECANPAY\"\n" 
  769                    HelpExampleCli(
"signrawtransactionwithkey", 
"\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"")
 
  770            + 
HelpExampleRpc(
"signrawtransactionwithkey", 
"\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"")
 
  774    RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, 
true);
 
  777    if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
 
  783    for (
unsigned int idx = 0; idx < keys.
size(); ++idx) {
 
  793    std::map<COutPoint, Coin> coins;
 
  813                "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n" 
  814                "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n" 
  815                "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n" 
  816                "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n" 
  817                "\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n" 
  818                "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
 
  822                        "Reject transactions whose fee rate is higher than the specified value, expressed in " + 
CURRENCY_UNIT +
 
  823                            "/kvB.\nSet to 0 to accept any fee rate.\n"},
 
  829            "\nCreate a transaction\n" 
  830            + 
HelpExampleCli(
"createrawtransaction", 
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
 
  831            "Sign the transaction, and get back the hex\n" 
  833            "\nSend the transaction (signed hex)\n" 
  835            "\nAs a JSON-RPC call\n" 
  846    if (!
DecodeHexTx(mtx, request.params[0].get_str())) {
 
  851    const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
 
  856    CAmount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
 
  858    std::string err_string;
 
  866    return tx->GetHash().GetHex();
 
  874                "\nReturns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n" 
  875                "\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" 
  876                "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n" 
  878                "\nThis checks if transactions violate the consensus or policy rules.\n" 
  879                "\nSee sendrawtransaction call.\n",
 
  887                     "Reject transactions whose fee rate is higher than the specified value, expressed in " + 
CURRENCY_UNIT + 
"/kvB\n"},
 
  890                    RPCResult::Type::ARR, 
"", 
"The result of the mempool acceptance test for each raw transaction in the input array.\n" 
  891                        "Returns results for each transaction in the same order they were passed in.\n" 
  892                        "Transactions that cannot be fully validated due to failures in other transactions will not contain an 'allowed' result.\n",
 
  898                            {
RPCResult::Type::STR, 
"package-error",  
true, 
"Package validation error, if any (only possible if rawtxs had more than 1 transaction)."},
 
  899                            {
RPCResult::Type::BOOL, 
"allowed",  
true, 
"Whether this tx would be accepted to the mempool and pass client-specified maxfeerate. " 
  900                                                               "If not present, the tx was not fully validated due to a failure in another tx in the list."},
 
  901                            {
RPCResult::Type::NUM, 
"vsize",  
true, 
"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)"},
 
  906                            {
RPCResult::Type::STR, 
"reject-reason",  
true, 
"Rejection string (only present when 'allowed' is false)"},
 
  911            "\nCreate a transaction\n" 
  912            + 
HelpExampleCli(
"createrawtransaction", 
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
 
  913            "Sign the transaction, and get back the hex\n" 
  915            "\nTest acceptance of the transaction (signed hex)\n" 
  917            "\nAs a JSON-RPC call\n" 
  932    const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
 
  936    std::vector<CTransactionRef> txns;
 
  937    txns.reserve(raw_transactions.
size());
 
  938    for (
const auto& rawtx : raw_transactions.
getValues()) {
 
  942                               "TX decode failed: " + rawtx.get_str() + 
" Make sure the tx has at least one input.");
 
  962    bool exit_early{
false};
 
  963    for (
const auto& tx : txns) {
 
  965        result_inner.
pushKV(
"txid", tx->GetHash().GetHex());
 
  966        result_inner.
pushKV(
"wtxid", tx->GetWitnessHash().GetHex());
 
  970        auto it = package_result.
m_tx_results.find(tx->GetWitnessHash());
 
  971        if (exit_early || it == package_result.
m_tx_results.end()) {
 
  976        const auto& tx_result = it->second;
 
  978            const CAmount fee = tx_result.m_base_fees.value();
 
  981            const CAmount max_raw_tx_fee = max_raw_tx_fee_rate.
GetFee(virtual_size);
 
  982            if (max_raw_tx_fee && fee > max_raw_tx_fee) {
 
  983                result_inner.
pushKV(
"allowed", 
false);
 
  984                result_inner.
pushKV(
"reject-reason", 
"max-fee-exceeded");
 
  989                result_inner.
pushKV(
"allowed", 
true);
 
  990                result_inner.
pushKV(
"vsize", virtual_size);
 
  993                result_inner.
pushKV(
"fees", fees);
 
  996            result_inner.
pushKV(
"allowed", 
false);
 
  999                result_inner.
pushKV(
"reject-reason", 
"missing-inputs");
 
 1014                "\nReturn a JSON object representing the serialized, base64-encoded partially signed Bitcoin transaction.\n",
 
 1033                                {
RPCResult::Type::OBJ, 
"non_witness_utxo",  
true, 
"Decoded network transaction for non-witness UTXOs",
 
 1045                                        {
RPCResult::Type::STR, 
"address",  
true, 
"The Bitcoin address (only if a well-defined address exists)"},
 
 1142    result.
pushKV(
"tx", tx_univ);
 
 1146    for (
auto entry : psbtx.
unknown) {
 
 1149    result.
pushKV(
"unknown", unknowns);
 
 1153    bool have_all_utxos = 
true;
 
 1155    for (
unsigned int i = 0; i < psbtx.
inputs.size(); ++i) {
 
 1159        bool have_a_utxo = 
false;
 
 1169            out.
pushKV(
"scriptPubKey", o);
 
 1171            in.
pushKV(
"witness_utxo", out);
 
 1180            in.
pushKV(
"non_witness_utxo", non_wit);
 
 1186                total_in += txout.
nValue;
 
 1189                have_all_utxos = 
false;
 
 1192            have_all_utxos = 
false;
 
 1201            in.
pushKV(
"partial_signatures", partial_sigs);
 
 1213            in.
pushKV(
"redeem_script", r);
 
 1218            in.
pushKV(
"witness_script", r);
 
 1232            in.
pushKV(
"bip32_derivs", keypaths);
 
 1240            in.
pushKV(
"final_scriptSig", scriptsig);
 
 1247            in.
pushKV(
"final_scriptwitness", txinwitness);
 
 1251        if (input.
unknown.size() > 0) {
 
 1253            for (
auto entry : input.
unknown) {
 
 1256            in.
pushKV(
"unknown", unknowns);
 
 1261    result.
pushKV(
"inputs", inputs);
 
 1266    for (
unsigned int i = 0; i < psbtx.
outputs.size(); ++i) {
 
 1273            out.
pushKV(
"redeem_script", r);
 
 1278            out.
pushKV(
"witness_script", r);
 
 1291            out.
pushKV(
"bip32_derivs", keypaths);
 
 1295        if (output.
unknown.size() > 0) {
 
 1297            for (
auto entry : output.
unknown) {
 
 1300            out.
pushKV(
"unknown", unknowns);
 
 1307            output_value += psbtx.
tx->vout[i].nValue;
 
 1310            have_all_utxos = 
false;
 
 1313    result.
pushKV(
"outputs", outputs);
 
 1314    if (have_all_utxos) {
 
 1326                "\nCombine multiple partially signed Bitcoin transactions into one transaction.\n" 
 1327                "Implements the Combiner role.\n",
 
 1339                    HelpExampleCli(
"combinepsbt", R
"('["mybase64_1", "mybase64_2", "mybase64_3"]')") 
 1346    std::vector<PartiallySignedTransaction> psbtxs;
 
 1351    for (
unsigned int i = 0; i < txs.
size(); ++i) {
 
 1357        psbtxs.push_back(psbtx);
 
 1367    ssTx << merged_psbt;
 
 1376                "Finalize the inputs of a PSBT. If the transaction is fully signed, it will produce a\n" 
 1377                "network serialized transaction which can be broadcast with sendrawtransaction. Otherwise a PSBT will be\n" 
 1378                "created which has the final_scriptSig and final_scriptWitness fields filled for inputs that are complete.\n" 
 1379                "Implements the Finalizer and Extractor roles.\n",
 
 1383            "                             extract and return the complete transaction in normal network serialization instead of the PSBT."},
 
 1388                        {
RPCResult::Type::STR, 
"psbt",  
true, 
"The base64-encoded partially signed transaction if not extracted"},
 
 1398    RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, 
true);
 
 1407    bool extract = request.params[1].isNull() || (!request.params[1].isNull() && request.params[1].get_bool());
 
 1414    std::string result_str;
 
 1418        result_str = 
HexStr(ssTx);
 
 1419        result.
pushKV(
"hex", result_str);
 
 1423        result.
pushKV(
"psbt", result_str);
 
 1425    result.
pushKV(
"complete", complete);
 
 1435                "\nCreates a transaction in the Partially Signed Transaction format.\n" 
 1436                "Implements the Creator role.\n",
 
 1450                            "That is, each address can only appear once and there can only be one 'data' object.\n" 
 1451                            "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" 
 1452                            "                             accepted as second parameter.",
 
 1468                            "                             Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible."},
 
 1474                    HelpExampleCli(
"createpsbt", 
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
 
 1488    if (!request.params[3].isNull()) {
 
 1489        rbf = request.params[3].isTrue();
 
 1496    for (
unsigned int i = 0; i < rawTx.
vin.size(); ++i) {
 
 1499    for (
unsigned int i = 0; i < rawTx.
vout.size(); ++i) {
 
 1515                "\nConverts a network serialized transaction to a PSBT. This should be used only with createrawtransaction and fundrawtransaction\n" 
 1516                "createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
 
 1520                            "                              will continue. If false, RPC will fail if any signatures are present."},
 
 1522                        "If iswitness is not present, heuristic tests will be used in decoding.\n" 
 1523                        "If true, only witness deserialization will be tried.\n" 
 1524                        "If false, only non-witness deserialization will be tried.\n" 
 1525                        "This boolean should reflect whether the transaction has inputs\n" 
 1526                        "(e.g. fully valid, or on-chain transactions), if known by the caller." 
 1533                            "\nCreate a transaction\n" 
 1534                            + 
HelpExampleCli(
"createrawtransaction", 
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
 
 1535                            "\nConvert the transaction to a PSBT\n" 
 1540    RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, 
true);
 
 1544    bool permitsigdata = request.params[1].isNull() ? false : request.params[1].get_bool();
 
 1545    bool witness_specified = !request.params[2].isNull();
 
 1546    bool iswitness = witness_specified ? request.params[2].get_bool() : 
false;
 
 1547    const bool try_witness = witness_specified ? iswitness : 
true;
 
 1548    const bool try_no_witness = witness_specified ? !iswitness : 
true;
 
 1549    if (!
DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
 
 1565    for (
unsigned int i = 0; i < tx.
vin.size(); ++i) {
 
 1568    for (
unsigned int i = 0; i < tx.
vout.size(); ++i) {
 
 1584            "\nUpdates all segwit inputs and outputs in a PSBT with data from output descriptors, the UTXO set or the mempool.\n",
 
 1596                    RPCResult::Type::STR, 
"", 
"The base64-encoded partially signed transaction with inputs updated" 
 1603    RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR}, 
true);
 
 1614    if (!request.params[1].isNull()) {
 
 1615        auto descs = request.params[1].get_array();
 
 1616        for (
size_t i = 0; i < descs.size(); ++i) {
 
 1635        for (
const CTxIn& txin : psbtx.
tx->vin) {
 
 1644    for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
 
 1664    for (
unsigned int i = 0; i < psbtx.
tx->vout.size(); ++i) {
 
 1678            "\nJoins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs\n" 
 1679            "No input in any of the PSBTs can be in more than one of the PSBTs.\n",
 
 1697    std::vector<PartiallySignedTransaction> psbtxs;
 
 1700    if (txs.
size() <= 1) {
 
 1704    uint32_t best_version = 1;
 
 1705    uint32_t best_locktime = 0xffffffff;
 
 1706    for (
unsigned int i = 0; i < txs.
size(); ++i) {
 
 1712        psbtxs.push_back(psbtx);
 
 1714        if (
static_cast<uint32_t
>(psbtx.
tx->nVersion) > best_version) {
 
 1715            best_version = 
static_cast<uint32_t
>(psbtx.
tx->nVersion);
 
 1718        if (psbtx.
tx->nLockTime < best_locktime) {
 
 1719            best_locktime = psbtx.
tx->nLockTime;
 
 1726    merged_psbt.
tx->nVersion = 
static_cast<int32_t
>(best_version);
 
 1727    merged_psbt.
tx->nLockTime = best_locktime;
 
 1730    for (
auto& psbt : psbtxs) {
 
 1731        for (
unsigned int i = 0; i < psbt.tx->vin.size(); ++i) {
 
 1732            if (!merged_psbt.
AddInput(psbt.tx->vin[i], psbt.inputs[i])) {
 
 1736        for (
unsigned int i = 0; i < psbt.tx->vout.size(); ++i) {
 
 1737            merged_psbt.
AddOutput(psbt.tx->vout[i], psbt.outputs[i]);
 
 1739        merged_psbt.
unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
 
 1743    std::vector<int> input_indices(merged_psbt.
inputs.size());
 
 1744    std::iota(input_indices.begin(), input_indices.end(), 0);
 
 1745    std::vector<int> output_indices(merged_psbt.
outputs.size());
 
 1746    std::iota(output_indices.begin(), output_indices.end(), 0);
 
 1754    shuffled_psbt.
tx->nVersion = merged_psbt.
tx->nVersion;
 
 1755    shuffled_psbt.
tx->nLockTime = merged_psbt.
tx->nLockTime;
 
 1756    for (
int i : input_indices) {
 
 1759    for (
int i : output_indices) {
 
 1765    ssTx << shuffled_psbt;
 
 1774            "\nAnalyzes and provides information about the current status of a PSBT and its inputs\n",
 
 1787                            {
RPCResult::Type::OBJ, 
"missing",  
true, 
"Things that are missing that are required to complete this input",
 
 1791                                    {
RPCResult::Type::STR_HEX, 
"keyid", 
"Public key ID, hash160 of the public key, of a public key whose BIP 32 derivation path is missing"},
 
 1795                                    {
RPCResult::Type::STR_HEX, 
"keyid", 
"Public key ID, hash160 of the public key, of a public key whose signature is missing"},
 
 1800                            {
RPCResult::Type::STR, 
"next",  
true, 
"Role of the next person that this input needs to go to"},
 
 1803                    {
RPCResult::Type::NUM, 
"estimated_vsize",  
true, 
"Estimated vsize of the final signed transaction"},
 
 1804                    {
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"},
 
 1805                    {
RPCResult::Type::STR_AMOUNT, 
"fee",  
true, 
"The transaction fee paid. Shown only if all UTXO slots in the PSBT have been filled"},
 
 1828    for (
const auto& input : psbta.
inputs) {
 
 1832        input_univ.
pushKV(
"has_utxo", input.has_utxo);
 
 1833        input_univ.
pushKV(
"is_final", input.is_final);
 
 1836        if (!input.missing_pubkeys.empty()) {
 
 1838            for (
const CKeyID& pubkey : input.missing_pubkeys) {
 
 1841            missing.
pushKV(
"pubkeys", missing_pubkeys_univ);
 
 1843        if (!input.missing_redeem_script.IsNull()) {
 
 1844            missing.
pushKV(
"redeemscript", 
HexStr(input.missing_redeem_script));
 
 1846        if (!input.missing_witness_script.IsNull()) {
 
 1847            missing.
pushKV(
"witnessscript", 
HexStr(input.missing_witness_script));
 
 1849        if (!input.missing_sigs.empty()) {
 
 1851            for (
const CKeyID& pubkey : input.missing_sigs) {
 
 1854            missing.
pushKV(
"signatures", missing_sigs_univ);
 
 1856        if (!missing.
getKeys().empty()) {
 
 1857            input_univ.
pushKV(
"missing", missing);
 
 1861    if (!inputs_result.
empty()) result.
pushKV(
"inputs", inputs_result);
 
 1869    if (psbta.
fee != std::nullopt) {
 
 1873    if (!psbta.
error.empty()) {
 
 1909    for (
const auto& c : commands) {
 
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath)
Write HD keypaths as strings.
static CAmount AmountFromValue(const UniValue &value)
ChainstateManager & EnsureAnyChainman(const std::any &context)
NodeContext & EnsureAnyNodeContext(const std::any &context)
CTxMemPool & EnsureMemPool(const NodeContext &node)
ChainstateManager & EnsureChainman(const NodeContext &node)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
@ BLOCK_HAVE_DATA
full block available in blk*.dat
const CChainParams & Params()
Return the currently selected parameters.
CBlockIndex * LookupBlockIndex(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
int64_t GetBlockTime() const
unsigned int nTx
Number of transactions in this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
uint32_t nStatus
Verification status of this block.
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.
CChainState stores and provides an API to update our local knowledge of the current best chain.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances.
CChain m_chain
The current chain of blockheaders we consult and build on.
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: CAmount / kB.
CAmount GetFee(uint32_t num_bytes) const
Return the fee in satoshis for the given size in bytes.
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
A reference to a CKey: the Hash160 of its serialized public key.
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
CBlockHeader header
Public only for unit testing.
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
unsigned int GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
An encapsulated public key.
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.
CScriptWitness scriptWitness
Only serialized through CTransaction.
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.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
CChainState & ActiveChainstate() const
The most-work chain.
CChain & ActiveChain() const
CTxOut out
unspent transaction output
bool IsSpent() const
Either this coin never existed (see e.g.
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKey(const CKey &key)
A signature creator for transactions.
const std::string & get_str() const
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
bool push_back(const UniValue &val)
const UniValue & get_array() const
bool pushKV(const std::string &key, const UniValue &val)
std::string GetRejectReason() const
std::string GetHex() const
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
std::string SighashToStr(unsigned char sighash_type)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool include_hex, bool include_address=true)
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, bool include_hex=true, int serialize_flags=0, const CTxUndo *txundo=nullptr, TxVerbosity verbosity=TxVerbosity::SHOW_DETAILS)
void ScriptToUniv(const CScript &script, UniValue &out)
UniValue ValueFromAmount(const CAmount amount)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &hex_tx, bool try_no_witness=false, bool try_witness=true)
static uint32_t ReadBE32(const unsigned char *ptr)
const std::string CURRENCY_UNIT
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
std::string EncodeDestination(const CTxDestination &dest)
CKey DecodeSecret(const std::string &str)
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
Provides helpful miscellaneous information about where a PSBT is in the signing workflow.
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.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, const Consensus::Params &consensusParams, uint256 &hashBlock)
Return transaction with a given hash.
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 nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
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...
static CTransactionRef MakeTransactionRef(Tx &&txIn)
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(PSBTRole role)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
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.
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
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...
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 utxoupdatepsbt()
static std::string GetAllOutputTypes()
static RPCHelpMan gettxoutproof()
static RPCHelpMan converttopsbt()
static RPCHelpMan analyzepsbt()
static RPCHelpMan decoderawtransaction()
static void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry, CChainState &active_chainstate)
static RPCHelpMan combinepsbt()
static RPCHelpMan decodepsbt()
static RPCHelpMan decodescript()
static RPCHelpMan createpsbt()
static RPCHelpMan joinpsbts()
static RPCHelpMan combinerawtransaction()
static RPCHelpMan testmempoolaccept()
static RPCHelpMan verifytxoutproof()
static RPCHelpMan signrawtransactionwithkey()
static RPCHelpMan createrawtransaction()
static RPCHelpMan finalizepsbt()
void RegisterRawTransactionRPCCommands(CRPCTable &t)
Register raw transaction RPC commands.
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 UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, bool rbf)
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.
@ 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< unsigned char > ParseHexV(const UniValue &v, std::string strName)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
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 ...
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
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()
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)
bool IsSegWitOutput(const SigningProvider &provider, const CScript &script)
Check whether a scriptPubKey is known to be segwit.
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
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
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 unsigned char > input)
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< std::vector< unsigned char > > stack
NodeContext struct containing references to chain state and connection state.
Holds the results of AnalyzePSBT (miscellaneous information about a PSBT)
std::optional< size_t > estimated_vsize
Estimated weight of the transaction.
std::optional< CAmount > fee
Amount of fee being paid by the transaction.
std::vector< PSBTInputAnalysis > inputs
More information about the individual inputs of the transaction.
std::string error
Error message.
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.
A structure for PSBTs which contains per output information.
std::map< CPubKey, KeyOriginInfo > hd_keypaths
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Validation result for package mempool acceptance.
std::map< const uint256, const MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
const PackageValidationState m_state
A version of CTransaction with the PSBT format.
std::map< std::vector< unsigned char >, std::vector< unsigned char > > 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. to define multiple addresses; as opposed to e....
@ 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)
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
@ 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)
#define AssertLockNotHeld(cs)
bool error(const char *fmt, const Args &... args)
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
const UniValue & find_value(const UniValue &obj, const std::string &name)
PackageMempoolAcceptResult ProcessNewPackage(CChainState &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Atomically test acceptance of a package.
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.
static const int PROTOCOL_VERSION
network protocol versioning