aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-06-15 20:34:25 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-06-15 20:35:39 -0400
commit8f033642a8c6874184e297b97b951b9bd12ffd75 (patch)
tree0165173767e58873341b247e11b2f8d23f331275 /src/wallet
parent25a655794a0c495332dadedd88b87d694c1077c2 (diff)
downloadbitcoin-8f033642a8c6874184e297b97b951b9bd12ffd75.tar.xz
walletdb: moveonly: Move BerkeleyBatch Cursor and Txn funcs to cpp
Put the implementation in the cpp, not the h file.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/db.cpp61
-rw-r--r--src/wallet/db.h65
2 files changed, 66 insertions, 60 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 99ad963f9a..5bf3f6dff6 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -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()
{
return DbEnv::version(nullptr, nullptr, nullptr);
diff --git a/src/wallet/db.h b/src/wallet/db.h
index 3c7c4c1255..d8a3087306 100644
--- a/src/wallet/db.h
+++ b/src/wallet/db.h
@@ -326,66 +326,11 @@ public:
return (ret == 0);
}
- Dbc* GetCursor()
- {
- if (!pdb)
- return nullptr;
- Dbc* pcursor = nullptr;
- 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);
- }
+ Dbc* GetCursor();
+ int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue);
+ bool TxnBegin();
+ bool TxnCommit();
+ bool TxnAbort();
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
};