@@ -24,6 +24,7 @@ static const char DB_TXINDEX = 't';
2424static const char DB_ADDRESSINDEX = ' a' ;
2525static const char DB_ADDRESSUNSPENTINDEX = ' u' ;
2626static const char DB_TIMESTAMPINDEX = ' s' ;
27+ static const char DB_BLOCKHASHINDEX = ' z' ;
2728static const char DB_SPENTINDEX = ' p' ;
2829static const char DB_BLOCK_INDEX = ' b' ;
2930
@@ -275,7 +276,7 @@ bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex)
275276 return WriteBatch (batch);
276277}
277278
278- bool CBlockTreeDB::ReadTimestampIndex (const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes) {
279+ bool CBlockTreeDB::ReadTimestampIndex (const unsigned int &high, const unsigned int &low, const bool fActiveOnly , std::vector<std::pair< uint256, unsigned int > > &hashes) {
279280
280281 boost::scoped_ptr<CDBIterator> pcursor (NewIterator ());
281282
@@ -284,8 +285,15 @@ bool CBlockTreeDB::ReadTimestampIndex(const unsigned int &high, const unsigned i
284285 while (pcursor->Valid ()) {
285286 boost::this_thread::interruption_point ();
286287 std::pair<char , CTimestampIndexKey> key;
287- if (pcursor->GetKey (key) && key.first == DB_TIMESTAMPINDEX && key.second .timestamp <= high) {
288- hashes.push_back (key.second .blockHash );
288+ if (pcursor->GetKey (key) && key.first == DB_TIMESTAMPINDEX && key.second .timestamp < high) {
289+ if (fActiveOnly ) {
290+ if (blockOnchainActive (key.second .blockHash )) {
291+ hashes.push_back (std::make_pair (key.second .blockHash , key.second .timestamp ));
292+ }
293+ } else {
294+ hashes.push_back (std::make_pair (key.second .blockHash , key.second .timestamp ));
295+ }
296+
289297 pcursor->Next ();
290298 } else {
291299 break ;
@@ -295,6 +303,22 @@ bool CBlockTreeDB::ReadTimestampIndex(const unsigned int &high, const unsigned i
295303 return true ;
296304}
297305
306+ bool CBlockTreeDB::WriteTimestampBlockIndex (const CTimestampBlockIndexKey &blockhashIndex, const CTimestampBlockIndexValue &logicalts) {
307+ CDBBatch batch (&GetObfuscateKey ());
308+ batch.Write (make_pair (DB_BLOCKHASHINDEX, blockhashIndex), logicalts);
309+ return WriteBatch (batch);
310+ }
311+
312+ bool CBlockTreeDB::ReadTimestampBlockIndex (const uint256 &hash, unsigned int <imestamp) {
313+
314+ CTimestampBlockIndexValue (lts);
315+ if (!Read (std::make_pair (DB_BLOCKHASHINDEX, hash), lts))
316+ return false ;
317+
318+ ltimestamp = lts.ltimestamp ;
319+ return true ;
320+ }
321+
298322bool CBlockTreeDB::WriteFlag (const std::string &name, bool fValue ) {
299323 return Write (std::make_pair (DB_FLAG, name), fValue ? ' 1' : ' 0' );
300324}
@@ -307,6 +331,16 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
307331 return true ;
308332}
309333
334+ bool CBlockTreeDB::blockOnchainActive (const uint256 &hash) {
335+ CBlockIndex* pblockindex = mapBlockIndex[hash];
336+
337+ if (!chainActive.Contains (pblockindex)) {
338+ return false ;
339+ }
340+
341+ return true ;
342+ }
343+
310344bool CBlockTreeDB::LoadBlockIndexGuts ()
311345{
312346 boost::scoped_ptr<CDBIterator> pcursor (NewIterator ());
0 commit comments