diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2011-07-05 17:42:44 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2011-07-05 17:42:44 +0200 |
commit | e9f61c8787af99c49678ba4bc182b24b8fdba0c4 (patch) | |
tree | d6ba403f7589fac5fa685998891f74b9bed19295 /src/wallet.cpp | |
parent | 9390431ce49893cbdf23846edb4bdf72b3d4e830 (diff) |
Fix synchronization of default key
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r-- | src/wallet.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index e54bbb3f45..6ef75ef27f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -98,14 +98,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) BOOST_FOREACH(const CTxOut& txout, wtx.vout) { if (txout.scriptPubKey == scriptDefaultKey) - { - if (!fFileBacked) - continue; - CWalletDB walletdb(strWalletFile); - vchDefaultKey = GetKeyFromKeyPool(); - walletdb.WriteDefaultKey(vchDefaultKey); - walletdb.WriteName(PubKeyToAddress(vchDefaultKey), ""); - } + SetDefaultKey(GetKeyFromKeyPool()); } // Notify UI @@ -967,10 +960,9 @@ bool CWallet::LoadWallet(bool& fFirstRunRet) // Create new default key RandAddSeedPerfmon(); - vchDefaultKey = GetKeyFromKeyPool(); + SetDefaultKey(GetKeyFromKeyPool()); if (!SetAddressBookName(PubKeyToAddress(vchDefaultKey), "")) return false; - CWalletDB(strWalletFile).WriteDefaultKey(vchDefaultKey); } CreateThread(ThreadFlushWalletDB, &strWalletFile); @@ -1022,6 +1014,17 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx) return false; } +bool CWallet::SetDefaultKey(const std::vector<unsigned char> &vchPubKey) +{ + if (fFileBacked) + { + if (!CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey)) + return false; + } + vchDefaultKey = vchPubKey; + return true; +} + bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut) { if (!pwallet->fFileBacked) @@ -1133,3 +1136,4 @@ void CReserveKey::ReturnKey() nIndex = -1; vchPubKey.clear(); } + |