aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-04-25 19:30:28 +0200
committerPieter Wuille <pieterw@google.com>2013-04-25 19:36:10 +0200
commit360cfe142c552ac5c4d904a1e970390188151ca8 (patch)
tree4e8232b61d597b9720cbb98a54d07690324b6c3b /src/wallet.cpp
parent77a1e12eed5fc66dce16584696f54988a8c2bf4e (diff)
Allow the default key to be unavailable
This solves the issue where no default key can be added after -salvagewallet.
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index c7eb4f74e8..0672a36690 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -457,17 +457,19 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
return false;
#ifndef QT_GUI
// If default receiving address gets used, replace it with a new one
- CScript scriptDefaultKey;
- scriptDefaultKey.SetDestination(vchDefaultKey.GetID());
- BOOST_FOREACH(const CTxOut& txout, wtx.vout)
- {
- if (txout.scriptPubKey == scriptDefaultKey)
+ if (vchDefaultKey.IsValid()) {
+ CScript scriptDefaultKey;
+ scriptDefaultKey.SetDestination(vchDefaultKey.GetID());
+ BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
- CPubKey newDefaultKey;
- if (GetKeyFromPool(newDefaultKey, false))
+ if (txout.scriptPubKey == scriptDefaultKey)
{
- SetDefaultKey(newDefaultKey);
- SetAddressBookName(vchDefaultKey.GetID(), "");
+ CPubKey newDefaultKey;
+ if (GetKeyFromPool(newDefaultKey, false))
+ {
+ SetDefaultKey(newDefaultKey);
+ SetAddressBookName(vchDefaultKey.GetID(), "");
+ }
}
}
}
@@ -1199,8 +1201,8 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
// post-backup change.
// Reserve a new key pair from key pool
- CPubKey vchPubKey = reservekey.GetReservedKey();
- // assert(mapKeys.count(vchPubKey));
+ CPubKey vchPubKey;
+ assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked
// Fill a vout to ourself
// TODO: pass in scriptChange instead of reservekey so
@@ -1737,7 +1739,7 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
return ret;
}
-CPubKey CReserveKey::GetReservedKey()
+bool CReserveKey::GetReservedKey(CPubKey& pubkey)
{
if (nIndex == -1)
{
@@ -1745,14 +1747,17 @@ CPubKey CReserveKey::GetReservedKey()
pwallet->ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex != -1)
vchPubKey = keypool.vchPubKey;
- else
- {
- printf("CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!");
- vchPubKey = pwallet->vchDefaultKey;
+ else {
+ if (pwallet->vchDefaultKey.IsValid()) {
+ printf("CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!");
+ vchPubKey = pwallet->vchDefaultKey;
+ } else
+ return false;
}
}
assert(vchPubKey.IsValid());
- return vchPubKey;
+ pubkey = vchPubKey;
+ return true;
}
void CReserveKey::KeepKey()