Skip to content

Commit 8f03364

Browse files
committed
walletdb: moveonly: Move BerkeleyBatch Cursor and Txn funcs to cpp
Put the implementation in the cpp, not the h file.
1 parent 25a6557 commit 8f03364

File tree

2 files changed

+66
-60
lines changed

2 files changed

+66
-60
lines changed

src/wallet/db.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,67 @@ void BerkeleyDatabase::ReloadDbEnv()
761761
}
762762
}
763763

764+
Dbc* BerkeleyBatch::GetCursor()
765+
{
766+
if (!pdb)
767+
return nullptr;
768+
Dbc* pcursor = nullptr;
769+
int ret = pdb->cursor(nullptr, &pcursor, 0);
770+
if (ret != 0)
771+
return nullptr;
772+
return pcursor;
773+
}
774+
775+
int BerkeleyBatch::ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue)
776+
{
777+
// Read at cursor
778+
SafeDbt datKey;
779+
SafeDbt datValue;
780+
int ret = pcursor->get(datKey, datValue, DB_NEXT);
781+
if (ret != 0)
782+
return ret;
783+
else if (datKey.get_data() == nullptr || datValue.get_data() == nullptr)
784+
return 99999;
785+
786+
// Convert to streams
787+
ssKey.SetType(SER_DISK);
788+
ssKey.clear();
789+
ssKey.write((char*)datKey.get_data(), datKey.get_size());
790+
ssValue.SetType(SER_DISK);
791+
ssValue.clear();
792+
ssValue.write((char*)datValue.get_data(), datValue.get_size());
793+
return 0;
794+
}
795+
796+
bool BerkeleyBatch::TxnBegin()
797+
{
798+
if (!pdb || activeTxn)
799+
return false;
800+
DbTxn* ptxn = env->TxnBegin();
801+
if (!ptxn)
802+
return false;
803+
activeTxn = ptxn;
804+
return true;
805+
}
806+
807+
bool BerkeleyBatch::TxnCommit()
808+
{
809+
if (!pdb || !activeTxn)
810+
return false;
811+
int ret = activeTxn->commit(0);
812+
activeTxn = nullptr;
813+
return (ret == 0);
814+
}
815+
816+
bool BerkeleyBatch::TxnAbort()
817+
{
818+
if (!pdb || !activeTxn)
819+
return false;
820+
int ret = activeTxn->abort();
821+
activeTxn = nullptr;
822+
return (ret == 0);
823+
}
824+
764825
std::string BerkeleyDatabaseVersion()
765826
{
766827
return DbEnv::version(nullptr, nullptr, nullptr);

src/wallet/db.h

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -326,66 +326,11 @@ class BerkeleyBatch
326326
return (ret == 0);
327327
}
328328

329-
Dbc* GetCursor()
330-
{
331-
if (!pdb)
332-
return nullptr;
333-
Dbc* pcursor = nullptr;
334-
int ret = pdb->cursor(nullptr, &pcursor, 0);
335-
if (ret != 0)
336-
return nullptr;
337-
return pcursor;
338-
}
339-
340-
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue)
341-
{
342-
// Read at cursor
343-
SafeDbt datKey;
344-
SafeDbt datValue;
345-
int ret = pcursor->get(datKey, datValue, DB_NEXT);
346-
if (ret != 0)
347-
return ret;
348-
else if (datKey.get_data() == nullptr || datValue.get_data() == nullptr)
349-
return 99999;
350-
351-
// Convert to streams
352-
ssKey.SetType(SER_DISK);
353-
ssKey.clear();
354-
ssKey.write((char*)datKey.get_data(), datKey.get_size());
355-
ssValue.SetType(SER_DISK);
356-
ssValue.clear();
357-
ssValue.write((char*)datValue.get_data(), datValue.get_size());
358-
return 0;
359-
}
360-
361-
bool TxnBegin()
362-
{
363-
if (!pdb || activeTxn)
364-
return false;
365-
DbTxn* ptxn = env->TxnBegin();
366-
if (!ptxn)
367-
return false;
368-
activeTxn = ptxn;
369-
return true;
370-
}
371-
372-
bool TxnCommit()
373-
{
374-
if (!pdb || !activeTxn)
375-
return false;
376-
int ret = activeTxn->commit(0);
377-
activeTxn = nullptr;
378-
return (ret == 0);
379-
}
380-
381-
bool TxnAbort()
382-
{
383-
if (!pdb || !activeTxn)
384-
return false;
385-
int ret = activeTxn->abort();
386-
activeTxn = nullptr;
387-
return (ret == 0);
388-
}
329+
Dbc* GetCursor();
330+
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue);
331+
bool TxnBegin();
332+
bool TxnCommit();
333+
bool TxnAbort();
389334

390335
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
391336
};

0 commit comments

Comments
 (0)