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> { | ||||
BlockHash getBlockHash(int height) override { | |||||
LockAssertion lock(::cs_main); | |||||
CBlockIndex *block = ::ChainActive()[height]; | |||||
assert(block != nullptr); | |||||
return block->GetBlockHash(); | |||||
} | |||||
bool haveBlockOnDisk(int height) override { | bool haveBlockOnDisk(int height) override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | ||||
} | } | ||||
Optional<int> | Optional<int> | ||||
findFirstBlockWithTimeAndHeight(int64_t time, int height, | findFirstBlockWithTimeAndHeight(int64_t time, int height, | ||||
BlockHash *hash) override { | BlockHash *hash) override { | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | public: | ||||
Optional<int> getBlockHeight(const BlockHash &hash) override { | Optional<int> getBlockHeight(const BlockHash &hash) override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
CBlockIndex *block = LookupBlockIndex(hash); | CBlockIndex *block = LookupBlockIndex(hash); | ||||
if (block && ::ChainActive().Contains(block)) { | if (block && ::ChainActive().Contains(block)) { | ||||
return block->nHeight; | return block->nHeight; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
} | } | ||||
BlockHash getBlockHash(int height) override { | |||||
LOCK(::cs_main); | |||||
CBlockIndex *block = ::ChainActive()[height]; | |||||
assert(block); | |||||
return block->GetBlockHash(); | |||||
} | |||||
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 |