aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/chain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/chain.cpp')
-rw-r--r--src/interfaces/chain.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp
index 6e2224bc3e..1f39e650dc 100644
--- a/src/interfaces/chain.cpp
+++ b/src/interfaces/chain.cpp
@@ -60,6 +60,42 @@ class LockImpl : public Chain::Lock
assert(block != nullptr);
return block->GetMedianTimePast();
}
+ Optional<int> findFirstBlockWithTime(int64_t time, uint256* hash) override
+ {
+ CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time);
+ if (block) {
+ if (hash) *hash = block->GetBlockHash();
+ return block->nHeight;
+ }
+ return nullopt;
+ }
+ Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height) override
+ {
+ // TODO: Could update CChain::FindEarliestAtLeast() to take a height
+ // parameter and use it with std::lower_bound() to make this
+ // implementation more efficient and allow combining
+ // findFirstBlockWithTime and findFirstBlockWithTimeAndHeight into one
+ // method.
+ for (CBlockIndex* block = ::chainActive[height]; block; block = ::chainActive.Next(block)) {
+ if (block->GetBlockTime() >= time) {
+ return block->nHeight;
+ }
+ }
+ return nullopt;
+ }
+ Optional<int> findPruned(int start_height, Optional<int> stop_height) override
+ {
+ if (::fPruneMode) {
+ CBlockIndex* block = stop_height ? ::chainActive[*stop_height] : ::chainActive.Tip();
+ while (block && block->nHeight >= start_height) {
+ if ((block->nStatus & BLOCK_HAVE_DATA) == 0) {
+ return block->nHeight;
+ }
+ block = block->pprev;
+ }
+ }
+ return nullopt;
+ }
Optional<int> findFork(const uint256& hash, Optional<int>* height) override
{
const CBlockIndex* block = LookupBlockIndex(hash);
@@ -116,6 +152,11 @@ public:
}
return true;
}
+ double guessVerificationProgress(const uint256& block_hash) override
+ {
+ LOCK(cs_main);
+ return GuessVerificationProgress(Params().TxData(), LookupBlockIndex(block_hash));
+ }
};
} // namespace