Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
walletdb.h
Go to the documentation of this file.
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
7 
8 #include "db.h"
9 #include "key.h"
10 
11 #include <list>
12 #include <stdint.h>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 class CAccount;
18 class CAccountingEntry;
19 struct CBlockLocator;
20 class CKeyPool;
21 class CMasterKey;
22 class CScript;
23 class CWallet;
24 class CWalletTx;
25 class uint160;
26 class uint256;
27 
30 {
37 };
38 
40 {
41 public:
42  static const int CURRENT_VERSION=1;
43  int nVersion;
44  int64_t nCreateTime; // 0 means unknown
45 
47  {
48  SetNull();
49  }
50  CKeyMetadata(int64_t nCreateTime_)
51  {
53  nCreateTime = nCreateTime_;
54  }
55 
57  (
58  READWRITE(this->nVersion);
59  nVersion = this->nVersion;
60  READWRITE(nCreateTime);
61  )
62 
63  void SetNull()
64  {
66  nCreateTime = 0;
67  }
68 };
69 
71 class CWalletDB : public CDB
72 {
73 public:
74  CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
75  {
76  }
77 private:
78  CWalletDB(const CWalletDB&);
79  void operator=(const CWalletDB&);
80 public:
81  bool WriteName(const std::string& strAddress, const std::string& strName);
82  bool EraseName(const std::string& strAddress);
83 
84  bool WritePurpose(const std::string& strAddress, const std::string& purpose);
85  bool ErasePurpose(const std::string& strAddress);
86 
87  bool WriteTx(uint256 hash, const CWalletTx& wtx);
88  bool EraseTx(uint256 hash);
89 
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);
93 
94  bool WriteCScript(const uint160& hash, const CScript& redeemScript);
95 
96  bool WriteBestBlock(const CBlockLocator& locator);
97  bool ReadBestBlock(CBlockLocator& locator);
98 
99  bool WriteOrderPosNext(int64_t nOrderPosNext);
100 
101  bool WriteDefaultKey(const CPubKey& vchPubKey);
102 
103  bool ReadPool(int64_t nPool, CKeyPool& keypool);
104  bool WritePool(int64_t nPool, const CKeyPool& keypool);
105  bool ErasePool(int64_t nPool);
106 
107  bool WriteMinVersion(int nVersion);
108 
109  bool ReadAccount(const std::string& strAccount, CAccount& account);
110  bool WriteAccount(const std::string& strAccount, const CAccount& account);
111 
113  bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
115  bool EraseDestData(const std::string &address, const std::string &key);
116 private:
117  bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
118 public:
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);
122 
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);
129 };
130 
131 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
132 
133 #endif // BITCOIN_WALLETDB_H
CKeyMetadata(int64_t nCreateTime_)
Definition: walletdb.h:50
bool WriteMinVersion(int nVersion)
Definition: walletdb.cpp:155
Account information.
Definition: wallet.h:771
DBErrors FindWalletTx(CWallet *pwallet, std::vector< uint256 > &vTxHash)
Definition: walletdb.cpp:683
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:166
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: core.h:459
#define READWRITE(obj)
Definition: serialize.h:92
bool BackupWallet(const CWallet &wallet, const std::string &strDest)
Definition: walletdb.cpp:825
CWalletDB(std::string strFilename, const char *pszMode="r+")
Definition: walletdb.h:74
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
Definition: walletdb.cpp:103
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:82
Master key for wallet encryption.
Definition: crypter.h:33
CKeyMetadata()
Definition: walletdb.h:46
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
Definition: walletdb.cpp:193
bool ErasePurpose(const std::string &strAddress)
Definition: walletdb.cpp:47
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:171
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:29
bool WriteOrderPosNext(int64_t nOrderPosNext)
Definition: walletdb.cpp:126
void operator=(const CWalletDB &)
bool EraseTx(uint256 hash)
Definition: walletdb.cpp:59
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
Definition: key.h:176
DBErrors ZapWalletTx(CWallet *pwallet)
Definition: walletdb.cpp:746
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
Definition: walletdb.cpp:957
bool WritePool(int64_t nPool, const CKeyPool &keypool)
Definition: walletdb.cpp:143
int64_t GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:181
static const int CURRENT_VERSION
Definition: walletdb.h:42
bool WriteName(const std::string &strAddress, const std::string &strName)
Definition: walletdb.cpp:27
DBErrors LoadWallet(CWallet *pwallet)
Definition: walletdb.cpp:582
An encapsulated public key.
Definition: key.h:42
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value)
Write destination data key,value tuple to database.
Definition: walletdb.cpp:951
RAII class that provides access to a Berkeley database.
Definition: db.h:90
int64_t nCreateTime
Definition: walletdb.h:44
bool ErasePool(int64_t nPool)
Definition: walletdb.cpp:149
bool WriteTx(uint256 hash, const CWalletTx &wtx)
Definition: walletdb.cpp:53
Access to the wallet database (wallet.dat)
Definition: walletdb.h:71
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:451
DBErrors ReorderTransactions(CWallet *)
Definition: walletdb.cpp:238
int nVersion
Definition: walletdb.h:43
bool ReadBestBlock(CBlockLocator &locator)
Definition: walletdb.cpp:121
bool WriteDefaultKey(const CPubKey &vchPubKey)
Definition: walletdb.cpp:132
bool WriteBestBlock(const CBlockLocator &locator)
Definition: walletdb.cpp:115
256-bit unsigned integer
Definition: uint256.h:531
bool ReadPool(int64_t nPool, CKeyPool &keypool)
Definition: walletdb.cpp:138
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:401
static bool Recover(CDBEnv &dbenv, std::string filename, bool fOnlyKeys)
Definition: walletdb.cpp:868
Internal transfers.
Definition: wallet.h:799
Definition: db.h:30
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:100
160-bit unsigned integer
Definition: uint256.h:419
bool EraseName(const std::string &strAddress)
Definition: walletdb.cpp:33
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
Definition: walletdb.cpp:109
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
Definition: walletdb.cpp:41
IMPLEMENT_SERIALIZE(READWRITE(this->nVersion);nVersion=this->nVersion;READWRITE(nCreateTime);) void SetNull()
Definition: walletdb.h:57
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:160
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:65
A key pool entry.
Definition: wallet.h:55