Skip to content

Commit dc5152b

Browse files
UdjinM6PastaPastaPasta
authored andcommitted
refactor: drop global coinJoinWalletManager
1 parent 7fd30b5 commit dc5152b

File tree

14 files changed

+30
-46
lines changed

14 files changed

+30
-46
lines changed

src/coinjoin/client.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include <memory>
3030
#include <univalue.h>
3131

32-
std::unique_ptr<CoinJoinWalletManager> coinJoinWalletManager;
33-
3432
void CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv)
3533
{
3634
if (fMasternodeMode) return;

src/coinjoin/client.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class UniValue;
2929

3030
using CDeterministicMNCPtr = std::shared_ptr<const CDeterministicMN>;
3131

32-
// The main object for accessing mixing
33-
extern std::unique_ptr<CoinJoinWalletManager> coinJoinWalletManager;
34-
3532
class CPendingDsaRequest
3633
{
3734
private:

src/coinjoin/context.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <coinjoin/context.h>
66

77
#include <net.h>
8-
#include <policy/fees.h>
98
#include <txmempool.h>
9+
#include <validation.h>
1010

1111
#ifdef ENABLE_WALLET
1212
#include <coinjoin/client.h>
@@ -15,20 +15,10 @@
1515

1616
CJContext::CJContext(CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, bool relay_txes) :
1717
#ifdef ENABLE_WALLET
18-
walletman {
19-
[&]() -> CoinJoinWalletManager* const {
20-
assert(::coinJoinWalletManager == nullptr);
21-
::coinJoinWalletManager = std::make_unique<CoinJoinWalletManager>(connman, mempool, mn_sync, queueman);
22-
return ::coinJoinWalletManager.get();
23-
}()
24-
},
18+
walletman{std::make_unique<CoinJoinWalletManager>(connman, mempool, mn_sync, queueman)},
2519
queueman {relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(connman, *walletman, mn_sync) : nullptr},
2620
#endif // ENABLE_WALLET
2721
server{std::make_unique<CCoinJoinServer>(chainstate, connman, mempool, mn_sync)}
2822
{}
2923

30-
CJContext::~CJContext() {
31-
#ifdef ENABLE_WALLET
32-
::coinJoinWalletManager.reset();
33-
#endif // ENABLE_WALLET
34-
}
24+
CJContext::~CJContext() {}

src/coinjoin/context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ struct CJContext {
3030
~CJContext();
3131

3232
#ifdef ENABLE_WALLET
33-
CoinJoinWalletManager* const walletman;
33+
// The main object for accessing mixing
34+
const std::unique_ptr<CoinJoinWalletManager> walletman;
3435
const std::unique_ptr<CCoinJoinClientQueueManager> queueman;
3536
#endif // ENABLE_WALLET
3637
const std::unique_ptr<CCoinJoinServer> server;

src/coinjoin/interfaces.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader
8181
}
8282
std::unique_ptr<interfaces::CoinJoin::Client> GetClient(const std::string& name) override
8383
{
84-
return interfaces::MakeCoinJoinClient(m_walletman, name);
84+
auto clientman = m_walletman.Get(name);
85+
return clientman ? std::make_unique<CoinJoinClientImpl>(*clientman) : nullptr;
86+
}
87+
CoinJoinWalletManager& walletman() override
88+
{
89+
return m_walletman;
8590
}
8691
};
8792

8893
} // namespace
8994
} // namespace coinjoin
9095

9196
namespace interfaces {
92-
std::unique_ptr<CoinJoin::Client> MakeCoinJoinClient(const CoinJoinWalletManager& walletman, const std::string& name)
93-
{
94-
auto clientman = walletman.Get(name);
95-
return clientman ? std::make_unique<coinjoin::CoinJoinClientImpl>(*clientman) : nullptr;
96-
}
9797
std::unique_ptr<CoinJoin::Loader> MakeCoinJoinLoader(CoinJoinWalletManager& walletman) { return std::make_unique<coinjoin::CoinJoinLoaderImpl>(walletman); }
9898
} // namespace interfaces

src/interfaces/coinjoin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class Loader
3838
virtual void RemoveWallet(const std::string&) = 0;
3939
virtual void FlushWallet(const std::string&) = 0;
4040
virtual std::unique_ptr<CoinJoin::Client> GetClient(const std::string&) = 0;
41+
virtual CoinJoinWalletManager& walletman() = 0;
4142
};
4243
} // namespace CoinJoin
4344

44-
std::unique_ptr<CoinJoin::Client> MakeCoinJoinClient(const CoinJoinWalletManager& walletman, const std::string& name);
4545
std::unique_ptr<CoinJoin::Loader> MakeCoinJoinLoader(CoinJoinWalletManager& walletman);
4646

4747
} // namespace interfaces

src/interfaces/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class Node
303303
//! Return interface for accessing masternode related handler.
304304
virtual Masternode::Sync& masternodeSync() = 0;
305305

306-
//! Return interface for accessing coinjoin related handler.
306+
//! Return interface for accessing coinjoin options related handler.
307307
virtual CoinJoin::Options& coinJoinOptions() = 0;
308308

309309
//! Return interface for accessing coinjoin loader handler.

src/interfaces/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <amount.h> // For CAmount
99
#include <fs.h> // For fs::path
1010
#include <interfaces/chain.h> // For ChainClient
11-
#include <interfaces/coinjoin.h> // For CoinJoin::*
1211
#include <pubkey.h> // For CKeyID and CScriptID (definitions needed in CTxDestination instantiation)
1312
#include <script/standard.h> // For CTxDestination
1413
#include <support/allocators/secure.h> // For SecureString
@@ -48,6 +47,9 @@ struct WalletBalances;
4847
struct WalletTx;
4948
struct WalletTxOut;
5049
struct WalletTxStatus;
50+
namespace CoinJoin {
51+
class Loader;
52+
}
5153

5254
using WalletOrderForm = std::vector<std::pair<std::string, std::string>>;
5355
using WalletValueMap = std::map<std::string, std::string>;
@@ -278,8 +280,6 @@ class Wallet
278280
// Return whether private keys enabled.
279281
virtual bool privateKeysDisabled() = 0;
280282

281-
virtual CoinJoin::Client& coinJoin() = 0;
282-
283283
//! Get max tx fee.
284284
virtual CAmount getDefaultMaxTxFee() = 0;
285285

src/rpc/coinjoin.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifdef ENABLE_WALLET
1515
#include <coinjoin/client.h>
1616
#include <coinjoin/options.h>
17+
#include <interfaces/coinjoin.h>
1718
#include <wallet/rpcwallet.h>
1819
#endif // ENABLE_WALLET
1920

@@ -51,7 +52,8 @@ static UniValue coinjoin(const JSONRPCRequest& request)
5152
}
5253
}
5354

54-
auto cj_clientman = ::coinJoinWalletManager->Get(wallet->GetName());
55+
const NodeContext& node = EnsureAnyNodeContext(request.context);
56+
auto cj_clientman = node.coinjoin_loader->walletman().Get(wallet->GetName());
5557
CHECK_NONFATAL(cj_clientman != nullptr);
5658

5759
if (request.params[0].get_str() == "start") {
@@ -65,7 +67,6 @@ static UniValue coinjoin(const JSONRPCRequest& request)
6567
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing has been started already.");
6668
}
6769

68-
const NodeContext& node = EnsureAnyNodeContext(request.context);
6970
CTxMemPool& mempool = EnsureMemPool(node);
7071
CBlockPolicyEstimator& fee_estimator = EnsureFeeEstimator(node);
7172
bool result = cj_clientman->DoAutomaticDenominating(*node.connman, fee_estimator, mempool);
@@ -163,7 +164,7 @@ static UniValue getcoinjoininfo(const JSONRPCRequest& request)
163164
return obj;
164165
}
165166

166-
auto manager = ::coinJoinWalletManager->Get(wallet->GetName());
167+
auto manager = node.coinjoin_loader->walletman().Get(wallet->GetName());
167168
CHECK_NONFATAL(manager != nullptr);
168169
manager->GetJsonInfo(obj);
169170

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void DashTestSetup(NodeContext& node)
110110

111111
node.cj_ctx = std::make_unique<CJContext>(chainstate, *node.connman, *node.mempool, *::masternodeSync, /* relay_txes */ true);
112112
#ifdef ENABLE_WALLET
113-
node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*::coinJoinWalletManager);
113+
node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman);
114114
#endif // ENABLE_WALLET
115115
::deterministicMNManager = std::make_unique<CDeterministicMNManager>(chainstate, *node.connman, *node.evodb);
116116
node.llmq_ctx = std::make_unique<LLMQContext>(chainstate, *node.connman, *node.evodb, *sporkManager, *node.mempool, node.peerman, true, false);

0 commit comments

Comments
 (0)