Remove namespace from header files
[novacoin.git] / src / walletdb.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_WALLETDB_H
6 #define BITCOIN_WALLETDB_H
7
8 #include "db.h"
9 #include "keystore.h"
10
11
12 class CKeyPool;
13 class CAccount;
14 class CAccountingEntry;
15
16 // Error statuses for the wallet database
17 enum DBErrors
18 {
19     DB_LOAD_OK,
20     DB_CORRUPT,
21     DB_NONCRITICAL_ERROR,
22     DB_TOO_NEW,
23     DB_LOAD_FAIL,
24     DB_NEED_REWRITE
25 };
26
27 class CKeyMetadata
28 {
29 public:
30     static const int CURRENT_VERSION=1;
31     int nVersion;
32     int64_t nCreateTime; // 0 means unknown
33
34     CKeyMetadata();
35     CKeyMetadata(int64_t nCreateTime_);
36
37     IMPLEMENT_SERIALIZE
38     (
39         READWRITE(this->nVersion);
40         nVersion = this->nVersion;
41         READWRITE(nCreateTime);
42     )
43
44     void SetNull();
45 };
46
47 // Access to the wallet database (wallet.dat)
48 class CWalletDB : public CDB
49 {
50 public:
51     CWalletDB(std::string strFilename, const char* pszMode="r+");
52 private:
53     CWalletDB(const CWalletDB&);
54     void operator=(const CWalletDB&);
55 public:
56     bool WriteName(const std::string& strAddress, const std::string& strName);
57     bool EraseName(const std::string& strAddress);
58     bool WriteTx(uint256 hash, const CWalletTx& wtx);
59     bool EraseTx(uint256 hash);
60     bool WriteKey(const CPubKey& key, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
61     bool WriteMalleableKey(const CMalleableKeyView& keyView, const CSecret& vchSecretH, const CKeyMetadata &keyMeta);
62     bool WriteCryptedMalleableKey(const CMalleableKeyView& keyView, const std::vector<unsigned char>& vchCryptedSecretH, const CKeyMetadata &keyMeta);
63     bool WriteCryptedKey(const CPubKey& key, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
64     bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
65     bool EraseMasterKey(unsigned int nID);
66     bool EraseCryptedKey(const CPubKey& key);
67     bool EraseCryptedMalleableKey(const CMalleableKeyView& keyView);
68     bool WriteCScript(const uint160& hash, const CScript& redeemScript);
69     bool WriteWatchOnly(const CScript &dest);
70     bool EraseWatchOnly(const CScript &dest);
71     bool WriteBestBlock(const CBlockLocator& locator);
72     bool ReadBestBlock(CBlockLocator& locator);
73     bool WriteOrderPosNext(int64_t nOrderPosNext);
74     bool WriteDefaultKey(const CPubKey& key);
75     bool ReadPool(int64_t nPool, CKeyPool& keypool);
76     bool WritePool(int64_t nPool, const CKeyPool& keypool);
77     bool ErasePool(int64_t nPool);
78     bool WriteMinVersion(int nVersion);
79     bool ReadAccount(const std::string& strAccount, CAccount& account);
80     bool WriteAccount(const std::string& strAccount, const CAccount& account);
81 private:
82     bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
83 public:
84     bool WriteAccountingEntry(const CAccountingEntry& acentry);
85     int64_t GetAccountCreditDebit(const std::string& strAccount);
86     void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
87
88     DBErrors ReorderTransactions(CWallet*);
89     DBErrors LoadWallet(CWallet* pwallet);
90     DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
91     DBErrors ZapWalletTx(CWallet* pwallet);
92
93     static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
94     static bool Recover(CDBEnv& dbenv, std::string filename);
95 };
96
97 #endif // BITCOIN_WALLETDB_H