Skip to content

Commit

Permalink
RPC: optional size parameter for keypoolrefill
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranz5 committed May 19, 2014
1 parent a683c5b commit d3c2482
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]);
if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true);
if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
if (strMethod == "keypoolrefill" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "sendalert" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "sendalert" && n > 3) ConvertTo<boost::int64_t>(params[3]);
if (strMethod == "sendalert" && n > 4) ConvertTo<boost::int64_t>(params[4]);
Expand Down
17 changes: 12 additions & 5 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", fTestNet));
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
if (pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
Expand Down Expand Up @@ -1313,17 +1313,24 @@ Value backupwallet(const Array& params, bool fHelp)

Value keypoolrefill(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 0)
if (fHelp || params.size() > 1)
throw runtime_error(
"keypoolrefill\n"
"keypoolrefill [new-size]\n"
"Fills the keypool."
+ HelpRequiringPassphrase());

unsigned int nSize = max(GetArg("-keypool", 100), 0LL);
if (params.size() > 0) {
if (params[0].get_int() < 0)
throw JSONRPCError(-8, "Invalid parameter, expected valid size");
nSize = (unsigned int) params[0].get_int();
}

EnsureWalletIsUnlocked();

pwalletMain->TopUpKeyPool();
pwalletMain->TopUpKeyPool(nSize);

if (pwalletMain->GetKeyPoolSize() < GetArg("-keypool", 100))
if (pwalletMain->GetKeyPoolSize() < nSize)
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");

return Value::null;
Expand Down
10 changes: 8 additions & 2 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ bool CWallet::NewKeyPool()
return true;
}

bool CWallet::TopUpKeyPool()
bool CWallet::TopUpKeyPool(unsigned int nSize)
{
{
LOCK(cs_wallet);
Expand All @@ -1816,7 +1816,13 @@ bool CWallet::TopUpKeyPool()
CWalletDB walletdb(strWalletFile);

// Top up key pool
unsigned int nTargetSize = max(GetArg("-keypool", 100), 0LL);
unsigned int nTargetSize;

if (nSize > 0)
nTargetSize = nSize;
else
nTargetSize = max(GetArg("-keypool", 100), 0LL);

while (setKeyPool.size() < (nTargetSize + 1))
{
int64 nEnd = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CWallet : public CCryptoKeyStore
std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);

bool NewKeyPool();
bool TopUpKeyPool();
bool TopUpKeyPool(unsigned int nSize = 0);
int64 AddReserveKey(const CKeyPool& keypool);
void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
void KeepKey(int64 nIndex);
Expand Down Expand Up @@ -281,7 +281,7 @@ class CWallet : public CCryptoKeyStore
}
}

int GetKeyPoolSize()
unsigned int GetKeyPoolSize()
{
return setKeyPool.size();
}
Expand Down

0 comments on commit d3c2482

Please sign in to comment.