Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
walletdb.h
Go to the documentation of this file.
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
7 
8 #include "db.h"
9 #include "base58.h"
10 
11 class CKeyPool;
12 class CAccount;
13 class CAccountingEntry;
14 
17 {
24 };
25 
27 class CWalletDB : public CDB
28 {
29 public:
30  CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
31  {
32  }
33 private:
34  CWalletDB(const CWalletDB&);
35  void operator=(const CWalletDB&);
36 public:
37  bool WriteName(const std::string& strAddress, const std::string& strName);
38 
39  bool EraseName(const std::string& strAddress);
40 
41  bool WriteTx(uint256 hash, const CWalletTx& wtx)
42  {
44  return Write(std::make_pair(std::string("tx"), hash), wtx);
45  }
46 
48  {
50  return Erase(std::make_pair(std::string("tx"), hash));
51  }
52 
53  bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey)
54  {
56  return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false);
57  }
58 
59  bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, bool fEraseUnencryptedKey = true)
60  {
62  if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
63  return false;
64  if (fEraseUnencryptedKey)
65  {
66  Erase(std::make_pair(std::string("key"), vchPubKey));
67  Erase(std::make_pair(std::string("wkey"), vchPubKey));
68  }
69  return true;
70  }
71 
72  bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
73  {
75  return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
76  }
77 
78  bool WriteCScript(const uint160& hash, const CScript& redeemScript)
79  {
81  return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
82  }
83 
84  bool WriteBestBlock(const CBlockLocator& locator)
85  {
87  return Write(std::string("bestblock"), locator);
88  }
89 
91  {
92  return Read(std::string("bestblock"), locator);
93  }
94 
95  bool WriteOrderPosNext(int64 nOrderPosNext)
96  {
98  return Write(std::string("orderposnext"), nOrderPosNext);
99  }
100 
101  bool WriteDefaultKey(const CPubKey& vchPubKey)
102  {
104  return Write(std::string("defaultkey"), vchPubKey);
105  }
106 
107  bool ReadPool(int64 nPool, CKeyPool& keypool)
108  {
109  return Read(std::make_pair(std::string("pool"), nPool), keypool);
110  }
111 
112  bool WritePool(int64 nPool, const CKeyPool& keypool)
113  {
115  return Write(std::make_pair(std::string("pool"), nPool), keypool);
116  }
117 
118  bool ErasePool(int64 nPool)
119  {
121  return Erase(std::make_pair(std::string("pool"), nPool));
122  }
123 
124  // Settings are no longer stored in wallet.dat; these are
125  // used only for backwards compatibility:
126  template<typename T>
127  bool ReadSetting(const std::string& strKey, T& value)
128  {
129  return Read(std::make_pair(std::string("setting"), strKey), value);
130  }
131  template<typename T>
132  bool WriteSetting(const std::string& strKey, const T& value)
133  {
135  return Write(std::make_pair(std::string("setting"), strKey), value);
136  }
137  bool EraseSetting(const std::string& strKey)
138  {
140  return Erase(std::make_pair(std::string("setting"), strKey));
141  }
142 
143  bool WriteMinVersion(int nVersion)
144  {
145  return Write(std::string("minversion"), nVersion);
146  }
147 
148  bool ReadAccount(const std::string& strAccount, CAccount& account);
149  bool WriteAccount(const std::string& strAccount, const CAccount& account);
150 private:
151  bool WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry& acentry);
152 public:
153  bool WriteAccountingEntry(const CAccountingEntry& acentry);
154  int64 GetAccountCreditDebit(const std::string& strAccount);
155  void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
156 
158  DBErrors LoadWallet(CWallet* pwallet);
159  static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
160  static bool Recover(CDBEnv& dbenv, std::string filename);
161 };
162 
163 #endif // BITCOIN_WALLETDB_H
unsigned int nWalletDBUpdated
Definition: db.cpp:21
bool Erase(const K &key)
Definition: db.h:174
bool WriteMinVersion(int nVersion)
Definition: walletdb.h:143
Account information.
Definition: wallet.h:758
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey)
Definition: walletdb.h:53
int64 GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:56
std::string * value
Definition: version_set.cc:270
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:41
CWalletDB(std::string strFilename, const char *pszMode="r+")
Definition: walletdb.h:30
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
Definition: walletdb.h:72
Master key for wallet encryption.
Definition: crypter.h:30
bool Write(const K &key, const T &value, bool fOverwrite=true)
Definition: db.h:145
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: main.h:1968
bool WriteSetting(const std::string &strKey, const T &value)
Definition: walletdb.h:132
bool ReadPool(int64 nPool, CKeyPool &keypool)
Definition: walletdb.h:107
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
Definition: walletdb.cpp:68
unsigned long long uint64
Definition: serialize.h:26
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:16
void operator=(const CWalletDB &)
bool EraseTx(uint256 hash)
Definition: walletdb.h:47
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
Definition: key.h:169
bool WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:46
bool WriteName(const std::string &strAddress, const std::string &strName)
Definition: walletdb.cpp:21
DBErrors LoadWallet(CWallet *pwallet)
Definition: walletdb.cpp:371
bool WritePool(int64 nPool, const CKeyPool &keypool)
Definition: walletdb.h:112
An encapsulated public key.
Definition: key.h:40
RAII class that provides access to a Berkeley database.
Definition: db.h:91
bool EraseSetting(const std::string &strKey)
Definition: walletdb.h:137
bool WriteTx(uint256 hash, const CWalletTx &wtx)
Definition: walletdb.h:41
Access to the wallet database (wallet.dat)
Definition: walletdb.h:27
bool Read(const K &key, T &value)
Definition: db.h:110
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:367
DBErrors ReorderTransactions(CWallet *)
Definition: walletdb.cpp:113
bool ReadBestBlock(CBlockLocator &locator)
Definition: walletdb.h:90
bool WriteDefaultKey(const CPubKey &vchPubKey)
Definition: walletdb.h:101
bool WriteBestBlock(const CBlockLocator &locator)
Definition: walletdb.h:84
256-bit unsigned integer
Definition: uint256.h:537
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, bool fEraseUnencryptedKey=true)
Definition: walletdb.h:59
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:244
bool WriteOrderPosNext(int64 nOrderPosNext)
Definition: walletdb.h:95
static bool Recover(CDBEnv &dbenv, std::string filename, bool fOnlyKeys)
Definition: walletdb.cpp:574
Internal transfers.
Definition: wallet.h:786
Definition: db.h:31
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:69
160-bit unsigned integer
Definition: uint256.h:422
bool ReadSetting(const std::string &strKey, T &value)
Definition: walletdb.h:127
bool EraseName(const std::string &strAddress)
Definition: walletdb.cpp:27
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
Definition: walletdb.h:78
bool ErasePool(int64 nPool)
Definition: walletdb.h:118
uint32_t hash
Definition: cache.cc:34
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:35
A key pool entry.
Definition: wallet.h:40
long long int64
Definition: serialize.h:25