aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2011-07-05 11:52:13 -0700
committerJeff Garzik <jgarzik@exmulti.com>2011-07-05 11:52:13 -0700
commite94010b2395694d56dd62a2cb956a40ef801a191 (patch)
treef16e8bd28503f79a5a639c0752e69590d5984d62
parentbb0d9ce2264c3b50d11850491c800654abffa1a5 (diff)
parente9f61c8787af99c49678ba4bc182b24b8fdba0c4 (diff)
Merge pull request #383 from sipa/syncdefaultv0.3.24rc3
Fix synchronization of default key
-rw-r--r--src/ui.cpp2
-rw-r--r--src/wallet.cpp24
-rw-r--r--src/wallet.h1
3 files changed, 16 insertions, 11 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index 2cbcfd5bd8..9b84fb9e6b 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -240,7 +240,7 @@ void SetDefaultReceivingAddress(const string& strAddress)
return;
if (!mapPubKeys.count(hash160))
return;
- CWalletDB(pwalletMain->strWalletFile).WriteDefaultKey(mapPubKeys[hash160]);
+ pwalletMain->SetDefaultKey(mapPubKeys[hash160]);
pframeMain->m_textCtrlAddress->SetValue(strAddress);
}
}
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();
}
+
diff --git a/src/wallet.h b/src/wallet.h
index bf7d8cc51f..7d9db97267 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -176,6 +176,7 @@ public:
bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
+ bool SetDefaultKey(const std::vector<unsigned char> &vchPubKey);
};