Anoncoin  0.9.4
P2P Digital Currency
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 // Copyright (c) 2013-2014 The Anoncoin Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef ANONCOIN_WALLETDB_H
7 #define ANONCOIN_WALLETDB_H
8 
9 #include "db.h"
10 #include "key.h"
11 #include "keystore.h"
12 
13 #include <list>
14 #include <stdint.h>
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 class CAccount;
20 class CAccountingEntry;
21 struct CBlockLocator;
22 class CKeyPool;
23 class CMasterKey;
24 class CScript;
25 class CWallet;
26 class CWalletTx;
27 class uint160;
28 class uint256;
29 
32 {
39 };
40 
42 {
43 public:
44  static const int CURRENT_VERSION=1;
45  int nVersion;
46  int64_t nCreateTime; // 0 means unknown
47 
49  {
50  SetNull();
51  }
52  CKeyMetadata(int64_t nCreateTime_)
53  {
55  nCreateTime = nCreateTime_;
56  }
57 
59  (
60  READWRITE(this->nVersion);
61  nVersion = this->nVersion;
62  READWRITE(nCreateTime);
63  )
64 
65  void SetNull()
66  {
68  nCreateTime = 0;
69  }
70 };
71 
73 class CWalletDB : public CDB
74 {
75 public:
76  CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
77  {
78  }
79 private:
80  CWalletDB(const CWalletDB&);
81  void operator=(const CWalletDB&);
82 public:
83  bool WriteName(const std::string& strAddress, const std::string& strName);
84  bool EraseName(const std::string& strAddress);
85 
86  bool WritePurpose(const std::string& strAddress, const std::string& purpose);
87  bool ErasePurpose(const std::string& strAddress);
88 
89  bool WriteTx(uint256 hash, const CWalletTx& wtx);
90  bool EraseTx(uint256 hash);
91 
92  bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
93  bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
94  bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
95 
96  bool WriteCScript(const uint160& hash, const CScript& redeemScript);
97 
98  bool WriteWatchOnly(const CScript &script);
99  bool EraseWatchOnly(const CScript &script);
100 
101  bool WriteBestBlock(const CBlockLocator& locator);
102  bool ReadBestBlock(CBlockLocator& locator);
103 
104  bool WriteOrderPosNext(int64_t nOrderPosNext);
105 
106  bool WriteDefaultKey(const CPubKey& vchPubKey);
107 
108  bool ReadPool(int64_t nPool, CKeyPool& keypool);
109  bool WritePool(int64_t nPool, const CKeyPool& keypool);
110  bool ErasePool(int64_t nPool);
111 
112  bool WriteMinVersion(int nVersion);
113 
114  bool ReadAccount(const std::string& strAccount, CAccount& account);
115  bool WriteAccount(const std::string& strAccount, const CAccount& account);
116 
118  bool WriteDestData(const std::string &address, const std::string &key, const std::string &value);
120  bool EraseDestData(const std::string &address, const std::string &key);
121 private:
122  bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
123 public:
124  bool WriteAccountingEntry(const CAccountingEntry& acentry);
125  int64_t GetAccountCreditDebit(const std::string& strAccount);
126  void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
127 
129  DBErrors LoadWallet(CWallet* pwallet);
130  DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
131  DBErrors ZapWalletTx(CWallet* pwallet);
132  static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
133  static bool Recover(CDBEnv& dbenv, std::string filename);
134 };
135 
136 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
137 
138 #endif // ANONCOIN_WALLETDB_H
CKeyMetadata(int64_t nCreateTime_)
Definition: walletdb.h:52
bool WriteMinVersion(int nVersion)
Definition: walletdb.cpp:168
Account information.
Definition: wallet.h:887
DBErrors FindWalletTx(CWallet *pwallet, std::vector< uint256 > &vTxHash)
Definition: walletdb.cpp:709
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:179
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: core.h:457
#define READWRITE(obj)
Definition: serialize.h:101
bool BackupWallet(const CWallet &wallet, const std::string &strDest)
CWalletDB(std::string strFilename, const char *pszMode="r+")
Definition: walletdb.h:76
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
Definition: walletdb.cpp:104
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:83
Master key for wallet encryption.
Definition: crypter.h:34
CKeyMetadata()
Definition: walletdb.h:48
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
Definition: walletdb.cpp:206
bool WriteWatchOnly(const CScript &script)
Definition: walletdb.cpp:116
bool ErasePurpose(const std::string &strAddress)
Definition: walletdb.cpp:48
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:184
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:31
bool WriteOrderPosNext(int64_t nOrderPosNext)
Definition: walletdb.cpp:139
void operator=(const CWalletDB &)
bool EraseTx(uint256 hash)
Definition: walletdb.cpp:60
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
Definition: key.h:177
DBErrors ZapWalletTx(CWallet *pwallet)
Definition: walletdb.cpp:772
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
Definition: walletdb.cpp:983
bool WritePool(int64_t nPool, const CKeyPool &keypool)
Definition: walletdb.cpp:156
int64_t GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:194
static const int CURRENT_VERSION
Definition: walletdb.h:44
bool WriteName(const std::string &strAddress, const std::string &strName)
Definition: walletdb.cpp:28
DBErrors LoadWallet(CWallet *pwallet)
Definition: walletdb.cpp:608
An encapsulated public key.
Definition: key.h:43
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:977
RAII class that provides access to a Berkeley database.
Definition: db.h:91
int64_t nCreateTime
Definition: walletdb.h:46
bool ErasePool(int64_t nPool)
Definition: walletdb.cpp:162
bool EraseWatchOnly(const CScript &script)
Definition: walletdb.cpp:122
bool WriteTx(uint256 hash, const CWalletTx &wtx)
Definition: walletdb.cpp:54
Access to the wallet database (wallet.dat)
Definition: walletdb.h:73
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:464
DBErrors ReorderTransactions(CWallet *)
Definition: walletdb.cpp:251
int nVersion
Definition: walletdb.h:45
bool ReadBestBlock(CBlockLocator &locator)
Definition: walletdb.cpp:134
bool WriteDefaultKey(const CPubKey &vchPubKey)
Definition: walletdb.cpp:145
bool WriteBestBlock(const CBlockLocator &locator)
Definition: walletdb.cpp:128
256-bit unsigned integer
Definition: uint256.h:532
bool ReadPool(int64_t nPool, CKeyPool &keypool)
Definition: walletdb.cpp:151
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
static bool Recover(CDBEnv &dbenv, std::string filename, bool fOnlyKeys)
Definition: walletdb.cpp:894
Internal transfers.
Definition: wallet.h:915
Definition: db.h:31
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:101
160-bit unsigned integer
Definition: uint256.h:420
bool EraseName(const std::string &strAddress)
Definition: walletdb.cpp:34
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
Definition: walletdb.cpp:110
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
Definition: walletdb.cpp:42
IMPLEMENT_SERIALIZE(READWRITE(this->nVersion);nVersion=this->nVersion;READWRITE(nCreateTime);) void SetNull()
Definition: walletdb.h:59
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:173
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:66
A key pool entry.
Definition: wallet.h:56