diff options
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r-- | src/wallet/walletdb.cpp | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 77cdfe7dd0..57261bb922 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -21,42 +21,42 @@ #include <boost/thread.hpp> // -// CWalletDB +// WalletBatch // -bool CWalletDB::WriteName(const std::string& strAddress, const std::string& strName) +bool WalletBatch::WriteName(const std::string& strAddress, const std::string& strName) { return WriteIC(std::make_pair(std::string("name"), strAddress), strName); } -bool CWalletDB::EraseName(const std::string& strAddress) +bool WalletBatch::EraseName(const std::string& strAddress) { // This should only be used for sending addresses, never for receiving addresses, // receiving addresses must always have an address book entry if they're not change return. return EraseIC(std::make_pair(std::string("name"), strAddress)); } -bool CWalletDB::WritePurpose(const std::string& strAddress, const std::string& strPurpose) +bool WalletBatch::WritePurpose(const std::string& strAddress, const std::string& strPurpose) { return WriteIC(std::make_pair(std::string("purpose"), strAddress), strPurpose); } -bool CWalletDB::ErasePurpose(const std::string& strAddress) +bool WalletBatch::ErasePurpose(const std::string& strAddress) { return EraseIC(std::make_pair(std::string("purpose"), strAddress)); } -bool CWalletDB::WriteTx(const CWalletTx& wtx) +bool WalletBatch::WriteTx(const CWalletTx& wtx) { return WriteIC(std::make_pair(std::string("tx"), wtx.GetHash()), wtx); } -bool CWalletDB::EraseTx(uint256 hash) +bool WalletBatch::EraseTx(uint256 hash) { return EraseIC(std::make_pair(std::string("tx"), hash)); } -bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta) +bool WalletBatch::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta) { if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta, false)) { return false; @@ -71,7 +71,7 @@ bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, c return WriteIC(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false); } -bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey, +bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta) { @@ -87,17 +87,17 @@ bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey, return true; } -bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) +bool WalletBatch::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) { return WriteIC(std::make_pair(std::string("mkey"), nID), kMasterKey, true); } -bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript) +bool WalletBatch::WriteCScript(const uint160& hash, const CScript& redeemScript) { return WriteIC(std::make_pair(std::string("cscript"), hash), redeemScript, false); } -bool CWalletDB::WriteWatchOnly(const CScript &dest, const CKeyMetadata& keyMeta) +bool WalletBatch::WriteWatchOnly(const CScript &dest, const CKeyMetadata& keyMeta) { if (!WriteIC(std::make_pair(std::string("watchmeta"), dest), keyMeta)) { return false; @@ -105,7 +105,7 @@ bool CWalletDB::WriteWatchOnly(const CScript &dest, const CKeyMetadata& keyMeta) return WriteIC(std::make_pair(std::string("watchs"), dest), '1'); } -bool CWalletDB::EraseWatchOnly(const CScript &dest) +bool WalletBatch::EraseWatchOnly(const CScript &dest) { if (!EraseIC(std::make_pair(std::string("watchmeta"), dest))) { return false; @@ -113,60 +113,60 @@ bool CWalletDB::EraseWatchOnly(const CScript &dest) return EraseIC(std::make_pair(std::string("watchs"), dest)); } -bool CWalletDB::WriteBestBlock(const CBlockLocator& locator) +bool WalletBatch::WriteBestBlock(const CBlockLocator& locator) { WriteIC(std::string("bestblock"), CBlockLocator()); // Write empty block locator so versions that require a merkle branch automatically rescan return WriteIC(std::string("bestblock_nomerkle"), locator); } -bool CWalletDB::ReadBestBlock(CBlockLocator& locator) +bool WalletBatch::ReadBestBlock(CBlockLocator& locator) { - if (batch.Read(std::string("bestblock"), locator) && !locator.vHave.empty()) return true; - return batch.Read(std::string("bestblock_nomerkle"), locator); + if (m_batch.Read(std::string("bestblock"), locator) && !locator.vHave.empty()) return true; + return m_batch.Read(std::string("bestblock_nomerkle"), locator); } -bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext) +bool WalletBatch::WriteOrderPosNext(int64_t nOrderPosNext) { return WriteIC(std::string("orderposnext"), nOrderPosNext); } -bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool) +bool WalletBatch::ReadPool(int64_t nPool, CKeyPool& keypool) { - return batch.Read(std::make_pair(std::string("pool"), nPool), keypool); + return m_batch.Read(std::make_pair(std::string("pool"), nPool), keypool); } -bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool) +bool WalletBatch::WritePool(int64_t nPool, const CKeyPool& keypool) { return WriteIC(std::make_pair(std::string("pool"), nPool), keypool); } -bool CWalletDB::ErasePool(int64_t nPool) +bool WalletBatch::ErasePool(int64_t nPool) { return EraseIC(std::make_pair(std::string("pool"), nPool)); } -bool CWalletDB::WriteMinVersion(int nVersion) +bool WalletBatch::WriteMinVersion(int nVersion) { return WriteIC(std::string("minversion"), nVersion); } -bool CWalletDB::ReadAccount(const std::string& strAccount, CAccount& account) +bool WalletBatch::ReadAccount(const std::string& strAccount, CAccount& account) { account.SetNull(); - return batch.Read(std::make_pair(std::string("acc"), strAccount), account); + return m_batch.Read(std::make_pair(std::string("acc"), strAccount), account); } -bool CWalletDB::WriteAccount(const std::string& strAccount, const CAccount& account) +bool WalletBatch::WriteAccount(const std::string& strAccount, const CAccount& account) { return WriteIC(std::make_pair(std::string("acc"), strAccount), account); } -bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry) +bool WalletBatch::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry) { return WriteIC(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry); } -CAmount CWalletDB::GetAccountCreditDebit(const std::string& strAccount) +CAmount WalletBatch::GetAccountCreditDebit(const std::string& strAccount) { std::list<CAccountingEntry> entries; ListAccountCreditDebit(strAccount, entries); @@ -178,11 +178,11 @@ CAmount CWalletDB::GetAccountCreditDebit(const std::string& strAccount) return nCreditDebit; } -void CWalletDB::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries) +void WalletBatch::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries) { bool fAllAccounts = (strAccount == "*"); - Dbc* pcursor = batch.GetCursor(); + Dbc* pcursor = m_batch.GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__) + ": cannot create DB cursor"); bool setRange = true; @@ -193,7 +193,7 @@ void CWalletDB::ListAccountCreditDebit(const std::string& strAccount, std::list< if (setRange) ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? std::string("") : strAccount), uint64_t(0))); CDataStream ssValue(SER_DISK, CLIENT_VERSION); - int ret = batch.ReadAtCursor(pcursor, ssKey, ssValue, setRange); + int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue, setRange); setRange = false; if (ret == DB_NOTFOUND) break; @@ -512,13 +512,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, return true; } -bool CWalletDB::IsKeyType(const std::string& strType) +bool WalletBatch::IsKeyType(const std::string& strType) { return (strType== "key" || strType == "wkey" || strType == "mkey" || strType == "ckey"); } -DBErrors CWalletDB::LoadWallet(CWallet* pwallet) +DBErrors WalletBatch::LoadWallet(CWallet* pwallet) { CWalletScanState wss; bool fNoncriticalErrors = false; @@ -527,7 +527,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) LOCK(pwallet->cs_wallet); try { int nMinVersion = 0; - if (batch.Read((std::string)"minversion", nMinVersion)) + if (m_batch.Read((std::string)"minversion", nMinVersion)) { if (nMinVersion > CLIENT_VERSION) return DBErrors::TOO_NEW; @@ -535,7 +535,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) } // Get cursor - Dbc* pcursor = batch.GetCursor(); + Dbc* pcursor = m_batch.GetCursor(); if (!pcursor) { LogPrintf("Error getting wallet database cursor\n"); @@ -547,7 +547,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) // Read next record CDataStream ssKey(SER_DISK, CLIENT_VERSION); CDataStream ssValue(SER_DISK, CLIENT_VERSION); - int ret = batch.ReadAtCursor(pcursor, ssKey, ssValue); + int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); if (ret == DB_NOTFOUND) break; else if (ret != 0) @@ -624,20 +624,20 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) return result; } -DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx) +DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx) { DBErrors result = DBErrors::LOAD_OK; try { int nMinVersion = 0; - if (batch.Read((std::string)"minversion", nMinVersion)) + if (m_batch.Read((std::string)"minversion", nMinVersion)) { if (nMinVersion > CLIENT_VERSION) return DBErrors::TOO_NEW; } // Get cursor - Dbc* pcursor = batch.GetCursor(); + Dbc* pcursor = m_batch.GetCursor(); if (!pcursor) { LogPrintf("Error getting wallet database cursor\n"); @@ -649,7 +649,7 @@ DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWal // Read next record CDataStream ssKey(SER_DISK, CLIENT_VERSION); CDataStream ssValue(SER_DISK, CLIENT_VERSION); - int ret = batch.ReadAtCursor(pcursor, ssKey, ssValue); + int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); if (ret == DB_NOTFOUND) break; else if (ret != 0) @@ -683,7 +683,7 @@ DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWal return result; } -DBErrors CWalletDB::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<uint256>& vTxHashOut) +DBErrors WalletBatch::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<uint256>& vTxHashOut) { // build list of wallet TXs and hashes std::vector<uint256> vTxHash; @@ -721,7 +721,7 @@ DBErrors CWalletDB::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<uin return DBErrors::LOAD_OK; } -DBErrors CWalletDB::ZapWalletTx(std::vector<CWalletTx>& vWtx) +DBErrors WalletBatch::ZapWalletTx(std::vector<CWalletTx>& vWtx) { // build list of wallet TXs std::vector<uint256> vTxHash; @@ -749,7 +749,7 @@ void MaybeCompactWalletDB() } for (CWalletRef pwallet : vpwallets) { - CWalletDBWrapper& dbh = pwallet->GetDBHandle(); + WalletDatabase& dbh = pwallet->GetDBHandle(); unsigned int nUpdateCounter = dbh.nUpdateCounter; @@ -759,7 +759,7 @@ void MaybeCompactWalletDB() } if (dbh.nLastFlushed != nUpdateCounter && GetTime() - dbh.nLastWalletUpdate >= 2) { - if (CDB::PeriodicFlush(dbh)) { + if (BerkeleyBatch::PeriodicFlush(dbh)) { dbh.nLastFlushed = nUpdateCounter; } } @@ -771,19 +771,19 @@ void MaybeCompactWalletDB() // // Try to (very carefully!) recover wallet file if there is a problem. // -bool CWalletDB::Recover(const fs::path& wallet_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename) +bool WalletBatch::Recover(const fs::path& wallet_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename) { - return CDB::Recover(wallet_path, callbackDataIn, recoverKVcallback, out_backup_filename); + return BerkeleyBatch::Recover(wallet_path, callbackDataIn, recoverKVcallback, out_backup_filename); } -bool CWalletDB::Recover(const fs::path& wallet_path, std::string& out_backup_filename) +bool WalletBatch::Recover(const fs::path& wallet_path, std::string& out_backup_filename) { // recover without a key filter callback // results in recovering all record types - return CWalletDB::Recover(wallet_path, nullptr, nullptr, out_backup_filename); + return WalletBatch::Recover(wallet_path, nullptr, nullptr, out_backup_filename); } -bool CWalletDB::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue) +bool WalletBatch::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue) { CWallet *dummyWallet = reinterpret_cast<CWallet*>(callbackData); CWalletScanState dummyWss; @@ -799,60 +799,60 @@ bool CWalletDB::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDa return false; if (!fReadOK) { - LogPrintf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType, strErr); + LogPrintf("WARNING: WalletBatch::Recover skipping %s: %s\n", strType, strErr); return false; } return true; } -bool CWalletDB::VerifyEnvironment(const fs::path& wallet_path, std::string& errorStr) +bool WalletBatch::VerifyEnvironment(const fs::path& wallet_path, std::string& errorStr) { - return CDB::VerifyEnvironment(wallet_path, errorStr); + return BerkeleyBatch::VerifyEnvironment(wallet_path, errorStr); } -bool CWalletDB::VerifyDatabaseFile(const fs::path& wallet_path, std::string& warningStr, std::string& errorStr) +bool WalletBatch::VerifyDatabaseFile(const fs::path& wallet_path, std::string& warningStr, std::string& errorStr) { - return CDB::VerifyDatabaseFile(wallet_path, warningStr, errorStr, CWalletDB::Recover); + return BerkeleyBatch::VerifyDatabaseFile(wallet_path, warningStr, errorStr, WalletBatch::Recover); } -bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value) +bool WalletBatch::WriteDestData(const std::string &address, const std::string &key, const std::string &value) { return WriteIC(std::make_pair(std::string("destdata"), std::make_pair(address, key)), value); } -bool CWalletDB::EraseDestData(const std::string &address, const std::string &key) +bool WalletBatch::EraseDestData(const std::string &address, const std::string &key) { return EraseIC(std::make_pair(std::string("destdata"), std::make_pair(address, key))); } -bool CWalletDB::WriteHDChain(const CHDChain& chain) +bool WalletBatch::WriteHDChain(const CHDChain& chain) { return WriteIC(std::string("hdchain"), chain); } -bool CWalletDB::TxnBegin() +bool WalletBatch::TxnBegin() { - return batch.TxnBegin(); + return m_batch.TxnBegin(); } -bool CWalletDB::TxnCommit() +bool WalletBatch::TxnCommit() { - return batch.TxnCommit(); + return m_batch.TxnCommit(); } -bool CWalletDB::TxnAbort() +bool WalletBatch::TxnAbort() { - return batch.TxnAbort(); + return m_batch.TxnAbort(); } -bool CWalletDB::ReadVersion(int& nVersion) +bool WalletBatch::ReadVersion(int& nVersion) { - return batch.ReadVersion(nVersion); + return m_batch.ReadVersion(nVersion); } -bool CWalletDB::WriteVersion(int nVersion) +bool WalletBatch::WriteVersion(int nVersion) { - return batch.WriteVersion(nVersion); + return m_batch.WriteVersion(nVersion); } |