@@ -69,48 +69,39 @@ static std::atomic<unsigned int> nWalletDBUpdateCounter;
69
69
70
70
bool CWalletDB::WriteName (const std::string& strAddress, const std::string& strName)
71
71
{
72
- nWalletDBUpdateCounter++;
73
- return batch.Write (std::make_pair (std::string (DBKeys::NAME), strAddress), strName);
72
+ return WriteIC (std::make_pair (std::string (DBKeys::NAME), strAddress), strName);
74
73
}
75
74
76
75
bool CWalletDB::EraseName (const std::string& strAddress)
77
76
{
78
77
// This should only be used for sending addresses, never for receiving addresses,
79
78
// receiving addresses must always have an address book entry if they're not change return.
80
- nWalletDBUpdateCounter++;
81
- return batch.Erase (std::make_pair (std::string (DBKeys::NAME), strAddress));
79
+ return EraseIC (std::make_pair (std::string (DBKeys::NAME), strAddress));
82
80
}
83
81
84
82
bool CWalletDB::WritePurpose (const std::string& strAddress, const std::string& strPurpose)
85
83
{
86
- nWalletDBUpdateCounter++;
87
- return batch.Write (std::make_pair (std::string (DBKeys::PURPOSE), strAddress), strPurpose);
84
+ return WriteIC (std::make_pair (std::string (DBKeys::PURPOSE), strAddress), strPurpose);
88
85
}
89
86
90
87
bool CWalletDB::ErasePurpose (const std::string& strPurpose)
91
88
{
92
- nWalletDBUpdateCounter++;
93
- return batch.Erase (std::make_pair (std::string (DBKeys::PURPOSE), strPurpose));
89
+ return EraseIC (std::make_pair (std::string (DBKeys::PURPOSE), strPurpose));
94
90
}
95
91
96
92
bool CWalletDB::WriteTx (const CWalletTx& wtx)
97
93
{
98
- nWalletDBUpdateCounter++;
99
- return batch.Write (std::make_pair (std::string (DBKeys::TX), wtx.GetHash ()), wtx);
94
+ return WriteIC (std::make_pair (std::string (DBKeys::TX), wtx.GetHash ()), wtx);
100
95
}
101
96
102
97
bool CWalletDB::EraseTx (uint256 hash)
103
98
{
104
- nWalletDBUpdateCounter++;
105
- return batch.Erase (std::make_pair (std::string (DBKeys::TX), hash));
99
+ return EraseIC (std::make_pair (std::string (DBKeys::TX), hash));
106
100
}
107
101
108
102
bool CWalletDB::WriteKey (const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
109
103
{
110
- nWalletDBUpdateCounter++;
111
-
112
- if (!batch.Write (std::make_pair (std::string (DBKeys::KEYMETA), vchPubKey),
113
- keyMeta, false ))
104
+ if (!WriteIC (std::make_pair (std::string (DBKeys::KEYMETA), vchPubKey), keyMeta, false ))
114
105
return false ;
115
106
116
107
// hash pubkey/privkey to accelerate wallet load
@@ -119,47 +110,42 @@ bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, c
119
110
vchKey.insert (vchKey.end (), vchPubKey.begin (), vchPubKey.end ());
120
111
vchKey.insert (vchKey.end (), vchPrivKey.begin (), vchPrivKey.end ());
121
112
122
- return batch. Write (std::make_pair (std::string (DBKeys::KEY), vchPubKey), std::make_pair (vchPrivKey, Hash (vchKey.begin (), vchKey.end ())), false );
113
+ return WriteIC (std::make_pair (std::string (DBKeys::KEY), vchPubKey), std::make_pair (vchPrivKey, Hash (vchKey.begin (), vchKey.end ())), false );
123
114
}
124
115
125
116
bool CWalletDB::WriteCryptedKey (const CPubKey& vchPubKey,
126
117
const std::vector<unsigned char >& vchCryptedSecret,
127
118
const CKeyMetadata& keyMeta)
128
119
{
129
120
const bool fEraseUnencryptedKey = true ;
130
- nWalletDBUpdateCounter++;
131
121
132
- if (!batch.Write (std::make_pair (std::string (DBKeys::KEYMETA), vchPubKey),
133
- keyMeta))
122
+ if (!WriteIC (std::make_pair (std::string (DBKeys::KEYMETA), vchPubKey), keyMeta))
134
123
return false ;
135
124
136
- if (!batch. Write (std::make_pair (std::string (DBKeys::CRYPTED_KEY), vchPubKey), vchCryptedSecret, false ))
125
+ if (!WriteIC (std::make_pair (std::string (DBKeys::CRYPTED_KEY), vchPubKey), vchCryptedSecret, false ))
137
126
return false ;
138
127
if (fEraseUnencryptedKey ) {
139
- batch. Erase (std::make_pair (std::string (DBKeys::KEY), vchPubKey));
128
+ EraseIC (std::make_pair (std::string (DBKeys::KEY), vchPubKey));
140
129
}
130
+
141
131
return true ;
142
132
}
143
133
144
134
bool CWalletDB::WriteSaplingZKey (const libzcash::SaplingIncomingViewingKey &ivk,
145
135
const libzcash::SaplingExtendedSpendingKey &key,
146
136
const CKeyMetadata &keyMeta)
147
137
{
148
- nWalletDBUpdateCounter++;
149
-
150
- if (!batch.Write (std::make_pair (std::string (DBKeys::SAP_KEYMETA), ivk), keyMeta))
138
+ if (!WriteIC (std::make_pair (std::string (DBKeys::SAP_KEYMETA), ivk), keyMeta))
151
139
return false ;
152
140
153
- return batch. Write (std::make_pair (std::string (DBKeys::SAP_KEY), ivk), key, false );
141
+ return WriteIC (std::make_pair (std::string (DBKeys::SAP_KEY), ivk), key, false );
154
142
}
155
143
156
144
bool CWalletDB::WriteSaplingPaymentAddress (
157
145
const libzcash::SaplingPaymentAddress &addr,
158
146
const libzcash::SaplingIncomingViewingKey &ivk)
159
147
{
160
- nWalletDBUpdateCounter++;
161
-
162
- return batch.Write (std::make_pair (std::string (DBKeys::SAP_ADDR), addr), ivk, false );
148
+ return WriteIC (std::make_pair (std::string (DBKeys::SAP_ADDR), addr), ivk, false );
163
149
}
164
150
165
151
bool CWalletDB::WriteCryptedSaplingZKey (
@@ -168,25 +154,23 @@ bool CWalletDB::WriteCryptedSaplingZKey(
168
154
const CKeyMetadata &keyMeta)
169
155
{
170
156
const bool fEraseUnencryptedKey = true ;
171
- nWalletDBUpdateCounter++;
172
157
auto ivk = extfvk.fvk .in_viewing_key ();
173
158
174
- if (!batch. Write (std::make_pair (std::string (DBKeys::SAP_KEYMETA), ivk), keyMeta))
159
+ if (!WriteIC (std::make_pair (std::string (DBKeys::SAP_KEYMETA), ivk), keyMeta))
175
160
return false ;
176
161
177
- if (!batch. Write (std::make_pair (std::string (DBKeys::SAP_KEY_CRIPTED), ivk), std::make_pair (extfvk, vchCryptedSecret), false ))
162
+ if (!WriteIC (std::make_pair (std::string (DBKeys::SAP_KEY_CRIPTED), ivk), std::make_pair (extfvk, vchCryptedSecret), false ))
178
163
return false ;
179
164
180
165
if (fEraseUnencryptedKey ) {
181
- batch. Erase (std::make_pair (std::string (DBKeys::SAP_KEY), ivk));
166
+ EraseIC (std::make_pair (std::string (DBKeys::SAP_KEY), ivk));
182
167
}
183
168
return true ;
184
169
}
185
170
186
171
bool CWalletDB::WriteSaplingCommonOVK (const uint256& ovk)
187
172
{
188
- nWalletDBUpdateCounter++;
189
- return batch.Write (std::string (DBKeys::SAP_COMMON_OVK), ovk);
173
+ return WriteIC (std::string (DBKeys::SAP_COMMON_OVK), ovk);
190
174
}
191
175
192
176
bool CWalletDB::ReadSaplingCommonOVK (uint256& ovkRet)
@@ -196,40 +180,33 @@ bool CWalletDB::ReadSaplingCommonOVK(uint256& ovkRet)
196
180
197
181
bool CWalletDB::WriteWitnessCacheSize (int64_t nWitnessCacheSize)
198
182
{
199
- nWalletDBUpdateCounter++;
200
- return batch.Write (std::string (DBKeys::SAP_WITNESS_CACHE_SIZE), nWitnessCacheSize);
183
+ return WriteIC (std::string (DBKeys::SAP_WITNESS_CACHE_SIZE), nWitnessCacheSize);
201
184
}
202
185
203
186
bool CWalletDB::WriteMasterKey (unsigned int nID, const CMasterKey& kMasterKey )
204
187
{
205
- nWalletDBUpdateCounter++;
206
- return batch.Write (std::make_pair (std::string (DBKeys::MASTER_KEY), nID), kMasterKey , true );
188
+ return WriteIC (std::make_pair (std::string (DBKeys::MASTER_KEY), nID), kMasterKey , true );
207
189
}
208
190
209
191
bool CWalletDB::WriteCScript (const uint160& hash, const CScript& redeemScript)
210
192
{
211
- nWalletDBUpdateCounter++;
212
- return batch.Write (std::make_pair (std::string (DBKeys::CSCRIPT), hash), redeemScript, false );
193
+ return WriteIC (std::make_pair (std::string (DBKeys::CSCRIPT), hash), redeemScript, false );
213
194
}
214
195
215
196
bool CWalletDB::WriteWatchOnly (const CScript& dest)
216
197
{
217
- nWalletDBUpdateCounter++;
218
- return batch.Write (std::make_pair (std::string (DBKeys::WATCHS), dest), ' 1' );
198
+ return WriteIC (std::make_pair (std::string (DBKeys::WATCHS), dest), ' 1' );
219
199
}
220
200
221
201
bool CWalletDB::EraseWatchOnly (const CScript& dest)
222
202
{
223
-
224
- nWalletDBUpdateCounter++;
225
- return batch.Erase (std::make_pair (std::string (DBKeys::WATCHS), dest));
203
+ return EraseIC (std::make_pair (std::string (DBKeys::WATCHS), dest));
226
204
}
227
205
228
206
bool CWalletDB::WriteBestBlock (const CBlockLocator& locator)
229
207
{
230
- nWalletDBUpdateCounter++;
231
- batch.Write (std::string (DBKeys::BESTBLOCK), CBlockLocator ()); // Write empty block locator so versions that require a merkle branch automatically rescan
232
- return batch.Write (std::string (DBKeys::BESTBLOCK_NOMERKLE), locator);
208
+ WriteIC (std::string (DBKeys::BESTBLOCK), CBlockLocator ()); // Write empty block locator so versions that require a merkle branch automatically rescan
209
+ return WriteIC (std::string (DBKeys::BESTBLOCK_NOMERKLE), locator);
233
210
}
234
211
235
212
bool CWalletDB::ReadBestBlock (CBlockLocator& locator)
@@ -240,35 +217,30 @@ bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
240
217
241
218
bool CWalletDB::WriteOrderPosNext (int64_t nOrderPosNext)
242
219
{
243
- nWalletDBUpdateCounter++;
244
- return batch.Write (std::string (DBKeys::ORDERPOSNEXT), nOrderPosNext);
220
+ return WriteIC (std::string (DBKeys::ORDERPOSNEXT), nOrderPosNext);
245
221
}
246
222
247
223
bool CWalletDB::WriteStakeSplitThreshold (const CAmount& nStakeSplitThreshold)
248
224
{
249
- nWalletDBUpdateCounter++;
250
- return batch.Write (std::string (DBKeys::STAKE_SPLIT_THRESHOLD), nStakeSplitThreshold);
225
+ return WriteIC (std::string (DBKeys::STAKE_SPLIT_THRESHOLD), nStakeSplitThreshold);
251
226
}
252
227
253
228
bool CWalletDB::WriteUseCustomFee (bool fUse )
254
229
{
255
- nWalletDBUpdateCounter++;
256
- return batch.Write (std::string (DBKeys::USE_CUSTOM_FEE), fUse );
230
+ return WriteIC (std::string (DBKeys::USE_CUSTOM_FEE), fUse );
257
231
}
258
232
259
233
bool CWalletDB::WriteCustomFeeValue (const CAmount& nFee)
260
234
{
261
- nWalletDBUpdateCounter++;
262
- return batch.Write (std::string (DBKeys::CUSTOM_FEE_VALUE), nFee);
235
+ return WriteIC (std::string (DBKeys::CUSTOM_FEE_VALUE), nFee);
263
236
}
264
237
265
238
bool CWalletDB::WriteAutoCombineSettings (bool fEnable , CAmount nCombineThreshold)
266
239
{
267
- nWalletDBUpdateCounter++;
268
240
std::pair<bool , CAmount> pSettings;
269
241
pSettings.first = fEnable ;
270
242
pSettings.second = nCombineThreshold;
271
- return batch. Write (std::string (DBKeys::AUTOCOMBINE), pSettings, true );
243
+ return WriteIC (std::string (DBKeys::AUTOCOMBINE), pSettings, true );
272
244
}
273
245
274
246
bool CWalletDB::ReadPool (int64_t nPool, CKeyPool& keypool)
@@ -278,14 +250,12 @@ bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
278
250
279
251
bool CWalletDB::WritePool (int64_t nPool, const CKeyPool& keypool)
280
252
{
281
- nWalletDBUpdateCounter++;
282
- return batch.Write (std::make_pair (std::string (DBKeys::POOL), nPool), keypool);
253
+ return WriteIC (std::make_pair (std::string (DBKeys::POOL), nPool), keypool);
283
254
}
284
255
285
256
bool CWalletDB::ErasePool (int64_t nPool)
286
257
{
287
- nWalletDBUpdateCounter++;
288
- return batch.Erase (std::make_pair (std::string (DBKeys::POOL), nPool));
258
+ return EraseIC (std::make_pair (std::string (DBKeys::POOL), nPool));
289
259
}
290
260
291
261
bool CWalletDB::WriteMinVersion (int nVersion)
@@ -295,10 +265,9 @@ bool CWalletDB::WriteMinVersion(int nVersion)
295
265
296
266
bool CWalletDB::WriteHDChain (const CHDChain& chain)
297
267
{
298
- nWalletDBUpdateCounter++;
299
268
std::string key = chain.chainType == HDChain::ChainCounterType::Sapling ?
300
269
DBKeys::SAP_HDCHAIN : DBKeys::HDCHAIN;
301
- return batch. Write (key, chain);
270
+ return WriteIC (key, chain);
302
271
}
303
272
304
273
DBErrors CWalletDB::ReorderTransactions (CWallet* pwallet)
@@ -1140,14 +1109,12 @@ bool CWalletDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path
1140
1109
1141
1110
bool CWalletDB::WriteDestData (const std::string& address, const std::string& key, const std::string& value)
1142
1111
{
1143
- nWalletDBUpdateCounter++;
1144
- return batch.Write (std::make_pair (std::string (DBKeys::DESTDATA), std::make_pair (address, key)), value);
1112
+ return WriteIC (std::make_pair (std::string (DBKeys::DESTDATA), std::make_pair (address, key)), value);
1145
1113
}
1146
1114
1147
1115
bool CWalletDB::EraseDestData (const std::string& address, const std::string& key)
1148
1116
{
1149
- nWalletDBUpdateCounter++;
1150
- return batch.Erase (std::make_pair (std::string (DBKeys::DESTDATA), std::make_pair (address, key)));
1117
+ return EraseIC (std::make_pair (std::string (DBKeys::DESTDATA), std::make_pair (address, key)));
1151
1118
}
1152
1119
1153
1120
void CWalletDB::IncrementUpdateCounter ()
0 commit comments