@@ -33,46 +33,46 @@ static std::atomic<unsigned int> nWalletDBUpdateCounter;
33
33
bool CWalletDB::WriteName (const std::string& strAddress, const std::string& strName)
34
34
{
35
35
nWalletDBUpdateCounter++;
36
- return Write (make_pair (std::string (" name" ), strAddress), strName);
36
+ return batch. Write (std:: make_pair (std::string (" name" ), strAddress), strName);
37
37
}
38
38
39
39
bool CWalletDB::EraseName (const std::string& strAddress)
40
40
{
41
41
// This should only be used for sending addresses, never for receiving addresses,
42
42
// receiving addresses must always have an address book entry if they're not change return.
43
43
nWalletDBUpdateCounter++;
44
- return Erase (make_pair (std::string (" name" ), strAddress));
44
+ return batch. Erase (std:: make_pair (std::string (" name" ), strAddress));
45
45
}
46
46
47
47
bool CWalletDB::WritePurpose (const std::string& strAddress, const std::string& strPurpose)
48
48
{
49
49
nWalletDBUpdateCounter++;
50
- return Write (make_pair (std::string (" purpose" ), strAddress), strPurpose);
50
+ return batch. Write (std:: make_pair (std::string (" purpose" ), strAddress), strPurpose);
51
51
}
52
52
53
53
bool CWalletDB::ErasePurpose (const std::string& strPurpose)
54
54
{
55
55
nWalletDBUpdateCounter++;
56
- return Erase (make_pair (std::string (" purpose" ), strPurpose));
56
+ return batch. Erase (std:: make_pair (std::string (" purpose" ), strPurpose));
57
57
}
58
58
59
59
bool CWalletDB::WriteTx (const CWalletTx& wtx)
60
60
{
61
61
nWalletDBUpdateCounter++;
62
- return Write (std::make_pair (std::string (" tx" ), wtx.GetHash ()), wtx);
62
+ return batch. Write (std::make_pair (std::string (" tx" ), wtx.GetHash ()), wtx);
63
63
}
64
64
65
65
bool CWalletDB::EraseTx (uint256 hash)
66
66
{
67
67
nWalletDBUpdateCounter++;
68
- return Erase (std::make_pair (std::string (" tx" ), hash));
68
+ return batch. Erase (std::make_pair (std::string (" tx" ), hash));
69
69
}
70
70
71
71
bool CWalletDB::WriteKey (const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
72
72
{
73
73
nWalletDBUpdateCounter++;
74
74
75
- if (!Write (std::make_pair (std::string (" keymeta" ), vchPubKey),
75
+ if (!batch. Write (std::make_pair (std::string (" keymeta" ), vchPubKey),
76
76
keyMeta, false ))
77
77
return false ;
78
78
@@ -82,7 +82,7 @@ bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, c
82
82
vchKey.insert (vchKey.end (), vchPubKey.begin (), vchPubKey.end ());
83
83
vchKey.insert (vchKey.end (), vchPrivKey.begin (), vchPrivKey.end ());
84
84
85
- return Write (std::make_pair (std::string (" key" ), vchPubKey), std::make_pair (vchPrivKey, Hash (vchKey.begin (), vchKey.end ())), false );
85
+ return batch. Write (std::make_pair (std::string (" key" ), vchPubKey), std::make_pair (vchPrivKey, Hash (vchKey.begin (), vchKey.end ())), false );
86
86
}
87
87
88
88
bool CWalletDB::WriteCryptedKey (const CPubKey& vchPubKey,
@@ -92,109 +92,109 @@ bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
92
92
const bool fEraseUnencryptedKey = true ;
93
93
nWalletDBUpdateCounter++;
94
94
95
- if (!Write (std::make_pair (std::string (" keymeta" ), vchPubKey),
95
+ if (!batch. Write (std::make_pair (std::string (" keymeta" ), vchPubKey),
96
96
keyMeta))
97
97
return false ;
98
98
99
- if (!Write (std::make_pair (std::string (" ckey" ), vchPubKey), vchCryptedSecret, false ))
99
+ if (!batch. Write (std::make_pair (std::string (" ckey" ), vchPubKey), vchCryptedSecret, false ))
100
100
return false ;
101
101
if (fEraseUnencryptedKey )
102
102
{
103
- Erase (std::make_pair (std::string (" key" ), vchPubKey));
104
- Erase (std::make_pair (std::string (" wkey" ), vchPubKey));
103
+ batch. Erase (std::make_pair (std::string (" key" ), vchPubKey));
104
+ batch. Erase (std::make_pair (std::string (" wkey" ), vchPubKey));
105
105
}
106
106
return true ;
107
107
}
108
108
109
109
bool CWalletDB::WriteMasterKey (unsigned int nID, const CMasterKey& kMasterKey )
110
110
{
111
111
nWalletDBUpdateCounter++;
112
- return Write (std::make_pair (std::string (" mkey" ), nID), kMasterKey , true );
112
+ return batch. Write (std::make_pair (std::string (" mkey" ), nID), kMasterKey , true );
113
113
}
114
114
115
115
bool CWalletDB::WriteCScript (const uint160& hash, const CScript& redeemScript)
116
116
{
117
117
nWalletDBUpdateCounter++;
118
- return Write (std::make_pair (std::string (" cscript" ), hash), *(const CScriptBase*)(&redeemScript), false );
118
+ return batch. Write (std::make_pair (std::string (" cscript" ), hash), *(const CScriptBase*)(&redeemScript), false );
119
119
}
120
120
121
121
bool CWalletDB::WriteWatchOnly (const CScript &dest, const CKeyMetadata& keyMeta)
122
122
{
123
123
nWalletDBUpdateCounter++;
124
- if (!Write (std::make_pair (std::string (" watchmeta" ), *(const CScriptBase*)(&dest)), keyMeta))
124
+ if (!batch. Write (std::make_pair (std::string (" watchmeta" ), *(const CScriptBase*)(&dest)), keyMeta))
125
125
return false ;
126
- return Write (std::make_pair (std::string (" watchs" ), *(const CScriptBase*)(&dest)), ' 1' );
126
+ return batch. Write (std::make_pair (std::string (" watchs" ), *(const CScriptBase*)(&dest)), ' 1' );
127
127
}
128
128
129
129
bool CWalletDB::EraseWatchOnly (const CScript &dest)
130
130
{
131
131
nWalletDBUpdateCounter++;
132
- if (!Erase (std::make_pair (std::string (" watchmeta" ), *(const CScriptBase*)(&dest))))
132
+ if (!batch. Erase (std::make_pair (std::string (" watchmeta" ), *(const CScriptBase*)(&dest))))
133
133
return false ;
134
- return Erase (std::make_pair (std::string (" watchs" ), *(const CScriptBase*)(&dest)));
134
+ return batch. Erase (std::make_pair (std::string (" watchs" ), *(const CScriptBase*)(&dest)));
135
135
}
136
136
137
137
bool CWalletDB::WriteBestBlock (const CBlockLocator& locator)
138
138
{
139
139
nWalletDBUpdateCounter++;
140
- Write (std::string (" bestblock" ), CBlockLocator ()); // Write empty block locator so versions that require a merkle branch automatically rescan
141
- return Write (std::string (" bestblock_nomerkle" ), locator);
140
+ batch. Write (std::string (" bestblock" ), CBlockLocator ()); // Write empty block locator so versions that require a merkle branch automatically rescan
141
+ return batch. Write (std::string (" bestblock_nomerkle" ), locator);
142
142
}
143
143
144
144
bool CWalletDB::ReadBestBlock (CBlockLocator& locator)
145
145
{
146
- if (Read (std::string (" bestblock" ), locator) && !locator.vHave .empty ()) return true ;
147
- return Read (std::string (" bestblock_nomerkle" ), locator);
146
+ if (batch. Read (std::string (" bestblock" ), locator) && !locator.vHave .empty ()) return true ;
147
+ return batch. Read (std::string (" bestblock_nomerkle" ), locator);
148
148
}
149
149
150
150
bool CWalletDB::WriteOrderPosNext (int64_t nOrderPosNext)
151
151
{
152
152
nWalletDBUpdateCounter++;
153
- return Write (std::string (" orderposnext" ), nOrderPosNext);
153
+ return batch. Write (std::string (" orderposnext" ), nOrderPosNext);
154
154
}
155
155
156
156
bool CWalletDB::WriteDefaultKey (const CPubKey& vchPubKey)
157
157
{
158
158
nWalletDBUpdateCounter++;
159
- return Write (std::string (" defaultkey" ), vchPubKey);
159
+ return batch. Write (std::string (" defaultkey" ), vchPubKey);
160
160
}
161
161
162
162
bool CWalletDB::ReadPool (int64_t nPool, CKeyPool& keypool)
163
163
{
164
- return Read (std::make_pair (std::string (" pool" ), nPool), keypool);
164
+ return batch. Read (std::make_pair (std::string (" pool" ), nPool), keypool);
165
165
}
166
166
167
167
bool CWalletDB::WritePool (int64_t nPool, const CKeyPool& keypool)
168
168
{
169
169
nWalletDBUpdateCounter++;
170
- return Write (std::make_pair (std::string (" pool" ), nPool), keypool);
170
+ return batch. Write (std::make_pair (std::string (" pool" ), nPool), keypool);
171
171
}
172
172
173
173
bool CWalletDB::ErasePool (int64_t nPool)
174
174
{
175
175
nWalletDBUpdateCounter++;
176
- return Erase (std::make_pair (std::string (" pool" ), nPool));
176
+ return batch. Erase (std::make_pair (std::string (" pool" ), nPool));
177
177
}
178
178
179
179
bool CWalletDB::WriteMinVersion (int nVersion)
180
180
{
181
- return Write (std::string (" minversion" ), nVersion);
181
+ return batch. Write (std::string (" minversion" ), nVersion);
182
182
}
183
183
184
184
bool CWalletDB::ReadAccount (const std::string& strAccount, CAccount& account)
185
185
{
186
186
account.SetNull ();
187
- return Read (make_pair (std::string (" acc" ), strAccount), account);
187
+ return batch. Read (std:: make_pair (std::string (" acc" ), strAccount), account);
188
188
}
189
189
190
190
bool CWalletDB::WriteAccount (const std::string& strAccount, const CAccount& account)
191
191
{
192
- return Write (make_pair (std::string (" acc" ), strAccount), account);
192
+ return batch. Write (std:: make_pair (std::string (" acc" ), strAccount), account);
193
193
}
194
194
195
195
bool CWalletDB::WriteAccountingEntry (const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
196
196
{
197
- return Write (std::make_pair (std::string (" acentry" ), std::make_pair (acentry.strAccount , nAccEntryNum)), acentry);
197
+ return batch. Write (std::make_pair (std::string (" acentry" ), std::make_pair (acentry.strAccount , nAccEntryNum)), acentry);
198
198
}
199
199
200
200
bool CWalletDB::WriteAccountingEntry_Backend (const CAccountingEntry& acentry)
@@ -218,7 +218,7 @@ void CWalletDB::ListAccountCreditDebit(const std::string& strAccount, std::list<
218
218
{
219
219
bool fAllAccounts = (strAccount == " *" );
220
220
221
- Dbc* pcursor = GetCursor ();
221
+ Dbc* pcursor = batch. GetCursor ();
222
222
if (!pcursor)
223
223
throw std::runtime_error (std::string (__func__) + " : cannot create DB cursor" );
224
224
bool setRange = true ;
@@ -229,7 +229,7 @@ void CWalletDB::ListAccountCreditDebit(const std::string& strAccount, std::list<
229
229
if (setRange)
230
230
ssKey << std::make_pair (std::string (" acentry" ), std::make_pair ((fAllAccounts ? std::string (" " ) : strAccount), uint64_t (0 )));
231
231
CDataStream ssValue (SER_DISK, CLIENT_VERSION);
232
- int ret = ReadAtCursor (pcursor, ssKey, ssValue, setRange);
232
+ int ret = batch. ReadAtCursor (pcursor, ssKey, ssValue, setRange);
233
233
setRange = false ;
234
234
if (ret == DB_NOTFOUND)
235
235
break ;
@@ -560,15 +560,15 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
560
560
LOCK (pwallet->cs_wallet );
561
561
try {
562
562
int nMinVersion = 0 ;
563
- if (Read ((std::string)" minversion" , nMinVersion))
563
+ if (batch. Read ((std::string)" minversion" , nMinVersion))
564
564
{
565
565
if (nMinVersion > CLIENT_VERSION)
566
566
return DB_TOO_NEW;
567
567
pwallet->LoadMinVersion (nMinVersion);
568
568
}
569
569
570
570
// Get cursor
571
- Dbc* pcursor = GetCursor ();
571
+ Dbc* pcursor = batch. GetCursor ();
572
572
if (!pcursor)
573
573
{
574
574
LogPrintf (" Error getting wallet database cursor\n " );
@@ -580,7 +580,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
580
580
// Read next record
581
581
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
582
582
CDataStream ssValue (SER_DISK, CLIENT_VERSION);
583
- int ret = ReadAtCursor (pcursor, ssKey, ssValue);
583
+ int ret = batch. ReadAtCursor (pcursor, ssKey, ssValue);
584
584
if (ret == DB_NOTFOUND)
585
585
break ;
586
586
else if (ret != 0 )
@@ -664,14 +664,14 @@ DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWal
664
664
665
665
try {
666
666
int nMinVersion = 0 ;
667
- if (Read ((std::string)" minversion" , nMinVersion))
667
+ if (batch. Read ((std::string)" minversion" , nMinVersion))
668
668
{
669
669
if (nMinVersion > CLIENT_VERSION)
670
670
return DB_TOO_NEW;
671
671
}
672
672
673
673
// Get cursor
674
- Dbc* pcursor = GetCursor ();
674
+ Dbc* pcursor = batch. GetCursor ();
675
675
if (!pcursor)
676
676
{
677
677
LogPrintf (" Error getting wallet database cursor\n " );
@@ -683,7 +683,7 @@ DBErrors CWalletDB::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWal
683
683
// Read next record
684
684
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
685
685
CDataStream ssValue (SER_DISK, CLIENT_VERSION);
686
- int ret = ReadAtCursor (pcursor, ssKey, ssValue);
686
+ int ret = batch. ReadAtCursor (pcursor, ssKey, ssValue);
687
687
if (ret == DB_NOTFOUND)
688
688
break ;
689
689
else if (ret != 0 )
@@ -855,20 +855,20 @@ bool CWalletDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path
855
855
bool CWalletDB::WriteDestData (const std::string &address, const std::string &key, const std::string &value)
856
856
{
857
857
nWalletDBUpdateCounter++;
858
- return Write (std::make_pair (std::string (" destdata" ), std::make_pair (address, key)), value);
858
+ return batch. Write (std::make_pair (std::string (" destdata" ), std::make_pair (address, key)), value);
859
859
}
860
860
861
861
bool CWalletDB::EraseDestData (const std::string &address, const std::string &key)
862
862
{
863
863
nWalletDBUpdateCounter++;
864
- return Erase (std::make_pair (std::string (" destdata" ), std::make_pair (address, key)));
864
+ return batch. Erase (std::make_pair (std::string (" destdata" ), std::make_pair (address, key)));
865
865
}
866
866
867
867
868
868
bool CWalletDB::WriteHDChain (const CHDChain& chain)
869
869
{
870
870
nWalletDBUpdateCounter++;
871
- return Write (std::string (" hdchain" ), chain);
871
+ return batch. Write (std::string (" hdchain" ), chain);
872
872
}
873
873
874
874
void CWalletDB::IncrementUpdateCounter ()
@@ -881,3 +881,27 @@ unsigned int CWalletDB::GetUpdateCounter()
881
881
return nWalletDBUpdateCounter;
882
882
}
883
883
884
+ bool CWalletDB::TxnBegin ()
885
+ {
886
+ return batch.TxnBegin ();
887
+ }
888
+
889
+ bool CWalletDB::TxnCommit ()
890
+ {
891
+ return batch.TxnCommit ();
892
+ }
893
+
894
+ bool CWalletDB::TxnAbort ()
895
+ {
896
+ return batch.TxnAbort ();
897
+ }
898
+
899
+ bool CWalletDB::ReadVersion (int & nVersion)
900
+ {
901
+ return batch.ReadVersion (nVersion);
902
+ }
903
+
904
+ bool CWalletDB::WriteVersion (int nVersion)
905
+ {
906
+ return batch.WriteVersion (nVersion);
907
+ }
0 commit comments