@@ -812,7 +812,8 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
812812#endif
813813
814814 // Get cursor
815- if (!m_batch->StartCursor ())
815+ std::unique_ptr<DatabaseCursor> cursor = m_batch->GetNewCursor ();
816+ if (!cursor)
816817 {
817818 pwallet->WalletLogPrintf (" Error getting wallet database cursor\n " );
818819 return DBErrors::CORRUPT;
@@ -824,13 +825,13 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
824825 CDataStream ssKey (SER_DISK, CLIENT_VERSION);
825826 CDataStream ssValue (SER_DISK, CLIENT_VERSION);
826827 bool complete;
827- bool ret = m_batch-> ReadAtCursor (ssKey, ssValue, complete);
828+ bool ret = cursor-> Next (ssKey, ssValue, complete);
828829 if (complete) {
829830 break ;
830831 }
831832 else if (!ret)
832833 {
833- m_batch-> CloseCursor ();
834+ cursor. reset ();
834835 pwallet->WalletLogPrintf (" Error reading next record from wallet database\n " );
835836 return DBErrors::CORRUPT;
836837 }
@@ -878,7 +879,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
878879 } catch (...) {
879880 result = DBErrors::CORRUPT;
880881 }
881- m_batch->CloseCursor ();
882882
883883 // Set the active ScriptPubKeyMans
884884 for (auto spk_man_pair : wss.m_active_external_spks ) {
@@ -986,7 +986,8 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWal
986986 }
987987
988988 // Get cursor
989- if (!m_batch->StartCursor ())
989+ std::unique_ptr<DatabaseCursor> cursor = m_batch->GetNewCursor ();
990+ if (!cursor)
990991 {
991992 LogPrintf (" Error getting wallet database cursor\n " );
992993 return DBErrors::CORRUPT;
@@ -998,11 +999,10 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWal
998999 CDataStream ssKey (SER_DISK, CLIENT_VERSION);
9991000 CDataStream ssValue (SER_DISK, CLIENT_VERSION);
10001001 bool complete;
1001- bool ret = m_batch-> ReadAtCursor (ssKey, ssValue, complete);
1002+ bool ret = cursor-> Next (ssKey, ssValue, complete);
10021003 if (complete) {
10031004 break ;
10041005 } else if (!ret) {
1005- m_batch->CloseCursor ();
10061006 LogPrintf (" Error reading next record from wallet database\n " );
10071007 return DBErrors::CORRUPT;
10081008 }
@@ -1020,7 +1020,6 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWal
10201020 } catch (...) {
10211021 result = DBErrors::CORRUPT;
10221022 }
1023- m_batch->CloseCursor ();
10241023
10251024 return result;
10261025}
@@ -1114,7 +1113,8 @@ bool WalletBatch::WriteWalletFlags(const uint64_t flags)
11141113bool WalletBatch::EraseRecords (const std::unordered_set<std::string>& types)
11151114{
11161115 // Get cursor
1117- if (!m_batch->StartCursor ())
1116+ std::unique_ptr<DatabaseCursor> cursor = m_batch->GetNewCursor ();
1117+ if (!cursor)
11181118 {
11191119 return false ;
11201120 }
@@ -1126,13 +1126,12 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
11261126 CDataStream key (SER_DISK, CLIENT_VERSION);
11271127 CDataStream value (SER_DISK, CLIENT_VERSION);
11281128 bool complete;
1129- bool ret = m_batch-> ReadAtCursor (key, value, complete);
1129+ bool ret = cursor-> Next (key, value, complete);
11301130 if (complete) {
11311131 break ;
11321132 }
11331133 else if (!ret)
11341134 {
1135- m_batch->CloseCursor ();
11361135 return false ;
11371136 }
11381137
@@ -1146,7 +1145,6 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
11461145 m_batch->Erase (key_data);
11471146 }
11481147 }
1149- m_batch->CloseCursor ();
11501148 return true ;
11511149}
11521150
0 commit comments