Skip to content

Commit

Permalink
Teach EnsureWalletIsUnlocked() to accept unlock for anon only
Browse files Browse the repository at this point in the history
Add an optional bool paramater to `EnsureWalletIsUnlocked()` that
defaults to `false` (current bahavior). If passed `true`, then only
require a partial unlock.
  • Loading branch information
Fuzzbawls committed Apr 26, 2018
1 parent 3809ec4 commit 38f226e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

using namespace std;

void EnsureWalletIsUnlocked();
void EnsureWalletIsUnlocked(bool fAllowAnonOnly);

std::string static EncodeDumpTime(int64_t nTime)
{
Expand Down
2 changes: 1 addition & 1 deletion src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extern std::string HelpRequiringPassphrase();
extern std::string HelpExampleCli(std::string methodname, std::string args);
extern std::string HelpExampleRpc(std::string methodname, std::string args);

extern void EnsureWalletIsUnlocked();
extern void EnsureWalletIsUnlocked(bool fAllowAnonOnly = false);

extern UniValue getconnectioncount(const UniValue& params, bool fHelp); // in rpcnet.cpp
extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
Expand Down
24 changes: 9 additions & 15 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ std::string HelpRequiringPassphrase()
return pwalletMain && pwalletMain->IsCrypted() ? "\nRequires wallet passphrase to be set with walletpassphrase call." : "";
}

void EnsureWalletIsUnlocked()
void EnsureWalletIsUnlocked(bool fAllowAnonOnly)
{
if (pwalletMain->IsLocked() || pwalletMain->fWalletUnlockAnonymizeOnly)
if (pwalletMain->IsLocked() || (!fAllowAnonOnly && pwalletMain->fWalletUnlockAnonymizeOnly))
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
}

Expand Down Expand Up @@ -2536,8 +2536,7 @@ UniValue getzerocoinbalance(const UniValue& params, bool fHelp)

LOCK2(cs_main, pwalletMain->cs_wallet);

if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked(true);

UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("Total", ValueFromAmount(pwalletMain->GetZerocoinBalance(false))));
Expand Down Expand Up @@ -2568,8 +2567,7 @@ UniValue listmintedzerocoins(const UniValue& params, bool fHelp)

LOCK2(cs_main, pwalletMain->cs_wallet);

if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked(true);

CWalletDB walletdb(pwalletMain->strWalletFile);
set<CMintMeta> setMints = pwalletMain->zpivTracker->ListMints(true, false, true);
Expand Down Expand Up @@ -2604,8 +2602,7 @@ UniValue listzerocoinamounts(const UniValue& params, bool fHelp)

LOCK2(cs_main, pwalletMain->cs_wallet);

if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked(true);

CWalletDB walletdb(pwalletMain->strWalletFile);
set<CMintMeta> setMints = pwalletMain->zpivTracker->ListMints(true, true, true);
Expand Down Expand Up @@ -2646,8 +2643,7 @@ UniValue listspentzerocoins(const UniValue& params, bool fHelp)

LOCK2(cs_main, pwalletMain->cs_wallet);

if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked(true);

CWalletDB walletdb(pwalletMain->strWalletFile);
list<CBigNum> listPubCoin = walletdb.ListSpentCoinsSerial();
Expand Down Expand Up @@ -2715,8 +2711,7 @@ UniValue mintzerocoin(const UniValue& params, bool fHelp)
if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE))
throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance.");

if (pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked(true);

CAmount nAmount = params[0].get_int() * COIN;

Expand Down Expand Up @@ -3044,6 +3039,7 @@ UniValue getarchivedzerocoin(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);

EnsureWalletIsUnlocked();

CWalletDB walletdb(pwalletMain->strWalletFile);
list<CZerocoinMint> listMints = walletdb.ListArchivedZerocoins();
list<CDeterministicMint> listDMints = walletdb.ListArchivedDeterministicMints();
Expand Down Expand Up @@ -3258,9 +3254,7 @@ UniValue reconsiderzerocoins(const UniValue& params, bool fHelp)

LOCK2(cs_main, pwalletMain->cs_wallet);

if(pwalletMain->IsLocked())
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED,
"Error: Please enter the wallet passphrase with walletpassphrase first.");
EnsureWalletIsUnlocked(true);

list<CZerocoinMint> listMints;
list<CDeterministicMint> listDMints;
Expand Down

0 comments on commit 38f226e

Please sign in to comment.