mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
walletdb: moveonly: Move BerkeleyBatch Cursor and Txn funcs to cpp
Put the implementation in the cpp, not the h file.
This commit is contained in:
@@ -761,6 +761,67 @@ void BerkeleyDatabase::ReloadDbEnv()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dbc* BerkeleyBatch::GetCursor()
|
||||||
|
{
|
||||||
|
if (!pdb)
|
||||||
|
return nullptr;
|
||||||
|
Dbc* pcursor = nullptr;
|
||||||
|
int ret = pdb->cursor(nullptr, &pcursor, 0);
|
||||||
|
if (ret != 0)
|
||||||
|
return nullptr;
|
||||||
|
return pcursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BerkeleyBatch::ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue)
|
||||||
|
{
|
||||||
|
// Read at cursor
|
||||||
|
SafeDbt datKey;
|
||||||
|
SafeDbt datValue;
|
||||||
|
int ret = pcursor->get(datKey, datValue, DB_NEXT);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
else if (datKey.get_data() == nullptr || datValue.get_data() == nullptr)
|
||||||
|
return 99999;
|
||||||
|
|
||||||
|
// Convert to streams
|
||||||
|
ssKey.SetType(SER_DISK);
|
||||||
|
ssKey.clear();
|
||||||
|
ssKey.write((char*)datKey.get_data(), datKey.get_size());
|
||||||
|
ssValue.SetType(SER_DISK);
|
||||||
|
ssValue.clear();
|
||||||
|
ssValue.write((char*)datValue.get_data(), datValue.get_size());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BerkeleyBatch::TxnBegin()
|
||||||
|
{
|
||||||
|
if (!pdb || activeTxn)
|
||||||
|
return false;
|
||||||
|
DbTxn* ptxn = env->TxnBegin();
|
||||||
|
if (!ptxn)
|
||||||
|
return false;
|
||||||
|
activeTxn = ptxn;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BerkeleyBatch::TxnCommit()
|
||||||
|
{
|
||||||
|
if (!pdb || !activeTxn)
|
||||||
|
return false;
|
||||||
|
int ret = activeTxn->commit(0);
|
||||||
|
activeTxn = nullptr;
|
||||||
|
return (ret == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BerkeleyBatch::TxnAbort()
|
||||||
|
{
|
||||||
|
if (!pdb || !activeTxn)
|
||||||
|
return false;
|
||||||
|
int ret = activeTxn->abort();
|
||||||
|
activeTxn = nullptr;
|
||||||
|
return (ret == 0);
|
||||||
|
}
|
||||||
|
|
||||||
std::string BerkeleyDatabaseVersion()
|
std::string BerkeleyDatabaseVersion()
|
||||||
{
|
{
|
||||||
return DbEnv::version(nullptr, nullptr, nullptr);
|
return DbEnv::version(nullptr, nullptr, nullptr);
|
||||||
|
|||||||
@@ -326,66 +326,11 @@ public:
|
|||||||
return (ret == 0);
|
return (ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dbc* GetCursor()
|
Dbc* GetCursor();
|
||||||
{
|
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue);
|
||||||
if (!pdb)
|
bool TxnBegin();
|
||||||
return nullptr;
|
bool TxnCommit();
|
||||||
Dbc* pcursor = nullptr;
|
bool TxnAbort();
|
||||||
int ret = pdb->cursor(nullptr, &pcursor, 0);
|
|
||||||
if (ret != 0)
|
|
||||||
return nullptr;
|
|
||||||
return pcursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue)
|
|
||||||
{
|
|
||||||
// Read at cursor
|
|
||||||
SafeDbt datKey;
|
|
||||||
SafeDbt datValue;
|
|
||||||
int ret = pcursor->get(datKey, datValue, DB_NEXT);
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
else if (datKey.get_data() == nullptr || datValue.get_data() == nullptr)
|
|
||||||
return 99999;
|
|
||||||
|
|
||||||
// Convert to streams
|
|
||||||
ssKey.SetType(SER_DISK);
|
|
||||||
ssKey.clear();
|
|
||||||
ssKey.write((char*)datKey.get_data(), datKey.get_size());
|
|
||||||
ssValue.SetType(SER_DISK);
|
|
||||||
ssValue.clear();
|
|
||||||
ssValue.write((char*)datValue.get_data(), datValue.get_size());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TxnBegin()
|
|
||||||
{
|
|
||||||
if (!pdb || activeTxn)
|
|
||||||
return false;
|
|
||||||
DbTxn* ptxn = env->TxnBegin();
|
|
||||||
if (!ptxn)
|
|
||||||
return false;
|
|
||||||
activeTxn = ptxn;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TxnCommit()
|
|
||||||
{
|
|
||||||
if (!pdb || !activeTxn)
|
|
||||||
return false;
|
|
||||||
int ret = activeTxn->commit(0);
|
|
||||||
activeTxn = nullptr;
|
|
||||||
return (ret == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TxnAbort()
|
|
||||||
{
|
|
||||||
if (!pdb || !activeTxn)
|
|
||||||
return false;
|
|
||||||
int ret = activeTxn->abort();
|
|
||||||
activeTxn = nullptr;
|
|
||||||
return (ret == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
|
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user