LCOV - code coverage report
Current view: top level - src/wallet/rpc - backup.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 94.8 % 362 343
Test Date: 2025-05-10 04:59:59 Functions: 100.0 % 14 14
Branches: 51.5 % 1430 737

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

Generated by: LCOV version 2.0-1