aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-01-11 01:47:57 +0100
committerPieter Wuille <pieterw@google.com>2013-01-18 14:39:11 +0100
commit2d1fa42e85c9164688aa69b3f54f015fbefc06aa (patch)
treed24823340b02d7e00af350b4592325414d5940f4 /src/txdb.cpp
parent2c7847349d5d4b1f3e8480c5137c2e8f3e2a5f5c (diff)
downloadbitcoin-2d1fa42e85c9164688aa69b3f54f015fbefc06aa.tar.xz
Add optional transaction index to databases
By specifying -txindex when initializing the database, a txid-to-diskpos index is maintained in the blktree database. This database is used to help answering getrawtransaction() RPC queries, when enabled. Changing the -txindex value requires a -reindex; the client will abort at startup if the database and the specified -txindex mismatch.
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 93c5f23d8b..78fa0279ba 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -145,6 +145,29 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
return true;
}
+bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
+ return Read(make_pair('t', txid), pos);
+}
+
+bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> >&vect) {
+ CLevelDBBatch batch;
+ for (std::vector<std::pair<uint256,CDiskTxPos> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
+ batch.Write(make_pair('t', it->first), it->second);
+ return WriteBatch(batch);
+}
+
+bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) {
+ return Write(std::make_pair('F', name), fValue ? '1' : '0');
+}
+
+bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
+ char ch;
+ if (!Read(std::make_pair('F', name), ch))
+ return false;
+ fValue = ch == '1';
+ return true;
+}
+
bool CBlockTreeDB::LoadBlockIndexGuts()
{
leveldb::Iterator *pcursor = NewIterator();