Skip to content

Commit b9fb692

Browse files
committed
Push down RPC reqWallet flag
1 parent 0b9dc9c commit b9fb692

File tree

5 files changed

+216
-97
lines changed

5 files changed

+216
-97
lines changed

src/init.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,6 @@ void OnRPCStopped()
242242

243243
void OnRPCPreCommand(const CRPCCommand& cmd)
244244
{
245-
#ifdef ENABLE_WALLET
246-
if (cmd.reqWallet && !pwalletMain)
247-
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
248-
#endif
249-
250245
// Observe safe mode
251246
string strWarning = GetWarnings("rpc");
252247
if (strWarning != "" && !GetBoolArg("-disablesafemode", false) &&

src/rpcserver.cpp

Lines changed: 86 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ string CRPCTable::help(string strCommand) const
193193
continue;
194194
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
195195
continue;
196-
#ifdef ENABLE_WALLET
197-
if (pcmd->reqWallet && !pwalletMain)
198-
continue;
199-
#endif
200-
201196
try
202197
{
203198
Array params;
@@ -271,114 +266,114 @@ Value stop(const Array& params, bool fHelp)
271266
* Call Table
272267
*/
273268
static const CRPCCommand vRPCCommands[] =
274-
{ // category name actor (function) okSafeMode reqWallet
275-
// --------------------- ------------------------ ----------------------- ---------- ---------
269+
{ // category name actor (function) okSafeMode
270+
// --------------------- ------------------------ ----------------------- ----------
276271
/* Overall control/query calls */
277-
{ "control", "getinfo", &getinfo, true, false }, /* uses wallet if enabled */
278-
{ "control", "help", &help, true, false },
279-
{ "control", "stop", &stop, true, false },
272+
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
273+
{ "control", "help", &help, true },
274+
{ "control", "stop", &stop, true },
280275

281276
/* P2P networking */
282-
{ "network", "getnetworkinfo", &getnetworkinfo, true, false },
283-
{ "network", "addnode", &addnode, true, false },
284-
{ "network", "getaddednodeinfo", &getaddednodeinfo, true, false },
285-
{ "network", "getconnectioncount", &getconnectioncount, true, false },
286-
{ "network", "getnettotals", &getnettotals, true, false },
287-
{ "network", "getpeerinfo", &getpeerinfo, true, false },
288-
{ "network", "ping", &ping, true, false },
277+
{ "network", "getnetworkinfo", &getnetworkinfo, true },
278+
{ "network", "addnode", &addnode, true },
279+
{ "network", "getaddednodeinfo", &getaddednodeinfo, true },
280+
{ "network", "getconnectioncount", &getconnectioncount, true },
281+
{ "network", "getnettotals", &getnettotals, true },
282+
{ "network", "getpeerinfo", &getpeerinfo, true },
283+
{ "network", "ping", &ping, true },
289284

290285
/* Block chain and UTXO */
291-
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, false },
292-
{ "blockchain", "getbestblockhash", &getbestblockhash, true, false },
293-
{ "blockchain", "getblockcount", &getblockcount, true, false },
294-
{ "blockchain", "getblock", &getblock, true, false },
295-
{ "blockchain", "getblockhash", &getblockhash, true, false },
296-
{ "blockchain", "getchaintips", &getchaintips, true, false },
297-
{ "blockchain", "getdifficulty", &getdifficulty, true, false },
298-
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true, false },
299-
{ "blockchain", "getrawmempool", &getrawmempool, true, false },
300-
{ "blockchain", "gettxout", &gettxout, true, false },
301-
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, false },
302-
{ "blockchain", "verifychain", &verifychain, true, false },
286+
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true },
287+
{ "blockchain", "getbestblockhash", &getbestblockhash, true },
288+
{ "blockchain", "getblockcount", &getblockcount, true },
289+
{ "blockchain", "getblock", &getblock, true },
290+
{ "blockchain", "getblockhash", &getblockhash, true },
291+
{ "blockchain", "getchaintips", &getchaintips, true },
292+
{ "blockchain", "getdifficulty", &getdifficulty, true },
293+
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
294+
{ "blockchain", "getrawmempool", &getrawmempool, true },
295+
{ "blockchain", "gettxout", &gettxout, true },
296+
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
297+
{ "blockchain", "verifychain", &verifychain, true },
303298

304299
/* Mining */
305-
{ "mining", "getblocktemplate", &getblocktemplate, true, false },
306-
{ "mining", "getmininginfo", &getmininginfo, true, false },
307-
{ "mining", "getnetworkhashps", &getnetworkhashps, true, false },
308-
{ "mining", "prioritisetransaction", &prioritisetransaction, true, false },
309-
{ "mining", "submitblock", &submitblock, true, false },
300+
{ "mining", "getblocktemplate", &getblocktemplate, true },
301+
{ "mining", "getmininginfo", &getmininginfo, true },
302+
{ "mining", "getnetworkhashps", &getnetworkhashps, true },
303+
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
304+
{ "mining", "submitblock", &submitblock, true },
310305

311306
#ifdef ENABLE_WALLET
312307
/* Coin generation */
313-
{ "generating", "getgenerate", &getgenerate, true, false },
314-
{ "generating", "setgenerate", &setgenerate, true, false },
315-
{ "generating", "generate", &generate, true, false },
308+
{ "generating", "getgenerate", &getgenerate, true },
309+
{ "generating", "setgenerate", &setgenerate, true },
310+
{ "generating", "generate", &generate, true },
316311
#endif
317312

318313
/* Raw transactions */
319-
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true, false },
320-
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true, false },
321-
{ "rawtransactions", "decodescript", &decodescript, true, false },
322-
{ "rawtransactions", "getrawtransaction", &getrawtransaction, true, false },
323-
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, false, false },
324-
{ "rawtransactions", "signrawtransaction", &signrawtransaction, false, false }, /* uses wallet if enabled */
314+
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true },
315+
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true },
316+
{ "rawtransactions", "decodescript", &decodescript, true },
317+
{ "rawtransactions", "getrawtransaction", &getrawtransaction, true },
318+
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, false },
319+
{ "rawtransactions", "signrawtransaction", &signrawtransaction, false }, /* uses wallet if enabled */
325320

326321
/* Utility functions */
327-
{ "util", "createmultisig", &createmultisig, true, false },
328-
{ "util", "validateaddress", &validateaddress, true, false }, /* uses wallet if enabled */
329-
{ "util", "verifymessage", &verifymessage, true, false },
330-
{ "util", "estimatefee", &estimatefee, true, false },
331-
{ "util", "estimatepriority", &estimatepriority, true, false },
322+
{ "util", "createmultisig", &createmultisig, true },
323+
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
324+
{ "util", "verifymessage", &verifymessage, true },
325+
{ "util", "estimatefee", &estimatefee, true },
326+
{ "util", "estimatepriority", &estimatepriority, true },
332327

333328
/* Not shown in help */
334-
{ "hidden", "invalidateblock", &invalidateblock, true, false },
335-
{ "hidden", "reconsiderblock", &reconsiderblock, true, false },
336-
{ "hidden", "setmocktime", &setmocktime, true, false },
329+
{ "hidden", "invalidateblock", &invalidateblock, true },
330+
{ "hidden", "reconsiderblock", &reconsiderblock, true },
331+
{ "hidden", "setmocktime", &setmocktime, true },
337332
#ifdef ENABLE_WALLET
338-
{ "hidden", "resendwallettransactions", &resendwallettransactions, true, true },
333+
{ "hidden", "resendwallettransactions", &resendwallettransactions, true},
339334
#endif
340335

341336
#ifdef ENABLE_WALLET
342337
/* Wallet */
343-
{ "wallet", "addmultisigaddress", &addmultisigaddress, true, true },
344-
{ "wallet", "backupwallet", &backupwallet, true, true },
345-
{ "wallet", "dumpprivkey", &dumpprivkey, true, true },
346-
{ "wallet", "dumpwallet", &dumpwallet, true, true },
347-
{ "wallet", "encryptwallet", &encryptwallet, true, true },
348-
{ "wallet", "getaccountaddress", &getaccountaddress, true, true },
349-
{ "wallet", "getaccount", &getaccount, true, true },
350-
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true, true },
351-
{ "wallet", "getbalance", &getbalance, false, true },
352-
{ "wallet", "getnewaddress", &getnewaddress, true, true },
353-
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true, true },
354-
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false, true },
355-
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false, true },
356-
{ "wallet", "gettransaction", &gettransaction, false, true },
357-
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false, true },
358-
{ "wallet", "getwalletinfo", &getwalletinfo, false, true },
359-
{ "wallet", "importprivkey", &importprivkey, true, true },
360-
{ "wallet", "importwallet", &importwallet, true, true },
361-
{ "wallet", "importaddress", &importaddress, true, true },
362-
{ "wallet", "keypoolrefill", &keypoolrefill, true, true },
363-
{ "wallet", "listaccounts", &listaccounts, false, true },
364-
{ "wallet", "listaddressgroupings", &listaddressgroupings, false, true },
365-
{ "wallet", "listlockunspent", &listlockunspent, false, true },
366-
{ "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false, true },
367-
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false, true },
368-
{ "wallet", "listsinceblock", &listsinceblock, false, true },
369-
{ "wallet", "listtransactions", &listtransactions, false, true },
370-
{ "wallet", "listunspent", &listunspent, false, true },
371-
{ "wallet", "lockunspent", &lockunspent, true, true },
372-
{ "wallet", "move", &movecmd, false, true },
373-
{ "wallet", "sendfrom", &sendfrom, false, true },
374-
{ "wallet", "sendmany", &sendmany, false, true },
375-
{ "wallet", "sendtoaddress", &sendtoaddress, false, true },
376-
{ "wallet", "setaccount", &setaccount, true, true },
377-
{ "wallet", "settxfee", &settxfee, true, true },
378-
{ "wallet", "signmessage", &signmessage, true, true },
379-
{ "wallet", "walletlock", &walletlock, true, true },
380-
{ "wallet", "walletpassphrasechange", &walletpassphrasechange, true, true },
381-
{ "wallet", "walletpassphrase", &walletpassphrase, true, true },
338+
{ "wallet", "addmultisigaddress", &addmultisigaddress, true },
339+
{ "wallet", "backupwallet", &backupwallet, true },
340+
{ "wallet", "dumpprivkey", &dumpprivkey, true },
341+
{ "wallet", "dumpwallet", &dumpwallet, true },
342+
{ "wallet", "encryptwallet", &encryptwallet, true },
343+
{ "wallet", "getaccountaddress", &getaccountaddress, true },
344+
{ "wallet", "getaccount", &getaccount, true },
345+
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
346+
{ "wallet", "getbalance", &getbalance, false },
347+
{ "wallet", "getnewaddress", &getnewaddress, true },
348+
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true },
349+
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false },
350+
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false },
351+
{ "wallet", "gettransaction", &gettransaction, false },
352+
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
353+
{ "wallet", "getwalletinfo", &getwalletinfo, false },
354+
{ "wallet", "importprivkey", &importprivkey, true },
355+
{ "wallet", "importwallet", &importwallet, true },
356+
{ "wallet", "importaddress", &importaddress, true },
357+
{ "wallet", "keypoolrefill", &keypoolrefill, true },
358+
{ "wallet", "listaccounts", &listaccounts, false },
359+
{ "wallet", "listaddressgroupings", &listaddressgroupings, false },
360+
{ "wallet", "listlockunspent", &listlockunspent, false },
361+
{ "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false },
362+
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false },
363+
{ "wallet", "listsinceblock", &listsinceblock, false },
364+
{ "wallet", "listtransactions", &listtransactions, false },
365+
{ "wallet", "listunspent", &listunspent, false },
366+
{ "wallet", "lockunspent", &lockunspent, true },
367+
{ "wallet", "move", &movecmd, false },
368+
{ "wallet", "sendfrom", &sendfrom, false },
369+
{ "wallet", "sendmany", &sendmany, false },
370+
{ "wallet", "sendtoaddress", &sendtoaddress, false },
371+
{ "wallet", "setaccount", &setaccount, true },
372+
{ "wallet", "settxfee", &settxfee, true },
373+
{ "wallet", "signmessage", &signmessage, true },
374+
{ "wallet", "walletlock", &walletlock, true },
375+
{ "wallet", "walletpassphrasechange", &walletpassphrasechange, true },
376+
{ "wallet", "walletpassphrase", &walletpassphrase, true },
382377
#endif // ENABLE_WALLET
383378
};
384379

src/rpcserver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class CRPCCommand
9898
std::string name;
9999
rpcfn_type actor;
100100
bool okSafeMode;
101-
bool reqWallet;
102101
};
103102

104103
/**

src/wallet/rpcdump.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace json_spirit;
2525
using namespace std;
2626

2727
void EnsureWalletIsUnlocked();
28+
bool EnsureWalletIsAvailable(bool avoidException);
2829

2930
std::string static EncodeDumpTime(int64_t nTime) {
3031
return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
@@ -71,6 +72,9 @@ std::string DecodeDumpString(const std::string &str) {
7172

7273
Value importprivkey(const Array& params, bool fHelp)
7374
{
75+
if (!EnsureWalletIsAvailable(fHelp))
76+
return Value::null;
77+
7478
if (fHelp || params.size() < 1 || params.size() > 3)
7579
throw runtime_error(
7680
"importprivkey \"bitcoinprivkey\" ( \"label\" rescan )\n"
@@ -142,6 +146,9 @@ Value importprivkey(const Array& params, bool fHelp)
142146

143147
Value importaddress(const Array& params, bool fHelp)
144148
{
149+
if (!EnsureWalletIsAvailable(fHelp))
150+
return Value::null;
151+
145152
if (fHelp || params.size() < 1 || params.size() > 3)
146153
throw runtime_error(
147154
"importaddress \"address\" ( \"label\" rescan )\n"
@@ -212,6 +219,9 @@ Value importaddress(const Array& params, bool fHelp)
212219

213220
Value importwallet(const Array& params, bool fHelp)
214221
{
222+
if (!EnsureWalletIsAvailable(fHelp))
223+
return Value::null;
224+
215225
if (fHelp || params.size() != 1)
216226
throw runtime_error(
217227
"importwallet \"filename\"\n"
@@ -313,6 +323,9 @@ Value importwallet(const Array& params, bool fHelp)
313323

314324
Value dumpprivkey(const Array& params, bool fHelp)
315325
{
326+
if (!EnsureWalletIsAvailable(fHelp))
327+
return Value::null;
328+
316329
if (fHelp || params.size() != 1)
317330
throw runtime_error(
318331
"dumpprivkey \"bitcoinaddress\"\n"
@@ -348,6 +361,9 @@ Value dumpprivkey(const Array& params, bool fHelp)
348361

349362
Value dumpwallet(const Array& params, bool fHelp)
350363
{
364+
if (!EnsureWalletIsAvailable(fHelp))
365+
return Value::null;
366+
351367
if (fHelp || params.size() != 1)
352368
throw runtime_error(
353369
"dumpwallet \"filename\"\n"

0 commit comments

Comments
 (0)