upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 581e5a7..7cfb7c5 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -56,6 +56,7 @@ string strWalletLoadError;
56static DbEnv* pdbenv = NULL; 56static DbEnv* pdbenv = NULL;
57static FILE* pdbErrFile = NULL; 57static FILE* pdbErrFile = NULL;
58static map<string, int> mapFileUseCount; 58static map<string, int> mapFileUseCount;
59static CWalletDBSQLite* pWalletSQLiteRuntime = NULL;
59 60
60DbEnv& GetDbEnv() 61DbEnv& GetDbEnv()
61{ 62{
@@ -95,6 +96,67 @@ public:
95} 96}
96instance_of_cdbinit; 97instance_of_cdbinit;
97 98
99bool WalletSQLiteRuntimeActive()
100{
101 return pWalletSQLiteRuntime != NULL;
102}
103
104bool WalletSQLiteRuntimeOpen(const string& strPath, string& strErrorRet)
105{
106 strErrorRet.clear();
107 if (!FileExists(strPath.c_str()))
108 {
109 strErrorRet = strprintf("SQLite wallet does not exist: %s",
110 strPath.c_str());
111 return false;
112 }
113
114 WalletSQLiteRuntimeClose();
115 std::auto_ptr<CWalletDBSQLite> db(new CWalletDBSQLite());
116 if (!db->Open(strPath, strErrorRet))
117 return false;
118
119 pWalletSQLiteRuntime = db.release();
120 return true;
121}
122
123void WalletSQLiteRuntimeClose()
124{
125 if (pWalletSQLiteRuntime)
126 {
127 delete pWalletSQLiteRuntime;
128 pWalletSQLiteRuntime = NULL;
129 }
130}
131
132bool WalletSQLiteRuntimeReadRecord(const vector<unsigned char>& vchKey,
133 vector<unsigned char>& vchValueRet)
134{
135 if (!pWalletSQLiteRuntime)
136 return false;
137 string strError;
138 return pWalletSQLiteRuntime->ReadRecord(vchKey, vchValueRet, strError);
139}
140
141bool WalletSQLiteRuntimeWriteRecord(const vector<unsigned char>& vchKey,
142 const vector<unsigned char>& vchValue,
143 bool fOverwrite)
144{
145 if (!pWalletSQLiteRuntime)
146 return false;
147 string strError;
148 return pWalletSQLiteRuntime->WriteRecord(vchKey, vchValue, strError,
149 fOverwrite);
150}
151
152bool WalletSQLiteRuntimeEraseRecord(const vector<unsigned char>& vchKey)
153{
154 if (!pWalletSQLiteRuntime)
155 return false;
156 string strError;
157 return pWalletSQLiteRuntime->EraseRecord(vchKey, strError);
158}
159
98 160
99CDB::CDB(const char* pszFile, const char* pszMode, bool fTxn) : pdb(NULL) 161CDB::CDB(const char* pszFile, const char* pszMode, bool fTxn) : pdb(NULL)
100{ 162{
@@ -651,6 +713,11 @@ bool CReviewDB::WriteReviews(uint256 hash, const vector<CReview>& vReviews)
651// CWalletDB 713// CWalletDB
652// 714//
653 715
716CWalletDB::CWalletDB(const char* pszMode, bool fTxn) :
717 CDB(WalletSQLiteRuntimeActive() ? NULL : "wallet.dat", pszMode, fTxn)
718{
719}
720
654class CSQLiteWalletRuntimeLoadVisitor : public CWalletRecordVisitor 721class CSQLiteWalletRuntimeLoadVisitor : public CWalletRecordVisitor
655{ 722{
656public: 723public: