]> Git Repo - VerusCoin.git/blob - src/walletdb.h
Merge pull request #5074
[VerusCoin.git] / src / walletdb.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 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
6 #ifndef BITCOIN_WALLETDB_H
7 #define BITCOIN_WALLETDB_H
8
9 #include "amount.h"
10 #include "db.h"
11 #include "key.h"
12 #include "keystore.h"
13
14 #include <list>
15 #include <stdint.h>
16 #include <string>
17 #include <utility>
18 #include <vector>
19
20 class CAccount;
21 class CAccountingEntry;
22 struct CBlockLocator;
23 class CKeyPool;
24 class CMasterKey;
25 class CScript;
26 class CWallet;
27 class CWalletTx;
28 class uint160;
29 class uint256;
30
31 /** Error statuses for the wallet database */
32 enum DBErrors
33 {
34     DB_LOAD_OK,
35     DB_CORRUPT,
36     DB_NONCRITICAL_ERROR,
37     DB_TOO_NEW,
38     DB_LOAD_FAIL,
39     DB_NEED_REWRITE
40 };
41
42 class CKeyMetadata
43 {
44 public:
45     static const int CURRENT_VERSION=1;
46     int nVersion;
47     int64_t nCreateTime; // 0 means unknown
48
49     CKeyMetadata()
50     {
51         SetNull();
52     }
53     CKeyMetadata(int64_t nCreateTime_)
54     {
55         nVersion = CKeyMetadata::CURRENT_VERSION;
56         nCreateTime = nCreateTime_;
57     }
58
59     ADD_SERIALIZE_METHODS;
60
61     template <typename Stream, typename Operation>
62     inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
63         READWRITE(this->nVersion);
64         nVersion = this->nVersion;
65         READWRITE(nCreateTime);
66     }
67
68     void SetNull()
69     {
70         nVersion = CKeyMetadata::CURRENT_VERSION;
71         nCreateTime = 0;
72     }
73 };
74
75 /** Access to the wallet database (wallet.dat) */
76 class CWalletDB : public CDB
77 {
78 public:
79     CWalletDB(const std::string& strFilename, const char* pszMode = "r+") : CDB(strFilename, pszMode)
80     {
81     }
82
83     bool WriteName(const std::string& strAddress, const std::string& strName);
84     bool EraseName(const std::string& strAddress);
85
86     bool WritePurpose(const std::string& strAddress, const std::string& purpose);
87     bool ErasePurpose(const std::string& strAddress);
88
89     bool WriteTx(uint256 hash, const CWalletTx& wtx);
90     bool EraseTx(uint256 hash);
91
92     bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
93     bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
94     bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
95
96     bool WriteCScript(const uint160& hash, const CScript& redeemScript);
97
98     bool WriteWatchOnly(const CScript &script);
99     bool EraseWatchOnly(const CScript &script);
100
101     bool WriteBestBlock(const CBlockLocator& locator);
102     bool ReadBestBlock(CBlockLocator& locator);
103
104     bool WriteOrderPosNext(int64_t nOrderPosNext);
105
106     bool WriteDefaultKey(const CPubKey& vchPubKey);
107
108     bool ReadPool(int64_t nPool, CKeyPool& keypool);
109     bool WritePool(int64_t nPool, const CKeyPool& keypool);
110     bool ErasePool(int64_t nPool);
111
112     bool WriteMinVersion(int nVersion);
113
114     bool ReadAccount(const std::string& strAccount, CAccount& account);
115     bool WriteAccount(const std::string& strAccount, const CAccount& account);
116
117     /// Write destination data key,value tuple to database
118     bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
119     /// Erase destination data tuple from wallet database
120     bool EraseDestData(const std::string &address, const std::string &key);
121
122     bool WriteAccountingEntry(const CAccountingEntry& acentry);
123     CAmount GetAccountCreditDebit(const std::string& strAccount);
124     void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
125
126     DBErrors ReorderTransactions(CWallet* pwallet);
127     DBErrors LoadWallet(CWallet* pwallet);
128     DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
129     DBErrors ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx);
130     static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
131     static bool Recover(CDBEnv& dbenv, std::string filename);
132
133 private:
134     CWalletDB(const CWalletDB&);
135     void operator=(const CWalletDB&);
136
137     bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
138 };
139
140 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
141
142 #endif // BITCOIN_WALLETDB_H
This page took 0.031244 seconds and 4 git commands to generate.