diff --git a/src/pow.cpp b/src/pow.cpp index 228696b..2625f0d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -196,6 +196,23 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return bnNew.GetCompact(); } +const CBlockIndex* GetLastBlockIndexForAlgoFast(const CBlockIndex* pindex, int algo) +{ + if (algo < 0 || algo >= NUM_ALGOS_IMPL) { + return nullptr; + } + + while (pindex) { + if (pindex->GetAlgo() == algo) { + return pindex; + } + + pindex = pindex->lastAlgoBlocks[algo]; + } + + return nullptr; +} + bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params) { bool fNegative; diff --git a/src/pow.h b/src/pow.h index ffa5bbd..fc92de0 100644 --- a/src/pow.h +++ b/src/pow.h @@ -20,5 +20,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&); +const CBlockIndex* GetLastBlockIndexForAlgoFast(const CBlockIndex* pindex, int algo); #endif // DIGIBYTE_POW_H