diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-08-12 16:32:07 -0400 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-09-01 10:12:59 -0400 |
commit | 7db3b75b3e38c2088596f49cb51fe1c9c7e8b433 (patch) | |
tree | 9484ca192506ab645ca1764d5993bd6ddce88b44 /src/rpc.cpp | |
parent | f662cefd8552f07548dcca9dcf84a952650fab6f (diff) | |
download | bitcoin-7db3b75b3e38c2088596f49cb51fe1c9c7e8b433.tar.xz |
Logic running with -keypool=0 was wrong (empty keys were being returned). Fixes #445
Renames GetOrReuseKeyFromKeyPool to GetKeyFromPool, with fAllowReuse arg and bool result.
Diffstat (limited to 'src/rpc.cpp')
-rw-r--r-- | src/rpc.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp index 5eb5669acb..161606af3c 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -331,21 +331,20 @@ Value getnewaddress(const Array& params, bool fHelp) "If [account] is specified (recommended), it is added to the address book " "so payments received with the address will be credited to [account]."); - if (!pwalletMain->IsLocked()) - pwalletMain->TopUpKeyPool(); - - if (pwalletMain->GetKeyPoolSize() < 1) - throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); - // Parse the account first so we don't generate a key if there's an error string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); + if (!pwalletMain->IsLocked()) + pwalletMain->TopUpKeyPool(); + // Generate a new key that is added to wallet - CBitcoinAddress address(pwalletMain->GetOrReuseKeyFromPool()); + std::vector<unsigned char> newKey; + if (!pwalletMain->GetKeyFromPool(newKey, false)) + throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); + CBitcoinAddress address(newKey); - // This could be done in the same main CS as GetKeyFromKeyPool. pwalletMain->SetAddressBookName(address, strAccount); return address.ToString(); @@ -382,12 +381,9 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false) { if (pwalletMain->GetKeyPoolSize() < 1) { - if (bKeyUsed || bForceNew) + if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) throw JSONRPCError(-12, "Error: Keypool ran out, please call topupkeypool first"); - } - else - { - account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool(); + pwalletMain->SetAddressBookName(CBitcoinAddress(account.vchPubKey), strAccount); walletdb.WriteAccount(strAccount, account); } |