mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
refactor: combine Chain::findFirstBlockWithTime/findFirstBlockWithTimeAndHeight
As suggested in #14711, pass height to CChain::FindEarliestAtLeast to simplify Chain interface by combining findFirstBlockWithTime and findFirstBlockWithTimeAndHeight into one Extend findearliestatleast_edge_test in consequence
This commit is contained in:
@@ -59,10 +59,11 @@ const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
|
||||
return pindex;
|
||||
}
|
||||
|
||||
CBlockIndex* CChain::FindEarliestAtLeast(int64_t nTime) const
|
||||
CBlockIndex* CChain::FindEarliestAtLeast(int64_t nTime, int height) const
|
||||
{
|
||||
std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(vChain.begin(), vChain.end(), nTime,
|
||||
[](CBlockIndex* pBlock, const int64_t& time) -> bool { return pBlock->GetBlockTimeMax() < time; });
|
||||
std::pair<int64_t, int> blockparams = std::make_pair(nTime, height);
|
||||
std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(vChain.begin(), vChain.end(), blockparams,
|
||||
[](CBlockIndex* pBlock, const std::pair<int64_t, int>& blockparams) -> bool { return pBlock->GetBlockTimeMax() < blockparams.first || pBlock->nHeight < blockparams.second; });
|
||||
return (lower == vChain.end() ? nullptr : *lower);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user