From 16163ca1b076ee1e6e2c99cc67695e6e654a3293 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 18 Aug 2013 21:00:35 +0400 Subject: [PATCH] RPC: optional size parameter for keypoolrefill Users are now permitted to increase the keypool size at runtime. --- src/bitcoinrpc.cpp | 1 + src/rpcwallet.cpp | 17 ++++++++++++----- src/wallet.cpp | 9 +++++++-- src/wallet.h | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 5c18452..d9ed3ac 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1219,6 +1219,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 1) ConvertTo(params[1]); if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); + if (strMethod == "keypoolrefill" && n > 0) ConvertTo(params[0]); return params; } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 5a81a07..4550667 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -85,7 +85,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)); @@ -1337,17 +1337,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; diff --git a/src/wallet.cpp b/src/wallet.cpp index df32644..e49c215 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1880,7 +1880,7 @@ bool CWallet::NewKeyPool() return true; } -bool CWallet::TopUpKeyPool() +bool CWallet::TopUpKeyPool(unsigned int nSize) { { LOCK(cs_wallet); @@ -1891,7 +1891,12 @@ 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; diff --git a/src/wallet.h b/src/wallet.h index 39cd1ce..d6cf174 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -199,7 +199,7 @@ public: 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); @@ -296,7 +296,7 @@ public: } } - int GetKeyPoolSize() + unsigned int GetKeyPoolSize() { return setKeyPool.size(); } -- 1.7.1