Browse Source

Merge pull request #2776 from jgarzik/keypoolsize

RPC: keypoolrefill now permits optional size parameter, to bump keypool
0.10
Gavin Andresen 11 years ago
parent
commit
4323bfeafd
  1. 1
      src/bitcoinrpc.cpp
  2. 17
      src/rpcwallet.cpp
  3. 9
      src/wallet.cpp
  4. 4
      src/wallet.h

1
src/bitcoinrpc.cpp

@ -1200,6 +1200,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]); if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "keypoolrefill" && n > 0) ConvertTo<boost::int64_t>(params[0]);
return params; return params;
} }

17
src/rpcwallet.cpp

@ -81,7 +81,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", TestNet())); obj.push_back(Pair("testnet", TestNet()));
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); 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))); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
if (pwalletMain->IsCrypted()) if (pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
@ -1253,17 +1253,24 @@ Value backupwallet(const Array& params, bool fHelp)
Value keypoolrefill(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( throw runtime_error(
"keypoolrefill\n" "keypoolrefill [new-size]\n"
"Fills the keypool." "Fills the keypool."
+ HelpRequiringPassphrase()); + HelpRequiringPassphrase());
unsigned int kpSize = max(GetArg("-keypool", 100), 0LL);
if (params.size() > 0) {
if (params[0].get_int() < 0)
throw JSONRPCError(-8, "Invalid parameter, expected valid size");
kpSize = (unsigned int) params[0].get_int();
}
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
pwalletMain->TopUpKeyPool(); pwalletMain->TopUpKeyPool(kpSize);
if (pwalletMain->GetKeyPoolSize() < GetArg("-keypool", 100)) if (pwalletMain->GetKeyPoolSize() < kpSize)
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
return Value::null; return Value::null;

9
src/wallet.cpp

@ -1551,7 +1551,7 @@ bool CWallet::NewKeyPool()
return true; return true;
} }
bool CWallet::TopUpKeyPool() bool CWallet::TopUpKeyPool(unsigned int kpSize)
{ {
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1562,7 +1562,12 @@ bool CWallet::TopUpKeyPool()
CWalletDB walletdb(strWalletFile); CWalletDB walletdb(strWalletFile);
// Top up key pool // Top up key pool
unsigned int nTargetSize = max(GetArg("-keypool", 100), 0LL); unsigned int nTargetSize;
if (kpSize > 0)
nTargetSize = kpSize;
else
nTargetSize = max(GetArg("-keypool", 100), 0LL);
while (setKeyPool.size() < (nTargetSize + 1)) while (setKeyPool.size() < (nTargetSize + 1))
{ {
int64 nEnd = 1; int64 nEnd = 1;

4
src/wallet.h

@ -202,7 +202,7 @@ public:
std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
bool NewKeyPool(); bool NewKeyPool();
bool TopUpKeyPool(); bool TopUpKeyPool(unsigned int kpSize = 0);
int64 AddReserveKey(const CKeyPool& keypool); int64 AddReserveKey(const CKeyPool& keypool);
void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
void KeepKey(int64 nIndex); void KeepKey(int64 nIndex);
@ -299,7 +299,7 @@ public:
} }
} }
int GetKeyPoolSize() unsigned int GetKeyPoolSize()
{ {
return setKeyPool.size(); return setKeyPool.size();
} }

Loading…
Cancel
Save