RPC: more EnsureWalletIsAvailable in Dash-specific code

This commit is contained in:
UdjinM6 2018-02-27 23:04:18 +03:00
parent d75d4842ae
commit 70e47f11a0
3 changed files with 33 additions and 2 deletions

View File

@ -24,6 +24,8 @@
#include "wallet/wallet.h"
#endif // ENABLE_WALLET
bool EnsureWalletIsAvailable(bool avoidException);
UniValue gobject(const JSONRPCRequest& request)
{
std::string strCommand;
@ -125,6 +127,9 @@ UniValue gobject(const JSONRPCRequest& request)
// PREPARE THE GOVERNANCE OBJECT BY CREATING A COLLATERAL TRANSACTION
if(strCommand == "prepare")
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.params.size() != 5) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject prepare <parent-hash> <revision> <time> <data-hex>'");
}

View File

@ -25,11 +25,16 @@
UniValue masternodelist(const JSONRPCRequest& request);
bool EnsureWalletIsAvailable(bool avoidException);
#ifdef ENABLE_WALLET
void EnsureWalletIsUnlocked();
UniValue privatesend(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"privatesend \"command\"\n"
@ -254,6 +259,9 @@ UniValue masternode(const JSONRPCRequest& request)
#ifdef ENABLE_WALLET
if (strCommand == "start-alias")
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.params.size() < 2)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Please specify an alias");
@ -303,6 +311,9 @@ UniValue masternode(const JSONRPCRequest& request)
if (strCommand == "start-all" || strCommand == "start-missing" || strCommand == "start-disabled")
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
{
LOCK(pwalletMain->cs_wallet);
EnsureWalletIsUnlocked();
@ -393,6 +404,9 @@ UniValue masternode(const JSONRPCRequest& request)
#ifdef ENABLE_WALLET
if (strCommand == "outputs") {
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
// Find possible candidates
std::vector<COutput> vPossibleCoins;
pwalletMain->AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_1000);
@ -646,6 +660,9 @@ UniValue masternodebroadcast(const JSONRPCRequest& request)
#ifdef ENABLE_WALLET
if (strCommand == "create-alias")
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
// wait for reindex and/or import to finish
if (fImporting || fReindex)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wait for reindex and/or import to finish");
@ -698,6 +715,9 @@ UniValue masternodebroadcast(const JSONRPCRequest& request)
if (strCommand == "create-all")
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
// wait for reindex and/or import to finish
if (fImporting || fReindex)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wait for reindex and/or import to finish");

View File

@ -2406,7 +2406,11 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
return obj;
}
UniValue keepass(const JSONRPCRequest& request) {
UniValue keepass(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
std::string strCommand;
if (request.params.size() >= 1)
@ -2453,7 +2457,6 @@ UniValue keepass(const JSONRPCRequest& request) {
}
return "Invalid command";
}
UniValue resendwallettransactions(const JSONRPCRequest& request)
@ -2767,6 +2770,9 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
UniValue setbip69enabled(const JSONRPCRequest& request)
{
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;
if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"setbip69enabled enable\n"