LCOV - code coverage report
Current view: top level - src/wallet - walletutil.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 0.0 % 49 0
Test Date: 2024-11-04 04:15:01 Functions: 0.0 % 4 0
Branches: 0.0 % 82 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2017-2022 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 <wallet/walletutil.h>
       6                 :             : 
       7                 :             : #include <chainparams.h>
       8                 :             : #include <common/args.h>
       9                 :             : #include <key_io.h>
      10                 :             : #include <logging.h>
      11                 :             : 
      12                 :             : namespace wallet {
      13                 :           0 : fs::path GetWalletDir()
      14                 :             : {
      15                 :           0 :     fs::path path;
      16                 :             : 
      17   [ #  #  #  #  :           0 :     if (gArgs.IsArgSet("-walletdir")) {
                   #  # ]
      18   [ #  #  #  # ]:           0 :         path = gArgs.GetPathArg("-walletdir");
      19   [ #  #  #  # ]:           0 :         if (!fs::is_directory(path)) {
      20                 :             :             // If the path specified doesn't exist, we return the deliberately
      21                 :             :             // invalid empty string.
      22         [ #  # ]:           0 :             path = "";
      23                 :             :         }
      24                 :             :     } else {
      25         [ #  # ]:           0 :         path = gArgs.GetDataDirNet();
      26                 :             :         // If a wallets directory exists, use that, otherwise default to GetDataDir
      27   [ #  #  #  #  :           0 :         if (fs::is_directory(path / "wallets")) {
             #  #  #  # ]
      28         [ #  # ]:           0 :             path /= "wallets";
      29                 :             :         }
      30                 :             :     }
      31                 :             : 
      32                 :           0 :     return path;
      33                 :           0 : }
      34                 :             : 
      35                 :           0 : bool IsFeatureSupported(int wallet_version, int feature_version)
      36                 :             : {
      37                 :           0 :     return wallet_version >= feature_version;
      38                 :             : }
      39                 :             : 
      40                 :           0 : WalletFeature GetClosestWalletFeature(int version)
      41                 :             : {
      42                 :           0 :     static constexpr std::array wallet_features{FEATURE_LATEST, FEATURE_PRE_SPLIT_KEYPOOL, FEATURE_NO_DEFAULT_KEY, FEATURE_HD_SPLIT, FEATURE_HD, FEATURE_COMPRPUBKEY, FEATURE_WALLETCRYPT, FEATURE_BASE};
      43         [ #  # ]:           0 :     for (const WalletFeature& wf : wallet_features) {
      44         [ #  # ]:           0 :         if (version >= wf) return wf;
      45                 :             :     }
      46                 :             :     return static_cast<WalletFeature>(0);
      47                 :             : }
      48                 :             : 
      49                 :           0 : WalletDescriptor GenerateWalletDescriptor(const CExtPubKey& master_key, const OutputType& addr_type, bool internal)
      50                 :             : {
      51                 :           0 :     int64_t creation_time = GetTime();
      52                 :             : 
      53                 :           0 :     std::string xpub = EncodeExtPubKey(master_key);
      54                 :             : 
      55                 :             :     // Build descriptor string
      56         [ #  # ]:           0 :     std::string desc_prefix;
      57         [ #  # ]:           0 :     std::string desc_suffix = "/*)";
      58   [ #  #  #  #  :           0 :     switch (addr_type) {
                   #  # ]
      59                 :           0 :     case OutputType::LEGACY: {
      60         [ #  # ]:           0 :         desc_prefix = "pkh(" + xpub + "/44h";
      61                 :           0 :         break;
      62                 :             :     }
      63                 :           0 :     case OutputType::P2SH_SEGWIT: {
      64         [ #  # ]:           0 :         desc_prefix = "sh(wpkh(" + xpub + "/49h";
      65         [ #  # ]:           0 :         desc_suffix += ")";
      66                 :             :         break;
      67                 :             :     }
      68                 :           0 :     case OutputType::BECH32: {
      69         [ #  # ]:           0 :         desc_prefix = "wpkh(" + xpub + "/84h";
      70                 :           0 :         break;
      71                 :             :     }
      72                 :           0 :     case OutputType::BECH32M: {
      73         [ #  # ]:           0 :         desc_prefix = "tr(" + xpub + "/86h";
      74                 :           0 :         break;
      75                 :             :     }
      76                 :           0 :     case OutputType::UNKNOWN: {
      77                 :             :         // We should never have a DescriptorScriptPubKeyMan for an UNKNOWN OutputType,
      78                 :             :         // so if we get to this point something is wrong
      79                 :           0 :         assert(false);
      80                 :             :     }
      81                 :             :     } // no default case, so the compiler can warn about missing cases
      82         [ #  # ]:           0 :     assert(!desc_prefix.empty());
      83                 :             : 
      84                 :             :     // Mainnet derives at 0', testnet and regtest derive at 1'
      85   [ #  #  #  # ]:           0 :     if (Params().IsTestChain()) {
      86         [ #  # ]:           0 :         desc_prefix += "/1h";
      87                 :             :     } else {
      88         [ #  # ]:           0 :         desc_prefix += "/0h";
      89                 :             :     }
      90                 :             : 
      91   [ #  #  #  # ]:           0 :     std::string internal_path = internal ? "/1" : "/0";
      92   [ #  #  #  #  :           0 :     std::string desc_str = desc_prefix + "/0h" + internal_path + desc_suffix;
                   #  # ]
      93                 :             : 
      94                 :             :     // Make the descriptor
      95                 :           0 :     FlatSigningProvider keys;
      96         [ #  # ]:           0 :     std::string error;
      97         [ #  # ]:           0 :     std::vector<std::unique_ptr<Descriptor>> desc = Parse(desc_str, keys, error, false);
      98   [ #  #  #  #  :           0 :     WalletDescriptor w_desc(std::move(desc.at(0)), creation_time, 0, 0, 0);
                   #  # ]
      99                 :           0 :     return w_desc;
     100                 :           0 : }
     101                 :             : 
     102                 :             : } // namespace wallet
        

Generated by: LCOV version 2.0-1