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
14 class CAccountingEntry;
16 // Error statuses for the wallet database
30 static const int CURRENT_VERSION=1;
32 int64_t nCreateTime; // 0 means unknown
35 CKeyMetadata(int64_t nCreateTime_);
39 READWRITE(this->nVersion);
40 nVersion = this->nVersion;
41 READWRITE(nCreateTime);
47 // Access to the wallet database (wallet.dat)
48 class CWalletDB : public CDB
51 CWalletDB(std::string strFilename, const char* pszMode="r+");
53 CWalletDB(const CWalletDB&);
54 void operator=(const CWalletDB&);
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);
82 bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
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);
88 DBErrors ReorderTransactions(CWallet*);
89 DBErrors LoadWallet(CWallet* pwallet);
90 DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
91 DBErrors ZapWalletTx(CWallet* pwallet);
93 static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
94 static bool Recover(CDBEnv& dbenv, std::string filename);
97 #endif // BITCOIN_WALLETDB_H