aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
authorJim Posen <jimpo@coinbase.com>2017-12-11 16:58:25 -0800
committerJim Posen <jimpo@coinbase.com>2018-04-25 11:25:05 -0700
commit0cb8303241db75b8a59234e4edcdc163d869443c (patch)
tree0d2f3434fabca52662c6be10c414fd21012da2ac /src/txdb.cpp
parent25ad2f75f5d105d30d2ca716a66138a6b32a8c68 (diff)
[db] Create separate database for txindex.
The new TxIndexDB class will be used by a future commit in this change set.
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 45ce94ae42..b4fbfd9522 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -424,3 +424,35 @@ bool CCoinsViewDB::Upgrade() {
LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE");
return !ShutdownRequested();
}
+
+TxIndexDB::TxIndexDB(size_t n_cache_size, bool f_memory, bool f_wipe) :
+ CDBWrapper(GetDataDir() / "indexes" / "txindex", n_cache_size, f_memory, f_wipe)
+{}
+
+bool TxIndexDB::ReadTxPos(const uint256 &txid, CDiskTxPos& pos) const
+{
+ return Read(std::make_pair(DB_TXINDEX, txid), pos);
+}
+
+bool TxIndexDB::WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos)
+{
+ CDBBatch batch(*this);
+ for (const auto& tuple : v_pos) {
+ batch.Write(std::make_pair(DB_TXINDEX, tuple.first), tuple.second);
+ }
+ return WriteBatch(batch);
+}
+
+bool TxIndexDB::ReadBestBlock(CBlockLocator& locator) const
+{
+ bool success = Read(DB_BEST_BLOCK, locator);
+ if (!success) {
+ locator.SetNull();
+ }
+ return success;
+}
+
+bool TxIndexDB::WriteBestBlock(const CBlockLocator& locator)
+{
+ return Write(DB_BEST_BLOCK, locator);
+}