Skip to content

Commit 398e9c3

Browse files
committed
refactor: stop exposing CoinJoinWalletManager from CoinJoin::Loader
1 parent 48fccdd commit 398e9c3

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/coinjoin/interfaces.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <coinjoin/client.h>
88
#include <wallet/wallet.h>
99

10+
#include <univalue.h>
11+
1012
#include <memory>
1113
#include <string>
1214

@@ -37,10 +39,18 @@ class CoinJoinClientImpl : public interfaces::CoinJoin::Client
3739
{
3840
return m_clientman.nCachedNumBlocks;
3941
}
42+
void getJsonInfo(UniValue& obj) override
43+
{
44+
return m_clientman.GetJsonInfo(obj);
45+
}
4046
std::string getSessionDenoms() override
4147
{
4248
return m_clientman.GetSessionDenoms();
4349
}
50+
std::vector<std::string> getSessionStatuses() override
51+
{
52+
return m_clientman.GetStatuses();
53+
}
4454
void setCachedBlocks(int nCachedBlocks) override
4555
{
4656
m_clientman.nCachedNumBlocks = nCachedBlocks;
@@ -81,10 +91,6 @@ class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader
8191
auto clientman = m_walletman.Get(name);
8292
return clientman ? std::make_unique<CoinJoinClientImpl>(*clientman) : nullptr;
8393
}
84-
CoinJoinWalletManager& walletman() override
85-
{
86-
return m_walletman;
87-
}
8894
};
8995

9096
} // namespace

src/interfaces/coinjoin.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
#include <memory>
99
#include <string>
10+
#include <vector>
1011

1112
class CoinJoinWalletManager;
1213
class CWallet;
1314

15+
class UniValue;
16+
1417
namespace interfaces {
1518
namespace CoinJoin {
1619
//! Interface for the wallet constrained src/coinjoin part of a dash node (dashd process).
@@ -21,6 +24,8 @@ class Client
2124
virtual void resetCachedBlocks() = 0;
2225
virtual void resetPool() = 0;
2326
virtual int getCachedBlocks() = 0;
27+
virtual void getJsonInfo(UniValue& obj) = 0;
28+
virtual std::vector<std::string> getSessionStatuses() = 0;
2429
virtual std::string getSessionDenoms() = 0;
2530
virtual void setCachedBlocks(int nCachedBlocks) = 0;
2631
virtual void disableAutobackups() = 0;
@@ -38,7 +43,6 @@ class Loader
3843
virtual void RemoveWallet(const std::string&) = 0;
3944
virtual void FlushWallet(const std::string&) = 0;
4045
virtual std::unique_ptr<CoinJoin::Client> GetClient(const std::string&) = 0;
41-
virtual CoinJoinWalletManager& walletman() = 0;
4246
};
4347
} // namespace CoinJoin
4448

src/rpc/coinjoin.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ static RPCHelpMan coinjoin_reset()
8585

8686
ValidateCoinJoinArguments();
8787

88-
auto cj_clientman = CHECK_NONFATAL(node.coinjoin_loader)->walletman().Get(wallet->GetName());
89-
CHECK_NONFATAL(cj_clientman)->ResetPool();
88+
auto cj_clientman = CHECK_NONFATAL(node.coinjoin_loader)->GetClient(wallet->GetName());
89+
CHECK_NONFATAL(cj_clientman)->resetPool();
9090

9191
return "Mixing was reset";
9292
},
@@ -125,8 +125,8 @@ static RPCHelpMan coinjoin_start()
125125
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first.");
126126
}
127127

128-
auto cj_clientman = CHECK_NONFATAL(CHECK_NONFATAL(node.coinjoin_loader)->walletman().Get(wallet->GetName()));
129-
if (!cj_clientman->StartMixing()) {
128+
auto cj_clientman = CHECK_NONFATAL(CHECK_NONFATAL(node.coinjoin_loader)->GetClient(wallet->GetName()));
129+
if (!cj_clientman->startMixing()) {
130130
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing has been started already.");
131131
}
132132

@@ -160,13 +160,13 @@ static RPCHelpMan coinjoin_status()
160160

161161
ValidateCoinJoinArguments();
162162

163-
auto cj_clientman = CHECK_NONFATAL(node.coinjoin_loader)->walletman().Get(wallet->GetName());
164-
if (!CHECK_NONFATAL(cj_clientman)->IsMixing()) {
163+
auto cj_clientman = CHECK_NONFATAL(node.coinjoin_loader)->GetClient(wallet->GetName());
164+
if (!CHECK_NONFATAL(cj_clientman)->isMixing()) {
165165
throw JSONRPCError(RPC_INTERNAL_ERROR, "No ongoing mix session");
166166
}
167167

168168
UniValue ret(UniValue::VARR);
169-
for (auto str_status : cj_clientman->GetStatuses()) {
169+
for (auto str_status : cj_clientman->getSessionStatuses()) {
170170
ret.push_back(str_status);
171171
}
172172
return ret;
@@ -200,13 +200,13 @@ static RPCHelpMan coinjoin_stop()
200200
ValidateCoinJoinArguments();
201201

202202
CHECK_NONFATAL(node.coinjoin_loader);
203-
auto cj_clientman = node.coinjoin_loader->walletman().Get(wallet->GetName());
203+
auto cj_clientman = node.coinjoin_loader->GetClient(wallet->GetName());
204204

205205
CHECK_NONFATAL(cj_clientman);
206-
if (!cj_clientman->IsMixing()) {
206+
if (!cj_clientman->isMixing()) {
207207
throw JSONRPCError(RPC_INTERNAL_ERROR, "No mix session to stop");
208208
}
209-
cj_clientman->StopMixing();
209+
cj_clientman->stopMixing();
210210

211211
return "Mixing was stopped";
212212
},
@@ -270,8 +270,8 @@ static RPCHelpMan coinjoinsalt_generate()
270270

271271
const NodeContext& node = EnsureAnyNodeContext(request.context);
272272
if (node.coinjoin_loader != nullptr) {
273-
auto cj_clientman = node.coinjoin_loader->walletman().Get(wallet->GetName());
274-
if (cj_clientman != nullptr && cj_clientman->IsMixing()) {
273+
auto cj_clientman = node.coinjoin_loader->GetClient(wallet->GetName());
274+
if (cj_clientman != nullptr && cj_clientman->isMixing()) {
275275
throw JSONRPCError(RPC_WALLET_ERROR,
276276
strprintf("Wallet \"%s\" is currently mixing, cannot change salt!", str_wallet));
277277
}
@@ -372,8 +372,8 @@ static RPCHelpMan coinjoinsalt_set()
372372

373373
const NodeContext& node = EnsureAnyNodeContext(request.context);
374374
if (node.coinjoin_loader != nullptr) {
375-
auto cj_clientman = node.coinjoin_loader->walletman().Get(wallet->GetName());
376-
if (cj_clientman != nullptr && cj_clientman->IsMixing()) {
375+
auto cj_clientman = node.coinjoin_loader->GetClient(wallet->GetName());
376+
if (cj_clientman != nullptr && cj_clientman->isMixing()) {
377377
throw JSONRPCError(RPC_WALLET_ERROR,
378378
strprintf("Wallet \"%s\" is currently mixing, cannot change salt!", str_wallet));
379379
}
@@ -467,8 +467,8 @@ static RPCHelpMan getcoinjoininfo()
467467
return obj;
468468
}
469469

470-
auto* manager = CHECK_NONFATAL(node.coinjoin_loader->walletman().Get(wallet->GetName()));
471-
manager->GetJsonInfo(obj);
470+
auto cj_clientman = CHECK_NONFATAL(node.coinjoin_loader)->GetClient(wallet->GetName());
471+
CHECK_NONFATAL(cj_clientman)->getJsonInfo(obj);
472472

473473
std::string warning_msg{""};
474474
if (wallet->IsLegacy()) {

0 commit comments

Comments
 (0)