Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

privatesend.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 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
8 #endif // ENABLE_WALLET
10 #include <rpc/server.h>
11 #include <rpc/safemode.h>
12 
13 #include <univalue.h>
14 
15 #ifdef ENABLE_WALLET
16 UniValue privatesend(const JSONRPCRequest& request)
17 {
18  CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
19  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
20  return NullUniValue;
21 
22  if (request.fHelp || request.params.size() != 1)
23  throw std::runtime_error(
24  "privatesend \"command\"\n"
25  "\nArguments:\n"
26  "1. \"command\" (string or set of strings, required) The command to execute\n"
27  "\nAvailable commands:\n"
28  " start - Start mixing\n"
29  " stop - Stop mixing\n"
30  " reset - Reset mixing\n"
31  );
32 
34 
35  if (fMasternodeMode)
36  throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
37 
39  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  // not enableprivatesend=false case,
44  // most likely something 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 
58  return "Mixing " + (result ? "started successfully" : ("start failed: " + privateSendClient.GetStatuses() + ", will retry"));
59  }
60 
61  if (request.params[0].get_str() == "stop") {
63  return "Mixing was stopped";
64  }
65 
66  if (request.params[0].get_str() == "reset") {
68  return "Mixing was reset";
69  }
70 
71  return "Unknown command, please see \"help privatesend\"";
72 }
73 #endif // ENABLE_WALLET
74 
76 {
77  throw std::runtime_error(
78  "getpoolinfo\n"
79  "DEPRECATED. Please use getprivatesendinfo instead.\n"
80  );
81 }
82 
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) Target PrivateSend balance in " + CURRENCY_UNIT + "\n"
97  " \"denoms_goal\": xxx, (numeric) How many inputs of each denominated amount to target\n"
98  " \"denoms_hardcap\": xxx, (numeric) Maximum limit of how many inputs of each denominated amount to create\n"
99  " \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
100  " \"sessions\": (array of json objects)\n"
101  " [\n"
102  " {\n"
103  " \"protxhash\": \"...\", (string) The ProTxHash of the masternode\n"
104  " \"outpoint\": \"txid-index\", (string) The outpoint of the masternode\n"
105  " \"service\": \"host:port\", (string) The IP address and port of the masternode\n"
106  " \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
107  " \"state\": \"...\", (string) Current state of the mixing session\n"
108  " \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
109  " }\n"
110  " ,...\n"
111  " ],\n"
112  " \"keys_left\": xxx, (numeric) How many new keys are left since last automatic backup\n"
113  " \"warnings\": \"...\" (string) Warnings if any\n"
114  "}\n"
115  "\nResult (for masternodes):\n"
116  "{\n"
117  " \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n"
118  " \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n"
119  " \"state\": \"...\", (string) Current state of the mixing session\n"
120  " \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n"
121  "}\n"
122  "\nExamples:\n"
123  + HelpExampleCli("getprivatesendinfo", "")
124  + HelpExampleRpc("getprivatesendinfo", "")
125  );
126  }
127 
129 
130  if (fMasternodeMode) {
132  return obj;
133  }
134 
135 
136 #ifdef ENABLE_WALLET
138 
139  CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
140  if (!pwallet) {
141  return obj;
142  }
143 
144  obj.push_back(Pair("keys_left", pwallet->nKeysLeftSinceAutoBackup));
146  ? "WARNING: keypool is almost depleted!" : ""));
147 #endif // ENABLE_WALLET
148 
149  return obj;
150 }
151 
152 static const CRPCCommand commands[] =
153  { // category name actor (function) argNames
154  // --------------------- ------------------------ ---------------------------------
155  { "dash", "getpoolinfo", &getpoolinfo, {} },
156  { "dash", "getprivatesendinfo", &getprivatesendinfo, {} },
157 #ifdef ENABLE_WALLET
158  { "dash", "privatesend", &privatesend, {} },
159 #endif // ENABLE_WALLET
160 };
161 
163 {
164  for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
165  t.appendCommand(commands[vcidx].name, &commands[vcidx]);
166 }
CPrivateSendServer privateSendServer
Enter the wallet passphrase with walletpassphrase first.
Definition: protocol.h:81
Dash RPC command dispatcher.
Definition: server.h:140
CCriticalSection cs_wallet
Definition: wallet.h:836
bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException)
Definition: rpcwallet.cpp:66
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING
const std::string & get_str() const
void GetJsonInfo(UniValue &obj) const
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:583
const std::string CURRENCY_UNIT
Definition: feerate.cpp:10
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:824
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:353
UniValue getpoolinfo(const JSONRPCRequest &request)
Definition: privatesend.cpp:75
bool fMasternodeMode
Definition: util.cpp:93
std::string name
Definition: server.h:132
bool push_back(const UniValue &val)
Definition: univalue.cpp:110
UniValue params
Definition: server.h:42
void GetJsonInfo(UniValue &obj) const
#define LOCK(cs)
Definition: sync.h:178
int64_t nKeysLeftSinceAutoBackup
Definition: wallet.h:910
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:578
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
UniValue getprivatesendinfo(const JSONRPCRequest &request)
Definition: privatesend.cpp:83
bool fHelp
Definition: server.h:43
ArgsManager gArgs
Definition: util.cpp:108
#define ARRAYLEN(array)
CPrivateSendClientManager privateSendClient
bool IsLocked(bool fForMixing=false) const
Definition: crypter.cpp:209
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
static const CRPCCommand commands[]
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:97
const UniValue NullUniValue
Definition: univalue.cpp:15
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: rpcwallet.cpp:45
void RegisterPrivateSendRPCCommands(CRPCTable &t)
Register PrivateSend RPC commands.
void ObserveSafeMode()
Definition: safemode.cpp:7
bool DoAutomaticDenominating(CConnman &connman, bool fDryRun=false)
Passively run mixing in the background according to the configuration in settings.
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:54
size_t size() const
Definition: univalue.h:69
Released under the MIT license