diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-11-10 19:19:30 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2013-11-10 19:21:03 +0100 |
commit | f76c122e2eac8ef66f69d142231bd33c88a24c50 (patch) | |
tree | d2f910390e55aef857023812fbdaefdd66cd99ff /src/walletdb.h | |
parent | 7c4c207be8420d394a5abc4368d1bb69ad4f8067 (diff) | |
parent | 51ed9ec971614aebdbfbd9527aba365dd0afd437 (diff) |
Merge pull request #2767
51ed9ec Cleanup code using forward declarations. (Brandon Dahler)
Diffstat (limited to 'src/walletdb.h')
-rw-r--r-- | src/walletdb.h | 144 |
1 files changed, 33 insertions, 111 deletions
diff --git a/src/walletdb.h b/src/walletdb.h index b6d0d45449..c3b87bb2a6 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -6,13 +6,24 @@ #define BITCOIN_WALLETDB_H #include "db.h" -#include "base58.h" +#include "key.h" + +#include <list> +#include <stdint.h> +#include <string> +#include <utility> +#include <vector> -class CKeyPool; class CAccount; class CAccountingEntry; +class CBlockLocator; +class CKeyPool; +class CMasterKey; +class CScript; class CWallet; class CWalletTx; +class uint160; +class uint256; /** Error statuses for the wallet database */ enum DBErrors @@ -30,13 +41,13 @@ class CKeyMetadata public: static const int CURRENT_VERSION=1; int nVersion; - int64 nCreateTime; // 0 means unknown + int64_t nCreateTime; // 0 means unknown CKeyMetadata() { SetNull(); } - CKeyMetadata(int64 nCreateTime_) + CKeyMetadata(int64_t nCreateTime_) { nVersion = CKeyMetadata::CURRENT_VERSION; nCreateTime = nCreateTime_; @@ -73,108 +84,25 @@ public: bool WritePurpose(const std::string& strAddress, const std::string& purpose); bool ErasePurpose(const std::string& strAddress); - bool WriteTx(uint256 hash, const CWalletTx& wtx) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("tx"), hash), wtx); - } + bool WriteTx(uint256 hash, const CWalletTx& wtx); + bool EraseTx(uint256 hash); - bool EraseTx(uint256 hash) - { - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("tx"), hash)); - } + bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta); + bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta); + bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey); - bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, - const CKeyMetadata &keyMeta) - { - nWalletDBUpdated++; + bool WriteCScript(const uint160& hash, const CScript& redeemScript); - if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), - keyMeta)) - return false; - - // hash pubkey/privkey to accelerate wallet load - std::vector<unsigned char> vchKey; - vchKey.reserve(vchPubKey.size() + vchPrivKey.size()); - vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); - vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end()); - - return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false); - } + bool WriteBestBlock(const CBlockLocator& locator); + bool ReadBestBlock(CBlockLocator& locator); - bool WriteCryptedKey(const CPubKey& vchPubKey, - const std::vector<unsigned char>& vchCryptedSecret, - const CKeyMetadata &keyMeta) - { - const bool fEraseUnencryptedKey = true; - nWalletDBUpdated++; + bool WriteOrderPosNext(int64_t nOrderPosNext); - if (!Write(std::make_pair(std::string("keymeta"), vchPubKey), - keyMeta)) - return false; - - if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false)) - return false; - if (fEraseUnencryptedKey) - { - Erase(std::make_pair(std::string("key"), vchPubKey)); - Erase(std::make_pair(std::string("wkey"), vchPubKey)); - } - return true; - } + bool WriteDefaultKey(const CPubKey& vchPubKey); - bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true); - } - - bool WriteCScript(const uint160& hash, const CScript& redeemScript) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false); - } - - bool WriteBestBlock(const CBlockLocator& locator) - { - nWalletDBUpdated++; - return Write(std::string("bestblock"), locator); - } - - bool ReadBestBlock(CBlockLocator& locator) - { - return Read(std::string("bestblock"), locator); - } - - bool WriteOrderPosNext(int64 nOrderPosNext) - { - nWalletDBUpdated++; - return Write(std::string("orderposnext"), nOrderPosNext); - } - - bool WriteDefaultKey(const CPubKey& vchPubKey) - { - nWalletDBUpdated++; - return Write(std::string("defaultkey"), vchPubKey); - } - - bool ReadPool(int64 nPool, CKeyPool& keypool) - { - return Read(std::make_pair(std::string("pool"), nPool), keypool); - } - - bool WritePool(int64 nPool, const CKeyPool& keypool) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("pool"), nPool), keypool); - } - - bool ErasePool(int64 nPool) - { - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("pool"), nPool)); - } + bool ReadPool(int64_t nPool, CKeyPool& keypool); + bool WritePool(int64_t nPool, const CKeyPool& keypool); + bool ErasePool(int64_t nPool); // Settings are no longer stored in wallet.dat; these are // used only for backwards compatibility: @@ -189,24 +117,18 @@ public: nWalletDBUpdated++; return Write(std::make_pair(std::string("setting"), strKey), value); } - bool EraseSetting(const std::string& strKey) - { - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("setting"), strKey)); - } + + bool EraseSetting(const std::string& strKey); - bool WriteMinVersion(int nVersion) - { - return Write(std::string("minversion"), nVersion); - } + bool WriteMinVersion(int nVersion); bool ReadAccount(const std::string& strAccount, CAccount& account); bool WriteAccount(const std::string& strAccount, const CAccount& account); private: - bool WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry& acentry); + bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry); public: bool WriteAccountingEntry(const CAccountingEntry& acentry); - int64 GetAccountCreditDebit(const std::string& strAccount); + int64_t GetAccountCreditDebit(const std::string& strAccount); void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries); DBErrors ReorderTransactions(CWallet*); |