diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-17 11:32:45 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-17 11:32:45 -0300 |
| commit | d082210c5d080c0a91412b94a109d8e73422eb31 (patch) | |
| tree | 5372e845b7c6cf75fb9aaab2caaaf15eaadd0dd3 /src/db.cpp | |
| parent | 0175bb9205d7e3dc474aede8000a05f1d70ed0e6 (diff) | |
wallet: route CWalletDB through SQLite runtime
Diffstat (limited to 'src/db.cpp')
| -rw-r--r-- | src/db.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
| @@ -56,6 +56,7 @@ string strWalletLoadError; | |||
| 56 | static DbEnv* pdbenv = NULL; | 56 | static DbEnv* pdbenv = NULL; |
| 57 | static FILE* pdbErrFile = NULL; | 57 | static FILE* pdbErrFile = NULL; |
| 58 | static map<string, int> mapFileUseCount; | 58 | static map<string, int> mapFileUseCount; |
| 59 | static CWalletDBSQLite* pWalletSQLiteRuntime = NULL; | ||
| 59 | 60 | ||
| 60 | DbEnv& GetDbEnv() | 61 | DbEnv& GetDbEnv() |
| 61 | { | 62 | { |
| @@ -95,6 +96,67 @@ public: | |||
| 95 | } | 96 | } |
| 96 | instance_of_cdbinit; | 97 | instance_of_cdbinit; |
| 97 | 98 | ||
| 99 | bool WalletSQLiteRuntimeActive() | ||
| 100 | { | ||
| 101 | return pWalletSQLiteRuntime != NULL; | ||
| 102 | } | ||
| 103 | |||
| 104 | bool 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 | |||
| 123 | void WalletSQLiteRuntimeClose() | ||
| 124 | { | ||
| 125 | if (pWalletSQLiteRuntime) | ||
| 126 | { | ||
| 127 | delete pWalletSQLiteRuntime; | ||
| 128 | pWalletSQLiteRuntime = NULL; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | bool 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 | |||
| 141 | bool 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 | |||
| 152 | bool 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 | ||
| 99 | CDB::CDB(const char* pszFile, const char* pszMode, bool fTxn) : pdb(NULL) | 161 | CDB::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 | ||
| 716 | CWalletDB::CWalletDB(const char* pszMode, bool fTxn) : | ||
| 717 | CDB(WalletSQLiteRuntimeActive() ? NULL : "wallet.dat", pszMode, fTxn) | ||
| 718 | { | ||
| 719 | } | ||
| 720 | |||
| 654 | class CSQLiteWalletRuntimeLoadVisitor : public CWalletRecordVisitor | 721 | class CSQLiteWalletRuntimeLoadVisitor : public CWalletRecordVisitor |
| 655 | { | 722 | { |
| 656 | public: | 723 | public: |