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
12 class CAccountingEntry;
14 /** Error statuses for the wallet database */
28 static const int CURRENT_VERSION=1;
30 int64_t nCreateTime; // 0 means unknown
33 CKeyMetadata(int64_t nCreateTime_);
37 READWRITE(this->nVersion);
38 nVersion = this->nVersion;
39 READWRITE(nCreateTime);
46 /** Access to the wallet database (wallet.dat) */
47 class CWalletDB : public CDB
50 CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
54 CWalletDB(const CWalletDB&);
55 void operator=(const CWalletDB&);
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);
83 bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
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);
89 DBErrors ReorderTransactions(CWallet*);
90 DBErrors LoadWallet(CWallet* pwallet);
91 DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
92 DBErrors ZapWalletTx(CWallet* pwallet);
94 static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
95 static bool Recover(CDBEnv& dbenv, std::string filename);
98 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
100 #endif // BITCOIN_WALLETDB_H