X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.cpp;h=5b88f387c7d285b169f2c71788cee061cccb0055;hb=ae3d0aba158d0a38c33d687e5473d688fbcb903d;hp=f8963367738c4c7d0101500e157b8fbcba9ca19e;hpb=fbaee7a8533b23d846ee16837320f709c4e83d47;p=novacoin.git diff --git a/src/wallet.cpp b/src/wallet.cpp index f896336..5b88f38 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()); } #endif // Notify UI @@ -967,16 +960,33 @@ 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); return true; } + +bool CWallet::SetAddressBookName(const string& strAddress, const string& strName) +{ + mapAddressBook[strAddress] = strName; + if (!fFileBacked) + return false; + return CWalletDB(strWalletFile).WriteName(strAddress, strName); +} + +bool CWallet::DelAddressBookName(const string& strAddress) +{ + mapAddressBook.erase(strAddress); + if (!fFileBacked) + return false; + return CWalletDB(strWalletFile).EraseName(strAddress); +} + + void CWallet::PrintWallet(const CBlock& block) { CRITICAL_BLOCK(cs_mapWallet) @@ -1004,6 +1014,17 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx) return false; } +bool CWallet::SetDefaultKey(const std::vector &vchPubKey) +{ + if (fFileBacked) + { + if (!CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey)) + return false; + } + vchDefaultKey = vchPubKey; + return true; +} + bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut) { if (!pwallet->fFileBacked) @@ -1070,65 +1091,6 @@ void CWallet::ReturnKey(int64 nIndex) printf("keypool return %"PRI64d"\n", nIndex); } -bool CWallet::SetAddressBookName(const std::string& strAddress, const std::string& strName) -{ - if (!fFileBacked) - return false; - if(CWalletDB(strWalletFile).WriteName(strAddress, strName)) - { - CRITICAL_BLOCK(cs_mapAddressBook) - mapAddressBook[strAddress] = strName; - return true; - } - else - { - return false; - } -} - -bool CWallet::EraseAddressBookName(const std::string& strAddress) -{ - if (!fFileBacked) - return false; - if(CWalletDB(strWalletFile).EraseName(strAddress)) - { - CRITICAL_BLOCK(cs_mapAddressBook) - mapAddressBook.erase(strAddress); - return true; - } - else - { - return false; - } -} - - -std::string CWallet::GetDefaultAddress() -{ - if (!fFileBacked) - return false; - std::vector vchPubKey; - if (CWalletDB(strWalletFile, "r").ReadDefaultKey(vchPubKey)) - { - return PubKeyToAddress(vchPubKey); - } - else - { - return ""; - } -} - -bool CWallet::SetDefaultAddress(const std::string& strAddress) -{ - uint160 hash160; - if (!AddressToHash160(strAddress, hash160)) - return false; - if (!mapPubKeys.count(hash160)) - return false; - return CWalletDB(strWalletFile).WriteDefaultKey(mapPubKeys[hash160]); -} - - vector CWallet::GetKeyFromKeyPool() { int64 nIndex = 0; @@ -1174,3 +1136,4 @@ void CReserveKey::ReturnKey() nIndex = -1; vchPubKey.clear(); } +