Browse Source

Merge pull request #383 from sipa/syncdefault

Fix synchronization of default key
0.8 v0.3.24rc3
Jeff Garzik 14 years ago
parent
commit
e94010b239
  1. 2
      src/ui.cpp
  2. 24
      src/wallet.cpp
  3. 1
      src/wallet.h

2
src/ui.cpp

@ -240,7 +240,7 @@ void SetDefaultReceivingAddress(const string& strAddress)
return; return;
if (!mapPubKeys.count(hash160)) if (!mapPubKeys.count(hash160))
return; return;
CWalletDB(pwalletMain->strWalletFile).WriteDefaultKey(mapPubKeys[hash160]); pwalletMain->SetDefaultKey(mapPubKeys[hash160]);
pframeMain->m_textCtrlAddress->SetValue(strAddress); pframeMain->m_textCtrlAddress->SetValue(strAddress);
} }
} }

24
src/wallet.cpp

@ -98,14 +98,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
BOOST_FOREACH(const CTxOut& txout, wtx.vout) BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{ {
if (txout.scriptPubKey == scriptDefaultKey) if (txout.scriptPubKey == scriptDefaultKey)
{ SetDefaultKey(GetKeyFromKeyPool());
if (!fFileBacked)
continue;
CWalletDB walletdb(strWalletFile);
vchDefaultKey = GetKeyFromKeyPool();
walletdb.WriteDefaultKey(vchDefaultKey);
walletdb.WriteName(PubKeyToAddress(vchDefaultKey), "");
}
} }
// Notify UI // Notify UI
@ -967,10 +960,9 @@ bool CWallet::LoadWallet(bool& fFirstRunRet)
// Create new default key // Create new default key
RandAddSeedPerfmon(); RandAddSeedPerfmon();
vchDefaultKey = GetKeyFromKeyPool(); SetDefaultKey(GetKeyFromKeyPool());
if (!SetAddressBookName(PubKeyToAddress(vchDefaultKey), "")) if (!SetAddressBookName(PubKeyToAddress(vchDefaultKey), ""))
return false; return false;
CWalletDB(strWalletFile).WriteDefaultKey(vchDefaultKey);
} }
CreateThread(ThreadFlushWalletDB, &strWalletFile); CreateThread(ThreadFlushWalletDB, &strWalletFile);
@ -1022,6 +1014,17 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
return false; 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) bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut)
{ {
if (!pwallet->fFileBacked) if (!pwallet->fFileBacked)
@ -1133,3 +1136,4 @@ void CReserveKey::ReturnKey()
nIndex = -1; nIndex = -1;
vchPubKey.clear(); vchPubKey.clear();
} }

1
src/wallet.h

@ -176,6 +176,7 @@ public:
bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
bool SetDefaultKey(const std::vector<unsigned char> &vchPubKey);
}; };

Loading…
Cancel
Save