changeset 743:379d94bf664e draft

Fix synchronization of default key
author Pieter Wuille <pieter.wuille@gmail.com>
date Tue, 05 Jul 2011 17:42:44 +0200
parents da8006aafefc
children 779e47d94589
files src/ui.cpp src/wallet.cpp src/wallet.h
diffstat 3 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -240,7 +240,7 @@
             return;
         if (!mapPubKeys.count(hash160))
             return;
-        CWalletDB(pwalletMain->strWalletFile).WriteDefaultKey(mapPubKeys[hash160]);
+        pwalletMain->SetDefaultKey(mapPubKeys[hash160]);
         pframeMain->m_textCtrlAddress->SetValue(strAddress);
     }
 }
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -98,14 +98,7 @@
         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 @@
         // 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 @@
     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 @@
     nIndex = -1;
     vchPubKey.clear();
 }
+
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -176,6 +176,7 @@
 
     bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
 
+    bool SetDefaultKey(const std::vector<unsigned char> &vchPubKey);
 };