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