X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fdb.h;h=9826194ed0d1f0805ecc5e1c059def6924cb9cf2;hb=223b6f1ba4819e9a146e7aa451d546726d0bc714;hp=290981c06afff0f157b66cd6bb6072f77fb0763e;hpb=c22feee634ade7f887d7e29635a8e5dc44675273;p=novacoin.git diff --git a/src/db.h b/src/db.h index 290981c..9826194 100644 --- a/src/db.h +++ b/src/db.h @@ -1,6 +1,16 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. +#ifndef BITCOIN_DB_H +#define BITCOIN_DB_H + +#include "key.h" + +#include +#include +#include + +#include class CTransaction; class CTxIndex; @@ -15,9 +25,9 @@ class CAccount; class CAccountingEntry; class CBlockLocator; -extern map mapAddressBook; +extern std::map mapAddressBook; extern CCriticalSection cs_mapAddressBook; -extern vector vchDefaultKey; +extern std::vector vchDefaultKey; extern bool fClient; extern int nBestHeight; @@ -27,7 +37,7 @@ extern DbEnv dbenv; extern void DBFlush(bool fShutdown); -extern vector GetKeyFromKeyPool(); +extern std::vector GetKeyFromKeyPool(); extern int64 GetOldestKeyPoolTime(); @@ -37,8 +47,8 @@ class CDB { protected: Db* pdb; - string strFile; - vector vTxn; + std::string strFile; + std::vector vTxn; bool fReadOnly; explicit CDB(const char* pszFile, const char* pszMode="r+"); @@ -247,12 +257,12 @@ public: bool ReadVersion(int& nVersion) { nVersion = 0; - return Read(string("version"), nVersion); + return Read(std::string("version"), nVersion); } bool WriteVersion(int nVersion) { - return Write(string("version"), nVersion); + return Write(std::string("version"), nVersion); } }; @@ -276,7 +286,7 @@ public: bool AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight); bool EraseTxIndex(const CTransaction& tx); bool ContainsTx(uint256 hash); - bool ReadOwnerTxes(uint160 hash160, int nHeight, vector& vtx); + bool ReadOwnerTxes(uint160 hash160, int nHeight, std::vector& vtx); bool ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex); bool ReadDiskTx(uint256 hash, CTransaction& tx); bool ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex); @@ -318,14 +328,14 @@ class CKeyPool { public: int64 nTime; - vector vchPubKey; + std::vector vchPubKey; CKeyPool() { nTime = GetTime(); } - CKeyPool(const vector& vchPubKeyIn) + CKeyPool(const std::vector& vchPubKeyIn) { nTime = GetTime(); vchPubKey = vchPubKeyIn; @@ -353,101 +363,101 @@ private: CWalletDB(const CWalletDB&); void operator=(const CWalletDB&); public: - bool ReadName(const string& strAddress, string& strName) + bool ReadName(const std::string& strAddress, std::string& strName) { strName = ""; - return Read(make_pair(string("name"), strAddress), strName); + return Read(std::make_pair(std::string("name"), strAddress), strName); } - bool WriteName(const string& strAddress, const string& strName) + bool WriteName(const std::string& strAddress, const std::string& strName) { CRITICAL_BLOCK(cs_mapAddressBook) mapAddressBook[strAddress] = strName; nWalletDBUpdated++; - return Write(make_pair(string("name"), strAddress), strName); + return Write(std::make_pair(std::string("name"), strAddress), strName); } - bool EraseName(const string& strAddress) + bool 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. CRITICAL_BLOCK(cs_mapAddressBook) mapAddressBook.erase(strAddress); nWalletDBUpdated++; - return Erase(make_pair(string("name"), strAddress)); + return Erase(std::make_pair(std::string("name"), strAddress)); } bool ReadTx(uint256 hash, CWalletTx& wtx) { - return Read(make_pair(string("tx"), hash), wtx); + return Read(std::make_pair(std::string("tx"), hash), wtx); } bool WriteTx(uint256 hash, const CWalletTx& wtx) { nWalletDBUpdated++; - return Write(make_pair(string("tx"), hash), wtx); + return Write(std::make_pair(std::string("tx"), hash), wtx); } bool EraseTx(uint256 hash) { nWalletDBUpdated++; - return Erase(make_pair(string("tx"), hash)); + return Erase(std::make_pair(std::string("tx"), hash)); } - bool ReadKey(const vector& vchPubKey, CPrivKey& vchPrivKey) + bool ReadKey(const std::vector& vchPubKey, CPrivKey& vchPrivKey) { vchPrivKey.clear(); - return Read(make_pair(string("key"), vchPubKey), vchPrivKey); + return Read(std::make_pair(std::string("key"), vchPubKey), vchPrivKey); } - bool WriteKey(const vector& vchPubKey, const CPrivKey& vchPrivKey) + bool WriteKey(const std::vector& vchPubKey, const CPrivKey& vchPrivKey) { nWalletDBUpdated++; - return Write(make_pair(string("key"), vchPubKey), vchPrivKey, false); + return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false); } bool WriteBestBlock(const CBlockLocator& locator) { nWalletDBUpdated++; - return Write(string("bestblock"), locator); + return Write(std::string("bestblock"), locator); } bool ReadBestBlock(CBlockLocator& locator) { - return Read(string("bestblock"), locator); + return Read(std::string("bestblock"), locator); } - bool ReadDefaultKey(vector& vchPubKey) + bool ReadDefaultKey(std::vector& vchPubKey) { vchPubKey.clear(); - return Read(string("defaultkey"), vchPubKey); + return Read(std::string("defaultkey"), vchPubKey); } - bool WriteDefaultKey(const vector& vchPubKey) + bool WriteDefaultKey(const std::vector& vchPubKey) { vchDefaultKey = vchPubKey; nWalletDBUpdated++; - return Write(string("defaultkey"), vchPubKey); + return Write(std::string("defaultkey"), vchPubKey); } template - bool ReadSetting(const string& strKey, T& value) + bool ReadSetting(const std::string& strKey, T& value) { - return Read(make_pair(string("setting"), strKey), value); + return Read(std::make_pair(std::string("setting"), strKey), value); } template - bool WriteSetting(const string& strKey, const T& value) + bool WriteSetting(const std::string& strKey, const T& value) { nWalletDBUpdated++; - return Write(make_pair(string("setting"), strKey), value); + return Write(std::make_pair(std::string("setting"), strKey), value); } - bool ReadAccount(const string& strAccount, CAccount& account); - bool WriteAccount(const string& strAccount, const CAccount& account); + bool ReadAccount(const std::string& strAccount, CAccount& account); + bool WriteAccount(const std::string& strAccount, const CAccount& account); bool WriteAccountingEntry(const CAccountingEntry& acentry); - int64 GetAccountCreditDebit(const string& strAccount); - void ListAccountCreditDebit(const string& strAccount, list& acentries); + int64 GetAccountCreditDebit(const std::string& strAccount); + void ListAccountCreditDebit(const std::string& strAccount, std::list& acentries); bool LoadWallet(); protected: @@ -455,14 +465,14 @@ protected: void KeepKey(int64 nIndex); static void ReturnKey(int64 nIndex); friend class CReserveKey; - friend vector GetKeyFromKeyPool(); + friend std::vector GetKeyFromKeyPool(); friend int64 GetOldestKeyPoolTime(); }; bool LoadWallet(bool& fFirstRunRet); -void BackupWallet(const string& strDest); +void BackupWallet(const std::string& strDest); -inline bool SetAddressBookName(const string& strAddress, const string& strName) +inline bool SetAddressBookName(const std::string& strAddress, const std::string& strName) { return CWalletDB().WriteName(strAddress, strName); } @@ -471,7 +481,7 @@ class CReserveKey { protected: int64 nIndex; - vector vchPubKey; + std::vector vchPubKey; public: CReserveKey() { @@ -484,7 +494,7 @@ public: ReturnKey(); } - vector GetReservedKey() + std::vector GetReservedKey() { if (nIndex == -1) { @@ -512,3 +522,5 @@ public: vchPubKey.clear(); } }; + +#endif