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 #ifndef BITCOIN_WALLETDB_H
6 #define BITCOIN_WALLETDB_H
18 class CAccountingEntry;
28 /** Error statuses for the wallet database */
42 static const int CURRENT_VERSION=1;
44 int64_t nCreateTime; // 0 means unknown
50 CKeyMetadata(int64_t nCreateTime_)
52 nVersion = CKeyMetadata::CURRENT_VERSION;
53 nCreateTime = nCreateTime_;
58 READWRITE(this->nVersion);
59 nVersion = this->nVersion;
60 READWRITE(nCreateTime);
65 nVersion = CKeyMetadata::CURRENT_VERSION;
70 /** Access to the wallet database (wallet.dat) */
71 class CWalletDB : public CDB
74 CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
78 CWalletDB(const CWalletDB&);
79 void operator=(const CWalletDB&);
81 bool WriteName(const std::string& strAddress, const std::string& strName);
82 bool EraseName(const std::string& strAddress);
84 bool WritePurpose(const std::string& strAddress, const std::string& purpose);
85 bool ErasePurpose(const std::string& strAddress);
87 bool WriteTx(uint256 hash, const CWalletTx& wtx);
88 bool EraseTx(uint256 hash);
90 bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
91 bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
92 bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
94 bool WriteCScript(const uint160& hash, const CScript& redeemScript);
96 bool WriteBestBlock(const CBlockLocator& locator);
97 bool ReadBestBlock(CBlockLocator& locator);
99 bool WriteOrderPosNext(int64_t nOrderPosNext);
101 bool WriteDefaultKey(const CPubKey& vchPubKey);
103 bool ReadPool(int64_t nPool, CKeyPool& keypool);
104 bool WritePool(int64_t nPool, const CKeyPool& keypool);
105 bool ErasePool(int64_t nPool);
107 bool WriteMinVersion(int nVersion);
109 bool ReadAccount(const std::string& strAccount, CAccount& account);
110 bool WriteAccount(const std::string& strAccount, const CAccount& account);
112 /// Write destination data key,value tuple to database
113 bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
114 /// Erase destination data tuple from wallet database
115 bool EraseDestData(const std::string &address, const std::string &key);
117 bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
119 bool WriteAccountingEntry(const CAccountingEntry& acentry);
120 int64_t GetAccountCreditDebit(const std::string& strAccount);
121 void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
123 DBErrors ReorderTransactions(CWallet*);
124 DBErrors LoadWallet(CWallet* pwallet);
125 DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
126 DBErrors ZapWalletTx(CWallet* pwallet);
127 static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
128 static bool Recover(CDBEnv& dbenv, std::string filename);
131 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
133 #endif // BITCOIN_WALLETDB_H