forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterfaces.cpp
More file actions
126 lines (111 loc) · 3.21 KB
/
interfaces.cpp
File metadata and controls
126 lines (111 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2024-2025 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <interfaces/coinjoin.h>
#include <coinjoin/client.h>
#include <coinjoin/options.h>
#include <coinjoin/walletman.h>
#include <node/context.h>
#include <util/check.h>
#include <walletinitinterface.h>
#include <memory>
#include <string>
using node::NodeContext;
using wallet::CWallet;
namespace coinjoin {
namespace {
class CoinJoinClientImpl : public interfaces::CoinJoin::Client
{
CCoinJoinClientManager& m_clientman;
public:
explicit CoinJoinClientImpl(CCoinJoinClientManager& clientman)
: m_clientman(clientman) {}
void resetCachedBlocks() override
{
m_clientman.nCachedNumBlocks = std::numeric_limits<int>::max();
}
void resetPool() override
{
m_clientman.ResetPool();
}
void disableAutobackups() override
{
m_clientman.fCreateAutoBackups = false;
}
int getCachedBlocks() override
{
return m_clientman.nCachedNumBlocks;
}
void getJsonInfo(UniValue& obj) override
{
return m_clientman.GetJsonInfo(obj);
}
std::string getSessionDenoms() override
{
return m_clientman.GetSessionDenoms();
}
std::vector<std::string> getSessionStatuses() override
{
return m_clientman.GetStatuses();
}
void setCachedBlocks(int nCachedBlocks) override
{
m_clientman.nCachedNumBlocks = nCachedBlocks;
}
bool isMixing() override
{
return m_clientman.IsMixing();
}
bool startMixing() override
{
return m_clientman.StartMixing();
}
void stopMixing() override
{
m_clientman.StopMixing();
}
};
class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader
{
private:
CJWalletManager& manager()
{
return *Assert(m_node.cj_walletman);
}
interfaces::WalletLoader& wallet_loader()
{
return *Assert(m_node.wallet_loader);
}
public:
explicit CoinJoinLoaderImpl(NodeContext& node) :
m_node(node)
{
// Enablement will be re-evaluated when a wallet is added or removed
CCoinJoinClientOptions::SetEnabled(false);
}
void AddWallet(const std::shared_ptr<CWallet>& wallet) override
{
manager().addWallet(wallet);
g_wallet_init_interface.InitCoinJoinSettings(*this, wallet_loader());
}
void RemoveWallet(const std::string& name) override
{
manager().removeWallet(name);
g_wallet_init_interface.InitCoinJoinSettings(*this, wallet_loader());
}
void FlushWallet(const std::string& name) override
{
manager().flushWallet(name);
}
std::unique_ptr<interfaces::CoinJoin::Client> GetClient(const std::string& name) override
{
auto clientman = manager().getClient(name);
return clientman ? std::make_unique<CoinJoinClientImpl>(*clientman) : nullptr;
}
NodeContext& m_node;
};
} // namespace
} // namespace coinjoin
namespace interfaces {
std::unique_ptr<CoinJoin::Loader> MakeCoinJoinLoader(NodeContext& node) { return std::make_unique<coinjoin::CoinJoinLoaderImpl>(node); }
} // namespace interfaces