diff options
| author | Gavin Andresen <[email protected]> | 2011-09-01 12:01:29 -0700 |
|---|---|---|
| committer | Gavin Andresen <[email protected]> | 2011-09-01 12:01:29 -0700 |
| commit | 783c636c73182731ca12e6af67516767a989da66 (patch) | |
| tree | 6e160958804c3f0b968a295b3bec7d2ed947b220 /src/rpc.cpp | |
| parent | Merge branch 'code-cleanup' of git://github.com/muggenhor/bitcoin (diff) | |
| parent | obtain cs_wallet mutex to protect vchDefaultKey (diff) | |
| download | discoin-783c636c73182731ca12e6af67516767a989da66.tar.xz discoin-783c636c73182731ca12e6af67516767a989da66.zip | |
Merge pull request #467 from gavinandresen/keypoolzero
Logic running with -keypool=0 was wrong (empty keys were being returned).
Diffstat (limited to 'src/rpc.cpp')
| -rw-r--r-- | src/rpc.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp index 5eb5669ac..ec2bb2a97 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) - throw JSONRPCError(-12, "Error: Keypool ran out, please call topupkeypool first"); - } - else - { - account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool(); + if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) + throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); + pwalletMain->SetAddressBookName(CBitcoinAddress(account.vchPubKey), strAccount); walletdb.WriteAccount(strAccount, account); } |