mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
wallet: Get rid of fFileBacked
Instead, CWalletDB() with a dummy handle will just give you a no-op database in which writes always succeeds and reads always fail. CDB already had functionality for this, so just use that.
This commit is contained in:
@@ -180,8 +180,6 @@ bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey)
|
||||
if (HaveWatchOnly(script))
|
||||
RemoveWatchOnly(script);
|
||||
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
if (!IsCrypted()) {
|
||||
return CWalletDB(*dbw).WriteKey(pubkey,
|
||||
secret.GetPrivKey(),
|
||||
@@ -195,8 +193,6 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
|
||||
{
|
||||
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret))
|
||||
return false;
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
if (pwalletdbEncryption)
|
||||
@@ -240,8 +236,6 @@ bool CWallet::AddCScript(const CScript& redeemScript)
|
||||
{
|
||||
if (!CCryptoKeyStore::AddCScript(redeemScript))
|
||||
return false;
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
return CWalletDB(*dbw).WriteCScript(Hash160(redeemScript), redeemScript);
|
||||
}
|
||||
|
||||
@@ -268,8 +262,6 @@ bool CWallet::AddWatchOnly(const CScript& dest)
|
||||
const CKeyMetadata& meta = mapKeyMetadata[CScriptID(dest)];
|
||||
UpdateTimeFirstKey(meta.nCreateTime);
|
||||
NotifyWatchonlyChanged(true);
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
return CWalletDB(*dbw).WriteWatchOnly(dest, meta);
|
||||
}
|
||||
|
||||
@@ -286,9 +278,8 @@ bool CWallet::RemoveWatchOnly(const CScript &dest)
|
||||
return false;
|
||||
if (!HaveWatchOnly())
|
||||
NotifyWatchonlyChanged(false);
|
||||
if (fFileBacked)
|
||||
if (!CWalletDB(*dbw).EraseWatchOnly(dest))
|
||||
return false;
|
||||
if (!CWalletDB(*dbw).EraseWatchOnly(dest))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -385,7 +376,6 @@ bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn,
|
||||
if (nVersion > nWalletMaxVersion)
|
||||
nWalletMaxVersion = nVersion;
|
||||
|
||||
if (fFileBacked)
|
||||
{
|
||||
CWalletDB* pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB(*dbw);
|
||||
if (nWalletVersion > 40000)
|
||||
@@ -594,24 +584,19 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
|
||||
if (fFileBacked)
|
||||
{
|
||||
assert(!pwalletdbEncryption);
|
||||
pwalletdbEncryption = new CWalletDB(*dbw);
|
||||
if (!pwalletdbEncryption->TxnBegin()) {
|
||||
delete pwalletdbEncryption;
|
||||
pwalletdbEncryption = NULL;
|
||||
return false;
|
||||
}
|
||||
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
|
||||
assert(!pwalletdbEncryption);
|
||||
pwalletdbEncryption = new CWalletDB(*dbw);
|
||||
if (!pwalletdbEncryption->TxnBegin()) {
|
||||
delete pwalletdbEncryption;
|
||||
pwalletdbEncryption = NULL;
|
||||
return false;
|
||||
}
|
||||
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
|
||||
|
||||
if (!EncryptKeys(_vMasterKey))
|
||||
{
|
||||
if (fFileBacked) {
|
||||
pwalletdbEncryption->TxnAbort();
|
||||
delete pwalletdbEncryption;
|
||||
}
|
||||
pwalletdbEncryption->TxnAbort();
|
||||
delete pwalletdbEncryption;
|
||||
// We now probably have half of our keys encrypted in memory, and half not...
|
||||
// die and let the user reload the unencrypted wallet.
|
||||
assert(false);
|
||||
@@ -620,19 +605,16 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
// Encryption was introduced in version 0.4.0
|
||||
SetMinVersion(FEATURE_WALLETCRYPT, pwalletdbEncryption, true);
|
||||
|
||||
if (fFileBacked)
|
||||
{
|
||||
if (!pwalletdbEncryption->TxnCommit()) {
|
||||
delete pwalletdbEncryption;
|
||||
// We now have keys encrypted in memory, but not on disk...
|
||||
// die to avoid confusion and let the user reload the unencrypted wallet.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if (!pwalletdbEncryption->TxnCommit()) {
|
||||
delete pwalletdbEncryption;
|
||||
pwalletdbEncryption = NULL;
|
||||
// We now have keys encrypted in memory, but not on disk...
|
||||
// die to avoid confusion and let the user reload the unencrypted wallet.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
delete pwalletdbEncryption;
|
||||
pwalletdbEncryption = NULL;
|
||||
|
||||
Lock();
|
||||
Unlock(strWalletPassphrase);
|
||||
|
||||
@@ -2816,8 +2798,6 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
|
||||
|
||||
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
{
|
||||
if (!fFileBacked)
|
||||
return DB_LOAD_OK;
|
||||
fFirstRunRet = false;
|
||||
DBErrors nLoadWalletRet = CWalletDB(*dbw,"cr+").LoadWallet(this);
|
||||
if (nLoadWalletRet == DB_NEED_REWRITE)
|
||||
@@ -2843,8 +2823,6 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
|
||||
DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
|
||||
{
|
||||
if (!fFileBacked)
|
||||
return DB_LOAD_OK;
|
||||
AssertLockHeld(cs_wallet); // mapWallet
|
||||
vchDefaultKey = CPubKey();
|
||||
DBErrors nZapSelectTxRet = CWalletDB(*dbw,"cr+").ZapSelectTx(vHashIn, vHashOut);
|
||||
@@ -2873,8 +2851,6 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
||||
|
||||
DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
{
|
||||
if (!fFileBacked)
|
||||
return DB_LOAD_OK;
|
||||
vchDefaultKey = CPubKey();
|
||||
DBErrors nZapWalletTxRet = CWalletDB(*dbw,"cr+").ZapWalletTx(vWtx);
|
||||
if (nZapWalletTxRet == DB_NEED_REWRITE)
|
||||
@@ -2909,8 +2885,6 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
|
||||
}
|
||||
NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address) != ISMINE_NO,
|
||||
strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) );
|
||||
if (!fFileBacked)
|
||||
return false;
|
||||
if (!strPurpose.empty() && !CWalletDB(*dbw).WritePurpose(CBitcoinAddress(address).ToString(), strPurpose))
|
||||
return false;
|
||||
return CWalletDB(*dbw).WriteName(CBitcoinAddress(address).ToString(), strName);
|
||||
@@ -2921,33 +2895,25 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
|
||||
{
|
||||
LOCK(cs_wallet); // mapAddressBook
|
||||
|
||||
if(fFileBacked)
|
||||
// Delete destdata tuples associated with address
|
||||
std::string strAddress = CBitcoinAddress(address).ToString();
|
||||
BOOST_FOREACH(const PAIRTYPE(std::string, std::string) &item, mapAddressBook[address].destdata)
|
||||
{
|
||||
// Delete destdata tuples associated with address
|
||||
std::string strAddress = CBitcoinAddress(address).ToString();
|
||||
BOOST_FOREACH(const PAIRTYPE(std::string, std::string) &item, mapAddressBook[address].destdata)
|
||||
{
|
||||
CWalletDB(*dbw).EraseDestData(strAddress, item.first);
|
||||
}
|
||||
CWalletDB(*dbw).EraseDestData(strAddress, item.first);
|
||||
}
|
||||
mapAddressBook.erase(address);
|
||||
}
|
||||
|
||||
NotifyAddressBookChanged(this, address, "", ::IsMine(*this, address) != ISMINE_NO, "", CT_DELETED);
|
||||
|
||||
if (!fFileBacked)
|
||||
return false;
|
||||
CWalletDB(*dbw).ErasePurpose(CBitcoinAddress(address).ToString());
|
||||
return CWalletDB(*dbw).EraseName(CBitcoinAddress(address).ToString());
|
||||
}
|
||||
|
||||
bool CWallet::SetDefaultKey(const CPubKey &vchPubKey)
|
||||
{
|
||||
if (fFileBacked)
|
||||
{
|
||||
if (!CWalletDB(*dbw).WriteDefaultKey(vchPubKey))
|
||||
return false;
|
||||
}
|
||||
if (!CWalletDB(*dbw).WriteDefaultKey(vchPubKey))
|
||||
return false;
|
||||
vchDefaultKey = vchPubKey;
|
||||
return true;
|
||||
}
|
||||
@@ -3081,11 +3047,8 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool int
|
||||
void CWallet::KeepKey(int64_t nIndex)
|
||||
{
|
||||
// Remove from key pool
|
||||
if (fFileBacked)
|
||||
{
|
||||
CWalletDB walletdb(*dbw);
|
||||
walletdb.ErasePool(nIndex);
|
||||
}
|
||||
CWalletDB walletdb(*dbw);
|
||||
walletdb.ErasePool(nIndex);
|
||||
LogPrintf("keypool keep %d\n", nIndex);
|
||||
}
|
||||
|
||||
@@ -3597,8 +3560,6 @@ bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, co
|
||||
return false;
|
||||
|
||||
mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
return CWalletDB(*dbw).WriteDestData(CBitcoinAddress(dest).ToString(), key, value);
|
||||
}
|
||||
|
||||
@@ -3606,8 +3567,6 @@ bool CWallet::EraseDestData(const CTxDestination &dest, const std::string &key)
|
||||
{
|
||||
if (!mapAddressBook[dest].destdata.erase(key))
|
||||
return false;
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
return CWalletDB(*dbw).EraseDestData(CBitcoinAddress(dest).ToString(), key);
|
||||
}
|
||||
|
||||
@@ -3979,8 +3938,6 @@ bool CWallet::ParameterInteraction()
|
||||
|
||||
bool CWallet::BackupWallet(const std::string& strDest)
|
||||
{
|
||||
if (!fFileBacked)
|
||||
return false;
|
||||
return dbw->Backup(strDest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user