Skip to content

Commit cecbbab

Browse files
PastaPastaPastaUdjinM6
authored andcommitted
move privatesend rpc methods from rpc/masternode.cpp to new rpc/privatesend.cpp (#3253)
* move privatesend rpc methods from masternode.cpp to new privatesend.cpp Signed-off-by: Pasta <pasta@dashboost.org> * add ifdef ENABLE_WALLET check for wallet.h import Signed-off-by: Pasta <pasta@dashboost.org> * actually register privatesend rpc Signed-off-by: Pasta <pasta@dashboost.org> * add dropped help text and change some weird spacing below Signed-off-by: Pasta <pasta@dashboost.org>
1 parent 8e054f3 commit cecbbab

File tree

4 files changed

+179
-151
lines changed

4 files changed

+179
-151
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ libdash_server_a_SOURCES = \
339339
rpc/rpcevo.cpp \
340340
rpc/rpcquorums.cpp \
341341
rpc/server.cpp \
342+
rpc/privatesend.cpp \
342343
script/sigcache.cpp \
343344
script/ismine.cpp \
344345
spork.cpp \

src/rpc/masternode.cpp

Lines changed: 10 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -8,165 +8,29 @@
88
#include "init.h"
99
#include "netbase.h"
1010
#include "validation.h"
11-
#include "masternode/masternode-payments.h"
12-
#include "masternode/masternode-sync.h"
13-
#ifdef ENABLE_WALLET
14-
#include "privatesend/privatesend-client.h"
15-
#endif // ENABLE_WALLET
16-
#include "privatesend/privatesend-server.h"
17-
#include "rpc/server.h"
1811
#include "util.h"
1912
#include "utilmoneystr.h"
2013
#include "txmempool.h"
2114

22-
#include "wallet/coincontrol.h"
23-
#include "wallet/rpcwallet.h"
24-
2515
#include "evo/specialtx.h"
2616
#include "evo/deterministicmns.h"
2717

28-
#include <fstream>
29-
#include <iomanip>
30-
#include <univalue.h>
18+
#include "masternode/masternode-payments.h"
19+
#include "masternode/masternode-sync.h"
3120

32-
UniValue masternodelist(const JSONRPCRequest& request);
21+
#include "rpc/server.h"
3322

23+
#include "wallet/coincontrol.h"
24+
#include "wallet/rpcwallet.h"
3425
#ifdef ENABLE_WALLET
35-
UniValue privatesend(const JSONRPCRequest& request)
36-
{
37-
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
38-
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
39-
return NullUniValue;
40-
41-
if (request.fHelp || request.params.size() != 1)
42-
throw std::runtime_error(
43-
"privatesend \"command\"\n"
44-
"\nArguments:\n"
45-
"1. \"command\" (string or set of strings, required) The command to execute\n"
46-
"\nAvailable commands:\n"
47-
" start - Start mixing\n"
48-
" stop - Stop mixing\n"
49-
" reset - Reset mixing\n"
50-
);
51-
52-
if (fMasternodeMode)
53-
throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
54-
55-
if (!privateSendClient.fEnablePrivateSend) {
56-
if (fLiteMode) {
57-
// mixing is disabled by default in lite mode
58-
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled in lite mode, use -enableprivatesend command line option to enable mixing again");
59-
} else if (!gArgs.GetBoolArg("-enableprivatesend", true)) {
60-
// otherwise it's on by default, unless cmd line option says otherwise
61-
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled via -enableprivatesend=0 command line option, remove it to enable mixing again");
62-
} else {
63-
// neither litemode nor enableprivatesend=false casee,
64-
// most likely smth bad happened and we disabled it while running the wallet
65-
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled due to some internal error");
66-
}
67-
}
68-
69-
if (request.params[0].get_str() == "start") {
70-
{
71-
LOCK(pwallet->cs_wallet);
72-
if (pwallet->IsLocked(true))
73-
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first.");
74-
}
75-
76-
privateSendClient.fPrivateSendRunning = true;
77-
bool result = privateSendClient.DoAutomaticDenominating(*g_connman);
78-
return "Mixing " + (result ? "started successfully" : ("start failed: " + privateSendClient.GetStatuses() + ", will retry"));
79-
}
80-
81-
if (request.params[0].get_str() == "stop") {
82-
privateSendClient.fPrivateSendRunning = false;
83-
return "Mixing was stopped";
84-
}
85-
86-
if (request.params[0].get_str() == "reset") {
87-
privateSendClient.ResetPool();
88-
return "Mixing was reset";
89-
}
90-
91-
return "Unknown command, please see \"help privatesend\"";
92-
}
26+
#include "wallet/wallet.h"
9327
#endif // ENABLE_WALLET
9428

95-
UniValue getpoolinfo(const JSONRPCRequest& request)
96-
{
97-
throw std::runtime_error(
98-
"getpoolinfo\n"
99-
"DEPRECATED. Please use getprivatesendinfo instead.\n"
100-
);
101-
}
102-
103-
UniValue getprivatesendinfo(const JSONRPCRequest& request)
104-
{
105-
if (request.fHelp || request.params.size() != 0) {
106-
throw std::runtime_error(
107-
"getprivatesendinfo\n"
108-
"Returns an object containing an information about PrivateSend settings and state.\n"
109-
"\nResult (for regular nodes):\n"
110-
"{\n"
111-
" \"enabled\": true|false, (bool) Whether mixing functionality is enabled\n"
112-
" \"running\": true|false, (bool) Whether mixing is currently running\n"
113-
" \"multisession\": true|false, (bool) Whether PrivateSend Multisession option is enabled\n"
114-
" \"max_sessions\": xxx, (numeric) How many parallel mixing sessions can there be at once\n"
115-
" \"max_rounds\": xxx, (numeric) How many rounds to mix\n"
116-
" \"max_amount\": xxx, (numeric) How many " + CURRENCY_UNIT + " to keep mixed\n"
117-
" \"max_denoms\": xxx, (numeric) How many inputs of each denominated amount to create\n"
118-
" \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
119-
" \"sessions\": (array of json objects)\n"
120-
" [\n"
121-
" {\n"
122-
" \"protxhash\": \"...\", (string) The ProTxHash of the masternode\n"
123-
" \"outpoint\": \"txid-index\", (string) The outpoint of the masternode\n"
124-
" \"service\": \"host:port\", (string) The IP address and port of the masternode\n"
125-
" \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
126-
" \"state\": \"...\", (string) Current state of the mixing session\n"
127-
" \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
128-
" }\n"
129-
" ,...\n"
130-
" ],\n"
131-
" \"keys_left\": xxx, (numeric) How many new keys are left since last automatic backup\n"
132-
" \"warnings\": \"...\" (string) Warnings if any\n"
133-
"}\n"
134-
"\nResult (for masternodes):\n"
135-
"{\n"
136-
" \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
137-
" \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
138-
" \"state\": \"...\", (string) Current state of the mixing session\n"
139-
" \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
140-
"}\n"
141-
"\nExamples:\n"
142-
+ HelpExampleCli("getprivatesendinfo", "")
143-
+ HelpExampleRpc("getprivatesendinfo", "")
144-
);
145-
}
146-
147-
UniValue obj(UniValue::VOBJ);
148-
149-
if (fMasternodeMode) {
150-
privateSendServer.GetJsonInfo(obj);
151-
return obj;
152-
}
153-
154-
155-
#ifdef ENABLE_WALLET
156-
privateSendClient.GetJsonInfo(obj);
157-
158-
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
159-
if (!pwallet) {
160-
return obj;
161-
}
162-
163-
obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup));
164-
obj.push_back(Pair("warnings", pwallet->nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
165-
? "WARNING: keypool is almost depleted!" : ""));
166-
#endif // ENABLE_WALLET
29+
#include <fstream>
30+
#include <iomanip>
31+
#include <univalue.h>
16732

168-
return obj;
169-
}
33+
UniValue masternodelist(const JSONRPCRequest& request);
17034

17135
void masternode_list_help()
17236
{
@@ -668,11 +532,6 @@ static const CRPCCommand commands[] =
668532
// --------------------- ------------------------ ----------------------- ------ ----------
669533
{ "dash", "masternode", &masternode, true, {} },
670534
{ "dash", "masternodelist", &masternodelist, true, {} },
671-
{ "dash", "getpoolinfo", &getpoolinfo, true, {} },
672-
{ "dash", "getprivatesendinfo", &getprivatesendinfo, true, {} },
673-
#ifdef ENABLE_WALLET
674-
{ "dash", "privatesend", &privatesend, false, {} },
675-
#endif // ENABLE_WALLET
676535
};
677536

678537
void RegisterMasternodeRPCCommands(CRPCTable &t)

src/rpc/privatesend.cpp

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Copyright (c) 2019 The Dash Core developers
2+
// Distributed under the MIT/X11 software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include "validation.h"
6+
#ifdef ENABLE_WALLET
7+
#include "privatesend/privatesend-client.h"
8+
#endif // ENABLE_WALLET
9+
#include "privatesend/privatesend-server.h"
10+
#include "rpc/server.h"
11+
12+
#include <univalue.h>
13+
14+
#ifdef ENABLE_WALLET
15+
UniValue privatesend(const JSONRPCRequest& request)
16+
{
17+
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
18+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
19+
return NullUniValue;
20+
21+
if (request.fHelp || request.params.size() != 1)
22+
throw std::runtime_error(
23+
"privatesend \"command\"\n"
24+
"\nArguments:\n"
25+
"1. \"command\" (string or set of strings, required) The command to execute\n"
26+
"\nAvailable commands:\n"
27+
" start - Start mixing\n"
28+
" stop - Stop mixing\n"
29+
" reset - Reset mixing\n"
30+
);
31+
32+
if (fMasternodeMode)
33+
throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
34+
35+
if (!privateSendClient.fEnablePrivateSend) {
36+
if (fLiteMode) {
37+
// mixing is disabled by default in lite mode
38+
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled in lite mode, use -enableprivatesend command line option to enable mixing again");
39+
} else if (!gArgs.GetBoolArg("-enableprivatesend", true)) {
40+
// otherwise it's on by default, unless cmd line option says otherwise
41+
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled via -enableprivatesend=0 command line option, remove it to enable mixing again");
42+
} else {
43+
// neither litemode nor enableprivatesend=false casee,
44+
// most likely smth bad happened and we disabled it while running the wallet
45+
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled due to some internal error");
46+
}
47+
}
48+
49+
if (request.params[0].get_str() == "start") {
50+
{
51+
LOCK(pwallet->cs_wallet);
52+
if (pwallet->IsLocked(true))
53+
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first.");
54+
}
55+
56+
privateSendClient.fPrivateSendRunning = true;
57+
bool result = privateSendClient.DoAutomaticDenominating(*g_connman);
58+
return "Mixing " + (result ? "started successfully" : ("start failed: " + privateSendClient.GetStatuses() + ", will retry"));
59+
}
60+
61+
if (request.params[0].get_str() == "stop") {
62+
privateSendClient.fPrivateSendRunning = false;
63+
return "Mixing was stopped";
64+
}
65+
66+
if (request.params[0].get_str() == "reset") {
67+
privateSendClient.ResetPool();
68+
return "Mixing was reset";
69+
}
70+
71+
return "Unknown command, please see \"help privatesend\"";
72+
}
73+
#endif // ENABLE_WALLET
74+
75+
UniValue getpoolinfo(const JSONRPCRequest& request)
76+
{
77+
throw std::runtime_error(
78+
"getpoolinfo\n"
79+
"DEPRECATED. Please use getprivatesendinfo instead.\n"
80+
);
81+
}
82+
83+
UniValue getprivatesendinfo(const JSONRPCRequest& request)
84+
{
85+
if (request.fHelp || request.params.size() != 0) {
86+
throw std::runtime_error(
87+
"getprivatesendinfo\n"
88+
"Returns an object containing an information about PrivateSend settings and state.\n"
89+
"\nResult (for regular nodes):\n"
90+
"{\n"
91+
" \"enabled\": true|false, (bool) Whether mixing functionality is enabled\n"
92+
" \"running\": true|false, (bool) Whether mixing is currently running\n"
93+
" \"multisession\": true|false, (bool) Whether PrivateSend Multisession option is enabled\n"
94+
" \"max_sessions\": xxx, (numeric) How many parallel mixing sessions can there be at once\n"
95+
" \"max_rounds\": xxx, (numeric) How many rounds to mix\n"
96+
" \"max_amount\": xxx, (numeric) How many " + CURRENCY_UNIT + " to keep mixed\n"
97+
" \"max_denoms\": xxx, (numeric) How many inputs of each denominated amount to create\n"
98+
" \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
99+
" \"sessions\": (array of json objects)\n"
100+
" [\n"
101+
" {\n"
102+
" \"protxhash\": \"...\", (string) The ProTxHash of the masternode\n"
103+
" \"outpoint\": \"txid-index\", (string) The outpoint of the masternode\n"
104+
" \"service\": \"host:port\", (string) The IP address and port of the masternode\n"
105+
" \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
106+
" \"state\": \"...\", (string) Current state of the mixing session\n"
107+
" \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
108+
" }\n"
109+
" ,...\n"
110+
" ],\n"
111+
" \"keys_left\": xxx, (numeric) How many new keys are left since last automatic backup\n"
112+
" \"warnings\": \"...\" (string) Warnings if any\n"
113+
"}\n"
114+
"\nResult (for masternodes):\n"
115+
"{\n"
116+
" \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
117+
" \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
118+
" \"state\": \"...\", (string) Current state of the mixing session\n"
119+
" \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
120+
"}\n"
121+
"\nExamples:\n"
122+
+ HelpExampleCli("getprivatesendinfo", "")
123+
+ HelpExampleRpc("getprivatesendinfo", "")
124+
);
125+
}
126+
127+
UniValue obj(UniValue::VOBJ);
128+
129+
if (fMasternodeMode) {
130+
privateSendServer.GetJsonInfo(obj);
131+
return obj;
132+
}
133+
134+
135+
#ifdef ENABLE_WALLET
136+
privateSendClient.GetJsonInfo(obj);
137+
138+
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
139+
if (!pwallet) {
140+
return obj;
141+
}
142+
143+
obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup));
144+
obj.push_back(Pair("warnings", pwallet->nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING
145+
? "WARNING: keypool is almost depleted!" : ""));
146+
#endif // ENABLE_WALLET
147+
148+
return obj;
149+
}
150+
151+
static const CRPCCommand commands[] =
152+
{ // category name actor (function) okSafe argNames
153+
// --------------------- ------------------------ ----------------------- ------ ----------
154+
{ "dash", "getpoolinfo", &getpoolinfo, true, {} },
155+
{ "dash", "getprivatesendinfo", &getprivatesendinfo, true, {} },
156+
#ifdef ENABLE_WALLET
157+
{ "dash", "privatesend", &privatesend, false, {} },
158+
#endif // ENABLE_WALLET
159+
};
160+
161+
void RegisterPrivateSendRPCCommands(CRPCTable &t)
162+
{
163+
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
164+
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
165+
}

src/rpc/register.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void RegisterMiningRPCCommands(CRPCTable &tableRPC);
2121
void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC);
2222
/** Register masternode RPC commands */
2323
void RegisterMasternodeRPCCommands(CRPCTable &tableRPC);
24+
/** Register PrivateSend RPC commands */
25+
void RegisterPrivateSendRPCCommands(CRPCTable &tableRPC);
2426
/** Register governance RPC commands */
2527
void RegisterGovernanceRPCCommands(CRPCTable &tableRPC);
2628
/** Register Evo RPC commands */
@@ -36,6 +38,7 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable &t)
3638
RegisterMiningRPCCommands(t);
3739
RegisterRawTransactionRPCCommands(t);
3840
RegisterMasternodeRPCCommands(t);
41+
RegisterPrivateSendRPCCommands(t);
3942
RegisterGovernanceRPCCommands(t);
4043
RegisterEvoRPCCommands(t);
4144
RegisterQuorumsRPCCommands(t);

0 commit comments

Comments
 (0)