LCOV - code coverage report
Current view: top level - src/wallet/rpc - backup.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 95.5 % 355 339
Test Date: 2025-07-01 05:14:16 Functions: 100.0 % 14 14
Branches: 52.1 % 1410 734

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2009-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <chain.h>
       6                 :             : #include <clientversion.h>
       7                 :             : #include <core_io.h>
       8                 :             : #include <hash.h>
       9                 :             : #include <interfaces/chain.h>
      10                 :             : #include <key_io.h>
      11                 :             : #include <merkleblock.h>
      12                 :             : #include <rpc/util.h>
      13                 :             : #include <script/descriptor.h>
      14                 :             : #include <script/script.h>
      15                 :             : #include <script/solver.h>
      16                 :             : #include <sync.h>
      17                 :             : #include <uint256.h>
      18                 :             : #include <util/bip32.h>
      19                 :             : #include <util/fs.h>
      20                 :             : #include <util/time.h>
      21                 :             : #include <util/translation.h>
      22                 :             : #include <wallet/rpc/util.h>
      23                 :             : #include <wallet/wallet.h>
      24                 :             : 
      25                 :             : #include <cstdint>
      26                 :             : #include <fstream>
      27                 :             : #include <tuple>
      28                 :             : #include <string>
      29                 :             : 
      30                 :             : #include <univalue.h>
      31                 :             : 
      32                 :             : 
      33                 :             : 
      34                 :             : using interfaces::FoundBlock;
      35                 :             : 
      36                 :             : namespace wallet {
      37                 :         791 : RPCHelpMan importprunedfunds()
      38                 :             : {
      39                 :         791 :     return RPCHelpMan{
      40                 :             :         "importprunedfunds",
      41                 :             :         "Imports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n",
      42                 :             :                 {
      43         [ +  - ]:         791 :                     {"rawtransaction", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A raw transaction in hex funding an already-existing address in wallet"},
      44         [ +  - ]:         791 :                     {"txoutproof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex output from gettxoutproof that contains the transaction"},
      45                 :             :                 },
      46   [ +  -  +  -  :        1582 :                 RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
      47   [ +  -  +  - ]:        2373 :                 RPCExamples{""},
      48                 :           7 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      49                 :             : {
      50                 :           7 :     std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
      51         [ -  + ]:           7 :     if (!pwallet) return UniValue::VNULL;
      52                 :             : 
      53         [ +  - ]:           7 :     CMutableTransaction tx;
      54   [ +  -  +  -  :           7 :     if (!DecodeHexTx(tx, request.params[0].get_str())) {
             +  -  +  + ]
      55   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
      56                 :             :     }
      57                 :             : 
      58   [ +  -  +  -  :           6 :     DataStream ssMB{ParseHexV(request.params[1], "proof")};
                   +  - ]
      59         [ +  - ]:           6 :     CMerkleBlock merkleBlock;
      60         [ +  - ]:           6 :     ssMB >> merkleBlock;
      61                 :             : 
      62                 :             :     //Search partial merkle tree in proof for our transaction and index in valid block
      63                 :           6 :     std::vector<uint256> vMatch;
      64                 :           6 :     std::vector<unsigned int> vIndex;
      65   [ +  -  +  + ]:           6 :     if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot) {
      66   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Something wrong with merkleblock");
      67                 :             :     }
      68                 :             : 
      69         [ +  - ]:           5 :     LOCK(pwallet->cs_wallet);
      70                 :           5 :     int height;
      71   [ +  -  +  -  :           5 :     if (!pwallet->chain().findAncestorByHash(pwallet->GetLastBlockHash(), merkleBlock.header.GetHash(), FoundBlock().height(height))) {
                   +  + ]
      72   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
      73                 :             :     }
      74                 :             : 
      75                 :           4 :     std::vector<uint256>::const_iterator it;
      76   [ +  -  +  + ]:           4 :     if ((it = std::find(vMatch.begin(), vMatch.end(), tx.GetHash())) == vMatch.end()) {
      77   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction given doesn't exist in proof");
      78                 :             :     }
      79                 :             : 
      80         [ +  - ]:           3 :     unsigned int txnIndex = vIndex[it - vMatch.begin()];
      81                 :             : 
      82         [ +  - ]:           3 :     CTransactionRef tx_ref = MakeTransactionRef(tx);
      83   [ +  -  +  + ]:           3 :     if (pwallet->IsMine(*tx_ref)) {
      84   [ +  -  +  - ]:           4 :         pwallet->AddToWallet(std::move(tx_ref), TxStateConfirmed{merkleBlock.header.GetHash(), height, static_cast<int>(txnIndex)});
      85         [ -  + ]:           2 :         return UniValue::VNULL;
      86                 :             :     }
      87                 :             : 
      88   [ +  -  +  - ]:           2 :     throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No addresses in wallet correspond to included transaction");
      89         [ +  - ]:          29 : },
      90   [ +  -  +  -  :        9492 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  -  
                      - ]
      91   [ +  -  +  -  :        3955 : }
             +  -  -  - ]
      92                 :             : 
      93                 :         787 : RPCHelpMan removeprunedfunds()
      94                 :             : {
      95                 :         787 :     return RPCHelpMan{
      96                 :             :         "removeprunedfunds",
      97                 :             :         "Deletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n",
      98                 :             :                 {
      99         [ +  - ]:         787 :                     {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"},
     100                 :             :                 },
     101   [ +  -  +  -  :        1574 :                 RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
     102                 :         787 :                 RPCExamples{
     103   [ +  -  +  -  :        1574 :                     HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") +
                   +  - ]
     104                 :         787 :             "\nAs a JSON-RPC call\n"
     105   [ +  -  +  -  :        3148 :             + HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"")
             +  -  +  - ]
     106         [ +  - ]:         787 :                 },
     107                 :           3 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     108                 :             : {
     109                 :           3 :     std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
     110         [ -  + ]:           3 :     if (!pwallet) return UniValue::VNULL;
     111                 :             : 
     112         [ +  - ]:           3 :     LOCK(pwallet->cs_wallet);
     113                 :             : 
     114   [ +  -  +  - ]:           3 :     Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
     115                 :           3 :     std::vector<Txid> vHash;
     116         [ +  - ]:           3 :     vHash.push_back(hash);
     117   [ +  -  +  + ]:           3 :     if (auto res = pwallet->RemoveTxs(vHash); !res) {
     118   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(res).original);
     119                 :           1 :     }
     120                 :             : 
     121                 :           2 :     return UniValue::VNULL;
     122         [ +  - ]:           8 : },
     123   [ +  -  +  -  :        7083 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
     124   [ +  -  +  - ]:        2361 : }
     125                 :             : 
     126                 :         639 : static int64_t GetImportTimestamp(const UniValue& data, int64_t now)
     127                 :             : {
     128         [ +  - ]:        1278 :     if (data.exists("timestamp")) {
     129         [ +  - ]:         639 :         const UniValue& timestamp = data["timestamp"];
     130         [ +  + ]:         639 :         if (timestamp.isNum()) {
     131                 :         198 :             return timestamp.getInt<int64_t>();
     132   [ +  -  -  + ]:         441 :         } else if (timestamp.isStr() && timestamp.get_str() == "now") {
     133                 :             :             return now;
     134                 :             :         }
     135   [ #  #  #  #  :           0 :         throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected number or \"now\" timestamp value for key. got type %s", uvTypeName(timestamp.type())));
                   #  # ]
     136                 :             :     }
     137   [ #  #  #  # ]:           0 :     throw JSONRPCError(RPC_TYPE_ERROR, "Missing required timestamp field for key");
     138                 :             : }
     139                 :             : 
     140                 :         637 : static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
     141                 :             : {
     142                 :         637 :     UniValue warnings(UniValue::VARR);
     143                 :         637 :     UniValue result(UniValue::VOBJ);
     144                 :             : 
     145                 :         637 :     try {
     146   [ +  -  +  + ]:        1274 :         if (!data.exists("desc")) {
     147   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Descriptor not found.");
     148                 :             :         }
     149                 :             : 
     150   [ +  -  +  -  :         636 :         const std::string& descriptor = data["desc"].get_str();
                   +  - ]
     151   [ +  -  +  +  :        1272 :         const bool active = data.exists("active") ? data["active"].get_bool() : false;
          +  -  +  -  +  
                      - ]
     152   [ +  -  +  -  :         637 :         const std::string label{LabelFromValue(data["label"])};
                   +  + ]
     153                 :             : 
     154                 :             :         // Parse descriptor string
     155                 :         635 :         FlatSigningProvider keys;
     156         [ +  - ]:         635 :         std::string error;
     157         [ +  - ]:         635 :         auto parsed_descs = Parse(descriptor, keys, error, /* require_checksum = */ true);
     158         [ +  + ]:         635 :         if (parsed_descs.empty()) {
     159         [ +  - ]:           8 :             throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error);
     160                 :             :         }
     161                 :         627 :         std::optional<bool> internal;
     162   [ +  -  +  + ]:        1254 :         if (data.exists("internal")) {
     163         [ +  + ]:         109 :             if (parsed_descs.size() > 1) {
     164   [ +  -  +  - ]:           2 :                 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot have multipath descriptor while also specifying \'internal\'");
     165                 :             :             }
     166   [ +  -  +  -  :         108 :             internal = data["internal"].get_bool();
                   +  - ]
     167                 :             :         }
     168                 :             : 
     169                 :             :         // Range check
     170                 :         626 :         int64_t range_start = 0, range_end = 1, next_index = 0;
     171   [ +  -  +  -  :         873 :         if (!parsed_descs.at(0)->IsRange() && data.exists("range")) {
          +  +  +  -  +  
             -  +  +  +  
                      + ]
     172   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Range should not be specified for an un-ranged descriptor");
     173   [ +  -  +  -  :         625 :         } else if (parsed_descs.at(0)->IsRange()) {
                   +  + ]
     174   [ +  -  +  + ]:         758 :             if (data.exists("range")) {
     175   [ +  -  +  -  :         108 :                 auto range = ParseDescriptorRange(data["range"]);
                   +  + ]
     176                 :          98 :                 range_start = range.first;
     177                 :          98 :                 range_end = range.second + 1; // Specified range end is inclusive, but we need range end as exclusive
     178                 :             :             } else {
     179   [ +  -  +  - ]:         276 :                 warnings.push_back("Range not given, using default keypool range");
     180                 :         276 :                 range_start = 0;
     181                 :         276 :                 range_end = wallet.m_keypool_size;
     182                 :             :             }
     183                 :         374 :             next_index = range_start;
     184                 :             : 
     185   [ +  -  +  + ]:         748 :             if (data.exists("next_index")) {
     186   [ +  -  +  -  :          63 :                 next_index = data["next_index"].getInt<int64_t>();
                   +  - ]
     187                 :             :                 // bound checks
     188         [ -  + ]:          63 :                 if (next_index < range_start || next_index >= range_end) {
     189   [ #  #  #  # ]:           0 :                     throw JSONRPCError(RPC_INVALID_PARAMETER, "next_index is out of range");
     190                 :             :                 }
     191                 :             :             }
     192                 :             :         }
     193                 :             : 
     194                 :             :         // Active descriptors must be ranged
     195   [ +  +  +  -  :         855 :         if (active && !parsed_descs.at(0)->IsRange()) {
                   +  + ]
     196   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Active descriptors must be ranged");
     197                 :             :         }
     198                 :             : 
     199                 :             :         // Multipath descriptors should not have a label
     200   [ +  +  +  -  :         621 :         if (parsed_descs.size() > 1 && data.exists("label")) {
          +  -  +  +  +  
                      + ]
     201   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Multipath descriptors should not have a label");
     202                 :             :         }
     203                 :             : 
     204                 :             :         // Ranged descriptors should not have a label
     205   [ +  -  +  -  :        1333 :         if (data.exists("range") && data.exists("label")) {
          +  +  +  -  +  
          -  +  +  +  +  
                   -  - ]
     206   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Ranged descriptors should not have a label");
     207                 :             :         }
     208                 :             : 
     209                 :             :         // Internal addresses should not have a label either
     210   [ +  +  +  -  :         725 :         if (internal && data.exists("label")) {
          +  -  +  +  +  
                      + ]
     211   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
     212                 :             :         }
     213                 :             : 
     214                 :             :         // Combo descriptor check
     215   [ +  +  +  -  :         849 :         if (active && !parsed_descs.at(0)->IsSingleType()) {
                   +  + ]
     216   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_WALLET_ERROR, "Combo descriptors cannot be set to active");
     217                 :             :         }
     218                 :             : 
     219                 :             :         // If the wallet disabled private keys, abort if private keys exist
     220   [ +  -  +  +  :         615 :         if (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !keys.keys.empty()) {
                   +  + ]
     221   [ +  -  +  - ]:           6 :             throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
     222                 :             :         }
     223                 :             : 
     224         [ +  + ]:        1220 :         for (size_t j = 0; j < parsed_descs.size(); ++j) {
     225         [ +  + ]:         613 :             auto parsed_desc = std::move(parsed_descs[j]);
     226   [ +  +  +  + ]:         613 :             bool desc_internal = internal.has_value() && internal.value();
     227         [ +  + ]:         613 :             if (parsed_descs.size() == 2) {
     228                 :           2 :                 desc_internal = j == 1;
     229         [ -  + ]:         611 :             } else if (parsed_descs.size() > 2) {
     230         [ #  # ]:           0 :                 CHECK_NONFATAL(!desc_internal);
     231                 :             :             }
     232                 :             :             // Need to ExpandPrivate to check if private keys are available for all pubkeys
     233                 :         613 :             FlatSigningProvider expand_keys;
     234                 :         613 :             std::vector<CScript> scripts;
     235   [ +  -  +  + ]:         613 :             if (!parsed_desc->Expand(0, keys, scripts, expand_keys)) {
     236   [ +  -  +  - ]:           2 :                 throw JSONRPCError(RPC_WALLET_ERROR, "Cannot expand descriptor. Probably because of hardened derivations without private keys provided");
     237                 :             :             }
     238         [ +  - ]:         612 :             parsed_desc->ExpandPrivate(0, keys, expand_keys);
     239                 :             : 
     240                 :             :             // Check if all private keys are provided
     241                 :         612 :             bool have_all_privkeys = !expand_keys.keys.empty();
     242         [ +  + ]:        1030 :             for (const auto& entry : expand_keys.origins) {
     243                 :         674 :                 const CKeyID& key_id = entry.first;
     244                 :         674 :                 CKey key;
     245   [ +  -  +  + ]:         674 :                 if (!expand_keys.GetKey(key_id, key)) {
     246                 :         256 :                     have_all_privkeys = false;
     247                 :         256 :                     break;
     248                 :             :                 }
     249                 :         674 :             }
     250                 :             : 
     251                 :             :             // If private keys are enabled, check some things.
     252   [ +  -  +  + ]:         612 :             if (!wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
     253         [ +  + ]:         439 :                if (keys.keys.empty()) {
     254   [ +  -  +  - ]:           2 :                     throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import descriptor without private keys to a wallet with private keys enabled");
     255                 :             :                }
     256         [ +  + ]:         438 :                if (!have_all_privkeys) {
     257   [ +  -  +  - ]:          88 :                    warnings.push_back("Not all private keys provided. Some wallet functionality may return unexpected errors");
     258                 :             :                }
     259                 :             :             }
     260                 :             : 
     261   [ +  -  +  - ]:         611 :             WalletDescriptor w_desc(std::move(parsed_desc), timestamp, range_start, range_end, next_index);
     262                 :             : 
     263                 :             :             // Add descriptor to the wallet
     264         [ +  - ]:         611 :             auto spk_manager_res = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal);
     265                 :             : 
     266         [ +  + ]:         611 :             if (!spk_manager_res) {
     267   [ +  -  +  -  :           9 :                 throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Could not add descriptor '%s': %s", descriptor, util::ErrorString(spk_manager_res).original));
                   +  - ]
     268                 :             :             }
     269                 :             : 
     270         [ +  + ]:         608 :             auto& spk_manager = spk_manager_res.value().get();
     271                 :             : 
     272                 :             :             // Set descriptor as active if necessary
     273         [ +  + ]:         608 :             if (active) {
     274   [ +  -  +  + ]:         230 :                 if (!w_desc.descriptor->GetOutputType()) {
     275   [ +  -  +  - ]:           1 :                     warnings.push_back("Unknown output type, cannot set descriptor to active.");
     276                 :             :                 } else {
     277   [ +  -  +  -  :         229 :                     wallet.AddActiveScriptPubKeyMan(spk_manager.GetID(), *w_desc.descriptor->GetOutputType(), desc_internal);
                   +  - ]
     278                 :             :                 }
     279                 :             :             } else {
     280   [ +  -  +  + ]:         378 :                 if (w_desc.descriptor->GetOutputType()) {
     281   [ +  -  +  -  :         210 :                     wallet.DeactivateScriptPubKeyMan(spk_manager.GetID(), *w_desc.descriptor->GetOutputType(), desc_internal);
                   +  - ]
     282                 :             :                 }
     283                 :             :             }
     284                 :         626 :         }
     285                 :             : 
     286   [ +  -  +  -  :        1214 :         result.pushKV("success", UniValue(true));
                   +  - ]
     287         [ -  + ]:         693 :     } catch (const UniValue& e) {
     288   [ +  -  +  -  :          60 :         result.pushKV("success", UniValue(false));
                   +  - ]
     289   [ +  -  +  -  :          60 :         result.pushKV("error", e);
                   +  - ]
     290                 :          30 :     }
     291         [ +  - ]:         637 :     PushWarnings(warnings, result);
     292                 :         637 :     return result;
     293                 :         637 : }
     294                 :             : 
     295                 :        1346 : RPCHelpMan importdescriptors()
     296                 :             : {
     297                 :        1346 :     return RPCHelpMan{
     298                 :             :         "importdescriptors",
     299                 :             :         "Import descriptors. This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being imported. Requires a new wallet backup.\n"
     300                 :             :         "When importing descriptors with multipath key expressions, if the multipath specifier contains exactly two elements, the descriptor produced from the second element will be imported as an internal descriptor.\n"
     301                 :             :             "\nNote: This call can take over an hour to complete if using an early timestamp; during that time, other rpc calls\n"
     302                 :             :             "may report that the imported keys, addresses or scripts exist but related transactions are still missing.\n"
     303                 :             :             "The rescan is significantly faster if block filters are available (using startup option \"-blockfilterindex=1\").\n",
     304                 :             :                 {
     305         [ +  - ]:        1346 :                     {"requests", RPCArg::Type::ARR, RPCArg::Optional::NO, "Data to be imported",
     306                 :             :                         {
     307         [ +  - ]:        1346 :                             {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
     308                 :             :                                 {
     309         [ +  - ]:        1346 :                                     {"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "Descriptor to import."},
     310         [ +  - ]:        2692 :                                     {"active", RPCArg::Type::BOOL, RPCArg::Default{false}, "Set this descriptor to be the active descriptor for the corresponding output type/externality"},
     311         [ +  - ]:        1346 :                                     {"range", RPCArg::Type::RANGE, RPCArg::Optional::OMITTED, "If a ranged descriptor is used, this specifies the end or the range (in the form [begin,end]) to import"},
     312         [ +  - ]:        1346 :                                     {"next_index", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "If a ranged descriptor is set to active, this specifies the next index to generate addresses from"},
     313         [ +  - ]:        2692 :                                     {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Time from which to start rescanning the blockchain for this descriptor, in " + UNIX_EPOCH_TIME + "\n"
     314                 :             :                                         "Use the string \"now\" to substitute the current synced blockchain time.\n"
     315                 :             :                                         "\"now\" can be specified to bypass scanning, for outputs which are known to never have been used, and\n"
     316                 :             :                                         "0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest timestamp\n"
     317                 :        1346 :                                         "of all descriptors being imported will be scanned as well as the mempool.",
     318         [ +  - ]:        2692 :                                         RPCArgOptions{.type_str={"timestamp | \"now\"", "integer / string"}}
     319                 :             :                                     },
     320         [ +  - ]:        2692 :                                     {"internal", RPCArg::Type::BOOL, RPCArg::Default{false}, "Whether matching outputs should be treated as not incoming payments (e.g. change)"},
     321         [ +  - ]:        2692 :                                     {"label", RPCArg::Type::STR, RPCArg::Default{""}, "Label to assign to the address, only allowed with internal=false. Disabled for ranged descriptors"},
     322                 :             :                                 },
     323                 :             :                             },
     324                 :             :                         },
     325   [ +  -  +  - ]:        1346 :                         RPCArgOptions{.oneline_description="requests"}},
     326                 :             :                 },
     327                 :           0 :                 RPCResult{
     328                 :             :                     RPCResult::Type::ARR, "", "Response is an array with the same size as the input that has the execution result",
     329                 :             :                     {
     330                 :             :                         {RPCResult::Type::OBJ, "", "",
     331                 :             :                         {
     332                 :             :                             {RPCResult::Type::BOOL, "success", ""},
     333                 :             :                             {RPCResult::Type::ARR, "warnings", /*optional=*/true, "",
     334                 :             :                             {
     335                 :             :                                 {RPCResult::Type::STR, "", ""},
     336                 :             :                             }},
     337                 :             :                             {RPCResult::Type::OBJ, "error", /*optional=*/true, "",
     338                 :             :                             {
     339                 :             :                                 {RPCResult::Type::ELISION, "", "JSONRPC error"},
     340                 :             :                             }},
     341                 :             :                         }},
     342                 :             :                     }
     343   [ +  -  +  -  :       14806 :                 },
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  +  +  +  
          +  +  +  -  -  
          -  -  -  -  -  
                      - ]
     344                 :        1346 :                 RPCExamples{
     345   [ +  -  +  -  :        2692 :                     HelpExampleCli("importdescriptors", "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, \"internal\": true }, "
                   +  - ]
     346                 :        1346 :                                           "{ \"desc\": \"<my descriptor 2>\", \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
     347   [ +  -  +  -  :        4038 :                     HelpExampleCli("importdescriptors", "'[{ \"desc\": \"<my descriptor>\", \"timestamp\":1455191478, \"active\": true, \"range\": [0,100], \"label\": \"<my bech32 wallet>\" }]'")
             +  -  +  - ]
     348         [ +  - ]:        1346 :                 },
     349                 :         562 :         [&](const RPCHelpMan& self, const JSONRPCRequest& main_request) -> UniValue
     350                 :             : {
     351                 :         562 :     std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(main_request);
     352         [ -  + ]:         562 :     if (!pwallet) return UniValue::VNULL;
     353         [ +  - ]:         562 :     CWallet& wallet{*pwallet};
     354                 :             : 
     355                 :             :     // Make sure the results are valid at least up to the most recent block
     356                 :             :     // the user could have gotten from another RPC command prior to now
     357         [ +  - ]:         562 :     wallet.BlockUntilSyncedToCurrentChain();
     358                 :             : 
     359                 :         562 :     WalletRescanReserver reserver(*pwallet);
     360         [ -  + ]:         562 :     if (!reserver.reserve(/*with_passphrase=*/true)) {
     361   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
     362                 :             :     }
     363                 :             : 
     364                 :             :     // Ensure that the wallet is not locked for the remainder of this RPC, as
     365                 :             :     // the passphrase is used to top up the keypool.
     366         [ +  - ]:         562 :     LOCK(pwallet->m_relock_mutex);
     367                 :             : 
     368         [ +  - ]:         562 :     const UniValue& requests = main_request.params[0];
     369                 :         562 :     const int64_t minimum_timestamp = 1;
     370                 :         562 :     int64_t now = 0;
     371                 :         562 :     int64_t lowest_timestamp = 0;
     372                 :         562 :     bool rescan = false;
     373                 :         562 :     UniValue response(UniValue::VARR);
     374                 :         562 :     {
     375         [ +  - ]:         562 :         LOCK(pwallet->cs_wallet);
     376         [ +  - ]:         562 :         EnsureWalletIsUnlocked(*pwallet);
     377                 :             : 
     378   [ +  -  +  - ]:         562 :         CHECK_NONFATAL(pwallet->chain().findBlock(pwallet->GetLastBlockHash(), FoundBlock().time(lowest_timestamp).mtpTime(now)));
     379                 :             : 
     380                 :             :         // Get all timestamps and extract the lowest timestamp
     381   [ +  -  +  + ]:        1199 :         for (const UniValue& request : requests.getValues()) {
     382                 :             :             // This throws an error if "timestamp" doesn't exist
     383   [ +  -  +  + ]:         637 :             const int64_t timestamp = std::max(GetImportTimestamp(request, now), minimum_timestamp);
     384         [ +  - ]:         637 :             const UniValue result = ProcessDescriptorImport(*pwallet, request, timestamp);
     385   [ +  -  +  - ]:         637 :             response.push_back(result);
     386                 :             : 
     387         [ +  + ]:         637 :             if (lowest_timestamp > timestamp ) {
     388                 :         421 :                 lowest_timestamp = timestamp;
     389                 :             :             }
     390                 :             : 
     391                 :             :             // If we know the chain tip, and at least one request was successful then allow rescan
     392   [ +  +  +  -  :        1199 :             if (!rescan && result["success"].get_bool()) {
          +  -  +  -  +  
             +  +  +  -  
                      - ]
     393                 :         532 :                 rescan = true;
     394                 :             :             }
     395                 :         637 :         }
     396         [ +  - ]:         562 :         pwallet->ConnectScriptPubKeyManNotifiers();
     397                 :           0 :     }
     398                 :             : 
     399                 :             :     // Rescan the blockchain using the lowest timestamp
     400         [ +  + ]:         562 :     if (rescan) {
     401         [ +  - ]:         532 :         int64_t scanned_time = pwallet->RescanFromTime(lowest_timestamp, reserver, /*update=*/true);
     402         [ +  - ]:         532 :         pwallet->ResubmitWalletTransactions(/*relay=*/false, /*force=*/true);
     403                 :             : 
     404         [ -  + ]:         532 :         if (pwallet->IsAbortingRescan()) {
     405   [ #  #  #  # ]:           0 :             throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");
     406                 :             :         }
     407                 :             : 
     408         [ +  + ]:         532 :         if (scanned_time > lowest_timestamp) {
     409   [ +  -  +  - ]:           1 :             std::vector<UniValue> results = response.getValues();
     410         [ +  - ]:           1 :             response.clear();
     411         [ +  - ]:           1 :             response.setArray();
     412                 :             : 
     413                 :             :             // Compose the response
     414         [ +  + ]:           2 :             for (unsigned int i = 0; i < requests.size(); ++i) {
     415   [ +  -  +  - ]:           1 :                 const UniValue& request = requests.getValues().at(i);
     416                 :             : 
     417                 :             :                 // If the descriptor timestamp is within the successfully scanned
     418                 :             :                 // range, or if the import result already has an error set, let
     419                 :             :                 // the result stand unmodified. Otherwise replace the result
     420                 :             :                 // with an error message.
     421   [ +  -  +  -  :           2 :                 if (scanned_time <= GetImportTimestamp(request, now) || results.at(i).exists("error")) {
          +  -  +  -  +  
          -  +  -  -  +  
                   -  - ]
     422   [ #  #  #  #  :           0 :                     response.push_back(results.at(i));
                   #  # ]
     423                 :             :                 } else {
     424                 :           1 :                     std::string error_msg{strprintf("Rescan failed for descriptor with timestamp %d. There "
     425                 :             :                             "was an error reading a block from time %d, which is after or within %d seconds "
     426                 :             :                             "of key creation, and could contain transactions pertaining to the desc. As a "
     427                 :             :                             "result, transactions and coins using this desc may not appear in the wallet.",
     428   [ +  -  +  - ]:           1 :                             GetImportTimestamp(request, now), scanned_time - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)};
     429   [ +  -  -  + ]:           1 :                     if (pwallet->chain().havePruned()) {
     430         [ #  # ]:           0 :                         error_msg += strprintf(" This error could be caused by pruning or data corruption "
     431                 :             :                                 "(see bitcoind log for details) and could be dealt with by downloading and "
     432                 :           0 :                                 "rescanning the relevant blocks (see -reindex option and rescanblockchain RPC).");
     433   [ +  -  +  - ]:           1 :                     } else if (pwallet->chain().hasAssumedValidChain()) {
     434         [ +  - ]:           2 :                         error_msg += strprintf(" This error is likely caused by an in-progress assumeutxo "
     435                 :             :                                 "background sync. Check logs or getchainstates RPC for assumeutxo background "
     436                 :           1 :                                 "sync progress and try again later.");
     437                 :             :                     } else {
     438         [ #  # ]:           0 :                         error_msg += strprintf(" This error could potentially caused by data corruption. If "
     439                 :           0 :                                 "the issue persists you may want to reindex (see -reindex option).");
     440                 :             :                     }
     441                 :             : 
     442                 :           1 :                     UniValue result = UniValue(UniValue::VOBJ);
     443   [ +  -  +  -  :           2 :                     result.pushKV("success", UniValue(false));
                   +  - ]
     444   [ +  -  +  -  :           2 :                     result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, error_msg));
                   +  - ]
     445         [ +  - ]:           1 :                     response.push_back(std::move(result));
     446                 :           1 :                 }
     447                 :             :             }
     448                 :           1 :         }
     449                 :             :     }
     450                 :             : 
     451                 :         562 :     return response;
     452         [ +  - ]:        1686 : },
     453   [ +  -  +  -  :       52494 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          +  +  +  +  +  
          -  -  -  -  -  
                      - ]
     454   [ +  -  +  -  :       32304 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             -  -  -  - ]
     455                 :             : 
     456                 :         837 : RPCHelpMan listdescriptors()
     457                 :             : {
     458                 :         837 :     return RPCHelpMan{
     459                 :             :         "listdescriptors",
     460                 :             :         "List all descriptors present in a wallet.\n",
     461                 :             :         {
     462         [ +  - ]:        1674 :             {"private", RPCArg::Type::BOOL, RPCArg::Default{false}, "Show private descriptors."}
     463                 :             :         },
     464                 :           0 :         RPCResult{RPCResult::Type::OBJ, "", "", {
     465                 :             :             {RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
     466                 :             :             {RPCResult::Type::ARR, "descriptors", "Array of descriptor objects (sorted by descriptor string representation)",
     467                 :             :             {
     468                 :             :                 {RPCResult::Type::OBJ, "", "", {
     469                 :             :                     {RPCResult::Type::STR, "desc", "Descriptor string representation"},
     470                 :             :                     {RPCResult::Type::NUM, "timestamp", "The creation time of the descriptor"},
     471                 :             :                     {RPCResult::Type::BOOL, "active", "Whether this descriptor is currently used to generate new addresses"},
     472                 :             :                     {RPCResult::Type::BOOL, "internal", /*optional=*/true, "True if this descriptor is used to generate change addresses. False if this descriptor is used to generate receiving addresses; defined only for active descriptors"},
     473                 :             :                     {RPCResult::Type::ARR_FIXED, "range", /*optional=*/true, "Defined only for ranged descriptors", {
     474                 :             :                         {RPCResult::Type::NUM, "", "Range start inclusive"},
     475                 :             :                         {RPCResult::Type::NUM, "", "Range end inclusive"},
     476                 :             :                     }},
     477                 :             :                     {RPCResult::Type::NUM, "next", /*optional=*/true, "Same as next_index field. Kept for compatibility reason."},
     478                 :             :                     {RPCResult::Type::NUM, "next_index", /*optional=*/true, "The next index to generate addresses from; defined only for ranged descriptors"},
     479                 :             :                 }},
     480                 :             :             }}
     481   [ +  -  +  -  :       14229 :         }},
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  +  +  +  
          +  +  +  +  -  
          -  -  -  -  -  
                   -  - ]
     482                 :         837 :         RPCExamples{
     483   [ +  -  +  -  :        1674 :             HelpExampleCli("listdescriptors", "") + HelpExampleRpc("listdescriptors", "")
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     484   [ +  -  +  -  :        3348 :             + HelpExampleCli("listdescriptors", "true") + HelpExampleRpc("listdescriptors", "true")
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     485         [ +  - ]:         837 :         },
     486                 :          53 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     487                 :             : {
     488         [ -  + ]:          53 :     const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
     489         [ -  + ]:          52 :     if (!wallet) return UniValue::VNULL;
     490                 :             : 
     491   [ +  -  +  +  :          52 :     const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
          +  -  +  -  +  
                      + ]
     492                 :          12 :     if (priv) {
     493         [ +  + ]:          12 :         EnsureWalletIsUnlocked(*wallet);
     494                 :             :     }
     495                 :             : 
     496         [ +  - ]:          51 :     LOCK(wallet->cs_wallet);
     497                 :             : 
     498         [ +  - ]:          51 :     const auto active_spk_mans = wallet->GetActiveScriptPubKeyMans();
     499                 :             : 
     500         [ -  - ]:         901 :     struct WalletDescInfo {
     501                 :             :         std::string descriptor;
     502                 :             :         uint64_t creation_time;
     503                 :             :         bool active;
     504                 :             :         std::optional<bool> internal;
     505                 :             :         std::optional<std::pair<int64_t,int64_t>> range;
     506                 :             :         int64_t next_index;
     507                 :             :     };
     508                 :             : 
     509                 :          51 :     std::vector<WalletDescInfo> wallet_descriptors;
     510   [ +  -  +  + ]:         354 :     for (const auto& spk_man : wallet->GetAllScriptPubKeyMans()) {
     511         [ +  - ]:         304 :         const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
     512         [ -  + ]:         304 :         if (!desc_spk_man) {
     513   [ #  #  #  # ]:           0 :             throw JSONRPCError(RPC_WALLET_ERROR, "Unexpected ScriptPubKey manager type.");
     514                 :             :         }
     515         [ +  - ]:         304 :         LOCK(desc_spk_man->cs_desc_man);
     516         [ +  - ]:         304 :         const auto& wallet_descriptor = desc_spk_man->GetWalletDescriptor();
     517         [ +  - ]:         304 :         std::string descriptor;
     518   [ +  -  +  + ]:         304 :         if (!desc_spk_man->GetDescriptorString(descriptor, priv)) {
     519   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_WALLET_ERROR, "Can't get descriptor string.");
     520                 :             :         }
     521         [ +  - ]:         303 :         const bool is_range = wallet_descriptor.descriptor->IsRange();
     522                 :         303 :         wallet_descriptors.push_back({
     523                 :             :             descriptor,
     524                 :         303 :             wallet_descriptor.creation_time,
     525                 :         606 :             active_spk_mans.count(desc_spk_man) != 0,
     526         [ +  - ]:         303 :             wallet->IsInternalScriptPubKeyMan(desc_spk_man),
     527         [ +  + ]:         303 :             is_range ? std::optional(std::make_pair(wallet_descriptor.range_start, wallet_descriptor.range_end)) : std::nullopt,
     528                 :         303 :             wallet_descriptor.next_index
     529                 :             :         });
     530         [ +  - ]:         609 :     }
     531                 :             : 
     532                 :          50 :     std::sort(wallet_descriptors.begin(), wallet_descriptors.end(), [](const auto& a, const auto& b) {
     533   [ -  -  -  -  :         807 :         return a.descriptor < b.descriptor;
          +  +  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
             -  -  -  +  
                      + ]
     534                 :             :     });
     535                 :             : 
     536                 :          50 :     UniValue descriptors(UniValue::VARR);
     537         [ +  + ]:         353 :     for (const WalletDescInfo& info : wallet_descriptors) {
     538                 :         303 :         UniValue spk(UniValue::VOBJ);
     539   [ +  -  +  -  :         606 :         spk.pushKV("desc", info.descriptor);
                   +  - ]
     540   [ +  -  +  -  :         606 :         spk.pushKV("timestamp", info.creation_time);
                   +  - ]
     541   [ +  -  +  -  :         606 :         spk.pushKV("active", info.active);
                   +  - ]
     542         [ +  + ]:         303 :         if (info.internal.has_value()) {
     543   [ +  -  +  -  :         514 :             spk.pushKV("internal", info.internal.value());
                   +  - ]
     544                 :             :         }
     545         [ +  + ]:         303 :         if (info.range.has_value()) {
     546                 :         272 :             UniValue range(UniValue::VARR);
     547   [ +  -  +  - ]:         272 :             range.push_back(info.range->first);
     548   [ +  -  +  - ]:         272 :             range.push_back(info.range->second - 1);
     549   [ +  -  +  - ]:         544 :             spk.pushKV("range", std::move(range));
     550   [ +  -  +  -  :         544 :             spk.pushKV("next", info.next_index);
                   +  - ]
     551   [ +  -  +  -  :         544 :             spk.pushKV("next_index", info.next_index);
                   +  - ]
     552                 :         272 :         }
     553         [ +  - ]:         303 :         descriptors.push_back(std::move(spk));
     554                 :         303 :     }
     555                 :             : 
     556                 :          50 :     UniValue response(UniValue::VOBJ);
     557   [ +  -  +  -  :         100 :     response.pushKV("wallet_name", wallet->GetName());
                   +  - ]
     558   [ +  -  +  - ]:         100 :     response.pushKV("descriptors", std::move(descriptors));
     559                 :             : 
     560                 :          50 :     return response;
     561   [ +  -  +  -  :         759 : },
             +  -  +  - ]
     562   [ +  -  +  -  :        9207 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
     563   [ +  -  +  -  :       13392 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  -  -  -  -  
                   -  - ]
     564                 :             : 
     565                 :         820 : RPCHelpMan backupwallet()
     566                 :             : {
     567                 :         820 :     return RPCHelpMan{
     568                 :             :         "backupwallet",
     569                 :             :         "Safely copies the current wallet file to the specified destination, which can either be a directory or a path with a filename.\n",
     570                 :             :                 {
     571         [ +  - ]:         820 :                     {"destination", RPCArg::Type::STR, RPCArg::Optional::NO, "The destination directory or file"},
     572                 :             :                 },
     573   [ +  -  +  -  :        1640 :                 RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
     574                 :         820 :                 RPCExamples{
     575   [ +  -  +  -  :        1640 :                     HelpExampleCli("backupwallet", "\"backup.dat\"")
                   +  - ]
     576   [ +  -  +  -  :        3280 :             + HelpExampleRpc("backupwallet", "\"backup.dat\"")
             +  -  +  - ]
     577         [ +  - ]:         820 :                 },
     578                 :          36 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     579                 :             : {
     580         [ -  + ]:          36 :     const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
     581         [ -  + ]:          36 :     if (!pwallet) return UniValue::VNULL;
     582                 :             : 
     583                 :             :     // Make sure the results are valid at least up to the most recent block
     584                 :             :     // the user could have gotten from another RPC command prior to now
     585         [ +  - ]:          36 :     pwallet->BlockUntilSyncedToCurrentChain();
     586                 :             : 
     587         [ +  - ]:          36 :     LOCK(pwallet->cs_wallet);
     588                 :             : 
     589   [ +  -  +  -  :          36 :     std::string strDest = request.params[0].get_str();
                   +  - ]
     590   [ +  -  +  + ]:          36 :     if (!pwallet->BackupWallet(strDest)) {
     591   [ +  -  +  - ]:           8 :         throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
     592                 :             :     }
     593                 :             : 
     594                 :          32 :     return UniValue::VNULL;
     595         [ +  - ]:         104 : },
     596   [ +  -  +  -  :        7380 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
     597   [ +  -  +  - ]:        2460 : }
     598                 :             : 
     599                 :             : 
     600                 :         810 : RPCHelpMan restorewallet()
     601                 :             : {
     602                 :         810 :     return RPCHelpMan{
     603                 :             :         "restorewallet",
     604                 :             :         "Restores and loads a wallet from backup.\n"
     605                 :             :         "\nThe rescan is significantly faster if block filters are available"
     606                 :             :         "\n(using startup option \"-blockfilterindex=1\").\n",
     607                 :             :         {
     608         [ +  - ]:         810 :             {"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, "The name that will be applied to the restored wallet"},
     609         [ +  - ]:         810 :             {"backup_file", RPCArg::Type::STR, RPCArg::Optional::NO, "The backup file that will be used to restore the wallet."},
     610         [ +  - ]:         810 :             {"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
     611                 :             :         },
     612                 :           0 :         RPCResult{
     613                 :             :             RPCResult::Type::OBJ, "", "",
     614                 :             :             {
     615                 :             :                 {RPCResult::Type::STR, "name", "The wallet name if restored successfully."},
     616                 :             :                 {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to restoring and loading the wallet.",
     617                 :             :                 {
     618                 :             :                     {RPCResult::Type::STR, "", ""},
     619                 :             :                 }},
     620                 :             :             }
     621   [ +  -  +  -  :        4860 :         },
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     622                 :         810 :         RPCExamples{
     623   [ +  -  +  -  :        1620 :             HelpExampleCli("restorewallet", "\"testwallet\" \"home\\backups\\backup-file.bak\"")
                   +  - ]
     624   [ +  -  +  -  :        3240 :             + HelpExampleRpc("restorewallet", "\"testwallet\" \"home\\backups\\backup-file.bak\"")
             +  -  +  - ]
     625   [ +  -  +  -  :        5670 :             + HelpExampleCliNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}})
          +  -  +  -  +  
                +  -  - ]
     626   [ +  -  +  -  :        5670 :             + HelpExampleRpcNamed("restorewallet", {{"wallet_name", "testwallet"}, {"backup_file", "home\\backups\\backup-file.bak\""}, {"load_on_startup", true}})
          +  -  +  -  +  
                +  -  - ]
     627         [ +  - ]:         810 :         },
     628                 :          26 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     629                 :             : {
     630                 :             : 
     631                 :          26 :     WalletContext& context = EnsureWalletContext(request.context);
     632                 :             : 
     633                 :          26 :     auto backup_file = fs::u8path(request.params[1].get_str());
     634                 :             : 
     635   [ +  -  +  -  :          26 :     std::string wallet_name = request.params[0].get_str();
                   +  - ]
     636                 :             : 
     637   [ +  -  +  -  :          26 :     std::optional<bool> load_on_start = request.params[2].isNull() ? std::nullopt : std::optional<bool>(request.params[2].get_bool());
             -  -  -  - ]
     638                 :             : 
     639                 :          26 :     DatabaseStatus status;
     640         [ +  - ]:          26 :     bilingual_str error;
     641                 :          26 :     std::vector<bilingual_str> warnings;
     642                 :             : 
     643         [ +  - ]:          26 :     const std::shared_ptr<CWallet> wallet = RestoreWallet(context, backup_file, wallet_name, load_on_start, status, error, warnings);
     644                 :             : 
     645   [ +  +  +  + ]:          52 :     HandleWalletError(wallet, status, error);
     646                 :             : 
     647                 :          14 :     UniValue obj(UniValue::VOBJ);
     648   [ +  -  +  -  :          28 :     obj.pushKV("name", wallet->GetName());
                   +  - ]
     649         [ +  - ]:          14 :     PushWarnings(warnings, obj);
     650                 :             : 
     651         [ +  - ]:          14 :     return obj;
     652                 :             : 
     653                 :          78 : },
     654   [ +  -  +  -  :       12150 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  +  -  
                      - ]
     655   [ +  -  +  -  :       10530 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
          -  -  -  -  -  
                   -  - ]
     656                 :             : } // namespace wallet
        

Generated by: LCOV version 2.0-1