Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | bool FillBlock(const CBlockIndex *index, const FoundBlock &block, | ||||
Params().GetConsensus())) { | Params().GetConsensus())) { | ||||
block.m_data->SetNull(); | block.m_data->SetNull(); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
Optional<int> getBlockHeight(const BlockHash &hash) override { | |||||
LockAssertion lock(::cs_main); | |||||
CBlockIndex *block = LookupBlockIndex(hash); | |||||
if (block && ::ChainActive().Contains(block)) { | |||||
return block->nHeight; | |||||
} | |||||
return nullopt; | |||||
} | |||||
BlockHash getBlockHash(int height) override { | BlockHash getBlockHash(int height) override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
assert(block != nullptr); | assert(block != nullptr); | ||||
return block->GetBlockHash(); | return block->GetBlockHash(); | ||||
} | } | ||||
bool haveBlockOnDisk(int height) override { | bool haveBlockOnDisk(int height) override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | public: | ||||
Optional<int> getHeight() override { | Optional<int> getHeight() override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
int height = ::ChainActive().Height(); | int height = ::ChainActive().Height(); | ||||
if (height >= 0) { | if (height >= 0) { | ||||
return height; | return height; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
} | } | ||||
Optional<int> getBlockHeight(const BlockHash &hash) override { | |||||
LOCK(::cs_main); | |||||
CBlockIndex *block = LookupBlockIndex(hash); | |||||
if (block && ::ChainActive().Contains(block)) { | |||||
return block->nHeight; | |||||
} | |||||
return nullopt; | |||||
} | |||||
bool findBlock(const BlockHash &hash, | bool findBlock(const BlockHash &hash, | ||||
const FoundBlock &block) override { | const FoundBlock &block) override { | ||||
WAIT_LOCK(cs_main, lock); | WAIT_LOCK(cs_main, lock); | ||||
return FillBlock(LookupBlockIndex(hash), block, lock); | return FillBlock(LookupBlockIndex(hash), block, lock); | ||||
} | } | ||||
bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, | bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, | ||||
const FoundBlock &block) override { | const FoundBlock &block) override { | ||||
WAIT_LOCK(cs_main, lock); | WAIT_LOCK(cs_main, lock); | ||||
▲ Show 20 Lines • Show All 218 Lines • Show Last 20 Lines |