diff options
| author | Russell Yanofsky <[email protected]> | 2019-01-07 23:38:53 -0800 |
|---|---|---|
| committer | Russell Yanofsky <[email protected]> | 2019-01-15 08:42:00 -0800 |
| commit | db21f0264855406c9b6ec4c084a15988c5c71b32 (patch) | |
| tree | 453f8541449673867736c10f9fd1edd8b53b5476 /src/interfaces/chain.cpp | |
| parent | Add findFork and findBlock to the Chain interface (diff) | |
| download | discoin-db21f0264855406c9b6ec4c084a15988c5c71b32.tar.xz discoin-db21f0264855406c9b6ec4c084a15988c5c71b32.zip | |
Convert CWallet::ScanForWalletTransactions and SyncTransaction to the new Chain apis
Only change in behavior is "Rescan started from block <height>" message
replaced by "Rescan started from block <hash>" message in
ScanForWalletTransactions.
Co-authored-by: Ben Woosley <[email protected]>
Diffstat (limited to 'src/interfaces/chain.cpp')
| -rw-r--r-- | src/interfaces/chain.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 6e2224bc3..1f39e650d 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 |