aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-08-12 16:32:07 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-09-01 10:12:59 -0400
commit7db3b75b3e38c2088596f49cb51fe1c9c7e8b433 (patch)
tree9484ca192506ab645ca1764d5993bd6ddce88b44 /src/wallet.cpp
parentf662cefd8552f07548dcca9dcf84a952650fab6f (diff)
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/wallet.cpp')
-rw-r--r--src/wallet.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 1daec98d34..e861416e50 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -268,8 +268,12 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
{
if (txout.scriptPubKey == scriptDefaultKey)
{
- SetDefaultKey(GetOrReuseKeyFromPool());
- SetAddressBookName(CBitcoinAddress(vchDefaultKey), "");
+ std::vector<unsigned char> newDefaultKey;
+ if (GetKeyFromPool(newDefaultKey, false))
+ {
+ SetDefaultKey(newDefaultKey);
+ SetAddressBookName(CBitcoinAddress(vchDefaultKey), "");
+ }
}
}
@@ -1126,7 +1130,10 @@ int CWallet::LoadWallet(bool& fFirstRunRet)
// Create new keyUser and set as default key
RandAddSeedPerfmon();
- SetDefaultKey(GetOrReuseKeyFromPool());
+ std::vector<unsigned char> newDefaultKey;
+ if (!GetKeyFromPool(newDefaultKey, false))
+ return DB_LOAD_FAIL;
+ SetDefaultKey(newDefaultKey);
if (!SetAddressBookName(CBitcoinAddress(vchDefaultKey), ""))
return DB_LOAD_FAIL;
}
@@ -1269,15 +1276,25 @@ void CWallet::ReturnKey(int64 nIndex)
printf("keypool return %"PRI64d"\n", nIndex);
}
-vector<unsigned char> CWallet::GetOrReuseKeyFromPool()
+bool CWallet::GetKeyFromPool(vector<unsigned char>& result, bool fAllowReuse)
{
int64 nIndex = 0;
CKeyPool keypool;
ReserveKeyFromKeyPool(nIndex, keypool);
- if(nIndex == -1)
- return vchDefaultKey;
+ if (nIndex == -1)
+ {
+ if (fAllowReuse && !vchDefaultKey.empty())
+ {
+ result = vchDefaultKey;
+ return true;
+ }
+ if (IsLocked()) return false;
+ result = GenerateNewKey();
+ return true;
+ }
KeepKey(nIndex);
- return keypool.vchPubKey;
+ result = keypool.vchPubKey;
+ return true;
}
int64 CWallet::GetOldestKeyPoolTime()