Skip to content

Commit f914c7a

Browse files
author
Philip Kaufmann
committed
rpcwallet: use EnsureWalletIsUnlocked() where possible
- replaces a pwalletMain->IsLocked() check - in keypoolrefill init kpSize to 0 as we have the logic to determine max kpSize in pwalletMain->TopUpKeyPool() anyway
1 parent 6694f4a commit f914c7a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/rpcwallet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
334334
if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty())
335335
wtx.mapValue["to"] = params[3].get_str();
336336

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

340339
string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx);
341340
if (strError != "")
@@ -1657,15 +1656,15 @@ Value keypoolrefill(const Array& params, bool fHelp)
16571656
+ HelpExampleRpc("keypoolrefill", "")
16581657
);
16591658

1660-
unsigned int kpSize = max(GetArg("-keypool", 100), (int64_t) 0);
1659+
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
1660+
unsigned int kpSize = 0;
16611661
if (params.size() > 0) {
16621662
if (params[0].get_int() < 0)
1663-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size");
1664-
kpSize = (unsigned int) params[0].get_int();
1663+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
1664+
kpSize = (unsigned int)params[0].get_int();
16651665
}
16661666

16671667
EnsureWalletIsUnlocked();
1668-
16691668
pwalletMain->TopUpKeyPool(kpSize);
16701669

16711670
if (pwalletMain->GetKeyPoolSize() < kpSize)

0 commit comments

Comments
 (0)