Update CMakeLists.txt - play with openssl
[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
10 class CKeyPool;
11 class CAccount;
12 class CAccountingEntry;
13
14 /** Error statuses for the wallet database */
15 enum DBErrors
16 {
17     DB_LOAD_OK,
18     DB_CORRUPT,
19     DB_NONCRITICAL_ERROR,
20     DB_TOO_NEW,
21     DB_LOAD_FAIL,
22     DB_NEED_REWRITE
23 };
24
25 class CKeyMetadata
26 {
27 public:
28     static const int CURRENT_VERSION=1;
29     int nVersion;
30     int64_t nCreateTime; // 0 means unknown
31
32     CKeyMetadata();
33     CKeyMetadata(int64_t nCreateTime_);
34
35     IMPLEMENT_SERIALIZE
36     (
37         READWRITE(this->nVersion);
38         nVersion = this->nVersion;
39         READWRITE(nCreateTime);
40     )
41
42     void SetNull();
43 };
44
45
46 /** Access to the wallet database (wallet.dat) */
47 class CWalletDB : public CDB
48 {
49 public:
50     CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
51     {
52     }
53 private:
54     CWalletDB(const CWalletDB&);
55     void operator=(const CWalletDB&);
56 public:
57     bool WriteName(const std::string& strAddress, const std::string& strName);
58     bool EraseName(const std::string& strAddress);
59     bool WriteTx(uint256 hash, const CWalletTx& wtx);
60     bool EraseTx(uint256 hash);
61     bool WriteKey(const CPubKey& key, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
62     bool WriteMalleableKey(const CMalleableKeyView& keyView, const CSecret& vchSecretH, const CKeyMetadata &keyMeta);
63     bool WriteCryptedMalleableKey(const CMalleableKeyView& keyView, const std::vector<unsigned char>& vchCryptedSecretH, const CKeyMetadata &keyMeta);
64     bool WriteCryptedKey(const CPubKey& key, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
65     bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
66     bool EraseMasterKey(unsigned int nID);
67     bool EraseCryptedKey(const CPubKey& key);
68     bool EraseCryptedMalleableKey(const CMalleableKeyView& keyView);
69     bool WriteCScript(const uint160& hash, const CScript& redeemScript);
70     bool WriteWatchOnly(const CScript &dest);
71     bool EraseWatchOnly(const CScript &dest);
72     bool WriteBestBlock(const CBlockLocator& locator);
73     bool ReadBestBlock(CBlockLocator& locator);
74     bool WriteOrderPosNext(int64_t nOrderPosNext);
75     bool WriteDefaultKey(const CPubKey& key);
76     bool ReadPool(int64_t nPool, CKeyPool& keypool);
77     bool WritePool(int64_t nPool, const CKeyPool& keypool);
78     bool ErasePool(int64_t nPool);
79     bool WriteMinVersion(int nVersion);
80     bool ReadAccount(const std::string& strAccount, CAccount& account);
81     bool WriteAccount(const std::string& strAccount, const CAccount& account);
82 private:
83     bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
84 public:
85     bool WriteAccountingEntry(const CAccountingEntry& acentry);
86     int64_t GetAccountCreditDebit(const std::string& strAccount);
87     void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
88
89     DBErrors ReorderTransactions(CWallet*);
90     DBErrors LoadWallet(CWallet* pwallet);
91     DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
92     DBErrors ZapWalletTx(CWallet* pwallet);
93
94     static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
95     static bool Recover(CDBEnv& dbenv, std::string filename);
96 };
97
98 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
99
100 #endif // BITCOIN_WALLETDB_H