mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-06 02:33:28 +01:00
Merge #19308: wallet: BerkeleyBatch Handle cursor internally
ca24edfbc1walletdb: Handle cursor internally (Andrew Chow) Pull request description: Instead of returning a Dbc (BDB cursor object) and having the caller deal with the cursor, make BerkeleyBatch handle the cursor internally. Split from #18971 ACKs for top commit: ryanofsky: Code review ACKca24edfbc1. Changes since last review: StartCursor rename, moving CloseCursor calls near returns promag: Code review ACKca24edfbc1. Tree-SHA512: f029b498c7f275aedca53ce7ade7cb99c82975fd6cad17346a4990fb3bcc54e2a5309b32053bd13def9ee464d331b036ac79abb8fc4fa561170c6cfc85283447
This commit is contained in:
@@ -700,8 +700,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
}
|
||||
|
||||
// Get cursor
|
||||
Dbc* pcursor = m_batch.GetCursor();
|
||||
if (!pcursor)
|
||||
if (!m_batch.StartCursor())
|
||||
{
|
||||
pwallet->WalletLogPrintf("Error getting wallet database cursor\n");
|
||||
return DBErrors::CORRUPT;
|
||||
@@ -712,11 +711,14 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
// Read next record
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||
int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue);
|
||||
if (ret == DB_NOTFOUND)
|
||||
bool complete;
|
||||
bool ret = m_batch.ReadAtCursor(ssKey, ssValue, complete);
|
||||
if (complete) {
|
||||
break;
|
||||
else if (ret != 0)
|
||||
}
|
||||
else if (!ret)
|
||||
{
|
||||
m_batch.CloseCursor();
|
||||
pwallet->WalletLogPrintf("Error reading next record from wallet database\n");
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
@@ -743,10 +745,10 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
if (!strErr.empty())
|
||||
pwallet->WalletLogPrintf("%s\n", strErr);
|
||||
}
|
||||
pcursor->close();
|
||||
} catch (...) {
|
||||
result = DBErrors::CORRUPT;
|
||||
}
|
||||
m_batch.CloseCursor();
|
||||
|
||||
// Set the active ScriptPubKeyMans
|
||||
for (auto spk_man_pair : wss.m_active_external_spks) {
|
||||
@@ -850,8 +852,7 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWal
|
||||
}
|
||||
|
||||
// Get cursor
|
||||
Dbc* pcursor = m_batch.GetCursor();
|
||||
if (!pcursor)
|
||||
if (!m_batch.StartCursor())
|
||||
{
|
||||
LogPrintf("Error getting wallet database cursor\n");
|
||||
return DBErrors::CORRUPT;
|
||||
@@ -862,11 +863,12 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWal
|
||||
// Read next record
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||
int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue);
|
||||
if (ret == DB_NOTFOUND)
|
||||
bool complete;
|
||||
bool ret = m_batch.ReadAtCursor(ssKey, ssValue, complete);
|
||||
if (complete) {
|
||||
break;
|
||||
else if (ret != 0)
|
||||
{
|
||||
} else if (!ret) {
|
||||
m_batch.CloseCursor();
|
||||
LogPrintf("Error reading next record from wallet database\n");
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
@@ -881,10 +883,10 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWal
|
||||
ssValue >> vWtx.back();
|
||||
}
|
||||
}
|
||||
pcursor->close();
|
||||
} catch (...) {
|
||||
result = DBErrors::CORRUPT;
|
||||
}
|
||||
m_batch.CloseCursor();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user