Browse Source

Merge pull request #2566 from sipa/nodef

Allow the default key to be unavailable
0.8
Gavin Andresen 12 years ago
parent
commit
61a845dcb6
  1. 4
      src/init.cpp
  2. 5
      src/main.cpp
  3. 17
      src/wallet.cpp
  4. 2
      src/wallet.h

4
src/init.cpp

@ -966,12 +966,12 @@ bool AppInit2(boost::thread_group& threadGroup) @@ -966,12 +966,12 @@ bool AppInit2(boost::thread_group& threadGroup)
RandAddSeedPerfmon();
CPubKey newDefaultKey;
if (!pwalletMain->GetKeyFromPool(newDefaultKey, false))
strErrors << _("Cannot initialize keypool") << "\n";
if (pwalletMain->GetKeyFromPool(newDefaultKey, false)) {
pwalletMain->SetDefaultKey(newDefaultKey);
if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), ""))
strErrors << _("Cannot write default address") << "\n";
}
}
printf("%s", strErrors.str().c_str());
printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);

5
src/main.cpp

@ -4158,7 +4158,10 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey) @@ -4158,7 +4158,10 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
txNew.vin.resize(1);
txNew.vin[0].prevout.SetNull();
txNew.vout.resize(1);
txNew.vout[0].scriptPubKey << reservekey.GetReservedKey() << OP_CHECKSIG;
CPubKey pubkey;
if (!reservekey.GetReservedKey(pubkey))
return NULL;
txNew.vout[0].scriptPubKey << pubkey << OP_CHECKSIG;
// Add our coinbase tx as first transaction
pblock->vtx.push_back(txNew);

17
src/wallet.cpp

@ -462,6 +462,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) @@ -462,6 +462,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
return false;
#ifndef QT_GUI
// If default receiving address gets used, replace it with a new one
if (vchDefaultKey.IsValid()) {
CScript scriptDefaultKey;
scriptDefaultKey.SetDestination(vchDefaultKey.GetID());
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
@ -476,6 +477,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) @@ -476,6 +477,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
}
}
}
}
#endif
// since AddToWallet is called directly for self-originating transactions, check for consumption of own coins
WalletUpdateSpent(wtx);
@ -1204,8 +1206,8 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW @@ -1204,8 +1206,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
@ -1742,7 +1744,7 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings() @@ -1742,7 +1744,7 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
return ret;
}
CPubKey CReserveKey::GetReservedKey()
bool CReserveKey::GetReservedKey(CPubKey& pubkey)
{
if (nIndex == -1)
{
@ -1750,14 +1752,17 @@ CPubKey CReserveKey::GetReservedKey() @@ -1750,14 +1752,17 @@ CPubKey CReserveKey::GetReservedKey()
pwallet->ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex != -1)
vchPubKey = keypool.vchPubKey;
else
{
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()

2
src/wallet.h

@ -331,7 +331,7 @@ public: @@ -331,7 +331,7 @@ public:
}
void ReturnKey();
CPubKey GetReservedKey();
bool GetReservedKey(CPubKey &pubkey);
void KeepKey();
};

Loading…
Cancel
Save