LCOV - code coverage report
Current view: top level - src/coinjoin - interfaces.cpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 18 53 34.0 %
Date: 2026-06-25 07:23:51 Functions: 12 30 40.0 %

          Line data    Source code
       1             : // Copyright (c) 2024-2025 The Dash 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 <interfaces/coinjoin.h>
       6             : 
       7             : #include <coinjoin/client.h>
       8             : #include <coinjoin/options.h>
       9             : #include <coinjoin/walletman.h>
      10             : #include <node/context.h>
      11             : #include <util/check.h>
      12             : #include <walletinitinterface.h>
      13             : 
      14             : #include <memory>
      15             : #include <string>
      16             : 
      17             : using node::NodeContext;
      18             : using wallet::CWallet;
      19             : 
      20             : namespace coinjoin {
      21             : namespace {
      22             : 
      23             : class CoinJoinClientImpl : public interfaces::CoinJoin::Client
      24             : {
      25             :     CCoinJoinClientManager& m_clientman;
      26             : 
      27             : public:
      28           0 :     explicit CoinJoinClientImpl(CCoinJoinClientManager& clientman)
      29           0 :         : m_clientman(clientman) {}
      30             : 
      31           0 :     void resetCachedBlocks() override
      32             :     {
      33           0 :         m_clientman.nCachedNumBlocks = std::numeric_limits<int>::max();
      34           0 :     }
      35           0 :     void resetPool() override
      36             :     {
      37           0 :         m_clientman.ResetPool();
      38           0 :     }
      39           0 :     void disableAutobackups() override
      40             :     {
      41           0 :         m_clientman.fCreateAutoBackups = false;
      42           0 :     }
      43           0 :     int getCachedBlocks() override
      44             :     {
      45           0 :         return m_clientman.nCachedNumBlocks;
      46             :     }
      47           0 :     void getJsonInfo(UniValue& obj) override
      48             :     {
      49           0 :         return m_clientman.GetJsonInfo(obj);
      50             :     }
      51           0 :     std::string getSessionDenoms() override
      52             :     {
      53           0 :         return m_clientman.GetSessionDenoms();
      54             :     }
      55           0 :     std::vector<std::string> getSessionStatuses() override
      56             :     {
      57           0 :         return m_clientman.GetStatuses();
      58             :     }
      59           0 :     void setCachedBlocks(int nCachedBlocks) override
      60             :     {
      61           0 :        m_clientman.nCachedNumBlocks = nCachedBlocks;
      62           0 :     }
      63           0 :     bool isMixing() override
      64             :     {
      65           0 :         return m_clientman.IsMixing();
      66             :     }
      67           0 :     bool startMixing() override
      68             :     {
      69           0 :         return m_clientman.StartMixing();
      70             :     }
      71           0 :     void stopMixing() override
      72             :     {
      73           0 :         m_clientman.StopMixing();
      74           0 :     }
      75             : };
      76             : 
      77             : class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader
      78             : {
      79             : private:
      80          26 :     CJWalletManager& manager()
      81             :     {
      82          26 :         return *Assert(m_node.cj_walletman);
      83             :     }
      84             : 
      85          26 :     interfaces::WalletLoader& wallet_loader()
      86             :     {
      87          26 :         return *Assert(m_node.wallet_loader);
      88             :     }
      89             : 
      90             : public:
      91         398 :     explicit CoinJoinLoaderImpl(NodeContext& node) :
      92         199 :         m_node(node)
      93         398 :     {
      94             :         // Enablement will be re-evaluated when a wallet is added or removed
      95         199 :         CCoinJoinClientOptions::SetEnabled(false);
      96         398 :     }
      97             : 
      98          15 :     void AddWallet(const std::shared_ptr<CWallet>& wallet) override
      99             :     {
     100          15 :         manager().addWallet(wallet);
     101          15 :         g_wallet_init_interface.InitCoinJoinSettings(*this, wallet_loader());
     102          15 :     }
     103          11 :     void RemoveWallet(const std::string& name) override
     104             :     {
     105          11 :         manager().removeWallet(name);
     106          11 :         g_wallet_init_interface.InitCoinJoinSettings(*this, wallet_loader());
     107          11 :     }
     108           0 :     void FlushWallet(const std::string& name) override
     109             :     {
     110           0 :         manager().flushWallet(name);
     111           0 :     }
     112           0 :     std::unique_ptr<interfaces::CoinJoin::Client> GetClient(const std::string& name) override
     113             :     {
     114           0 :         auto clientman = manager().getClient(name);
     115           0 :         return clientman ? std::make_unique<CoinJoinClientImpl>(*clientman) : nullptr;
     116             :     }
     117             : 
     118             :     NodeContext& m_node;
     119             : };
     120             : 
     121             : } // namespace
     122             : } // namespace coinjoin
     123             : 
     124             : namespace interfaces {
     125         199 : std::unique_ptr<CoinJoin::Loader> MakeCoinJoinLoader(NodeContext& node) { return std::make_unique<coinjoin::CoinJoinLoaderImpl>(node); }
     126             : } // namespace interfaces

Generated by: LCOV version 1.16