Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | public: | ||||
CRPCCommand m_command; | CRPCCommand m_command; | ||||
const CRPCCommand *m_wrapped_command; | const CRPCCommand *m_wrapped_command; | ||||
}; | }; | ||||
class ChainImpl : public Chain { | class ChainImpl : public Chain { | ||||
public: | public: | ||||
explicit ChainImpl(NodeContext &node, const CChainParams ¶ms) | explicit ChainImpl(NodeContext &node, const CChainParams ¶ms) | ||||
: m_node(node), m_params(params) {} | : m_node(node), m_params(params) {} | ||||
Optional<int> getHeight() override { | std::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 std::nullopt; | ||||
} | } | ||||
Optional<int> getBlockHeight(const BlockHash &hash) override { | std::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 std::nullopt; | ||||
} | } | ||||
BlockHash getBlockHash(int height) override { | BlockHash getBlockHash(int height) override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
assert(block); | assert(block); | ||||
return block->GetBlockHash(); | return block->GetBlockHash(); | ||||
} | } | ||||
bool haveBlockOnDisk(int height) override { | bool haveBlockOnDisk(int height) override { | ||||
LOCK(cs_main); | 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> | std::optional<int> | ||||
findFirstBlockWithTimeAndHeight(int64_t time, int height, | findFirstBlockWithTimeAndHeight(int64_t time, int height, | ||||
BlockHash *hash) override { | BlockHash *hash) override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *block = | CBlockIndex *block = | ||||
::ChainActive().FindEarliestAtLeast(time, height); | ::ChainActive().FindEarliestAtLeast(time, height); | ||||
if (block) { | if (block) { | ||||
if (hash) { | if (hash) { | ||||
*hash = block->GetBlockHash(); | *hash = block->GetBlockHash(); | ||||
} | } | ||||
return block->nHeight; | return block->nHeight; | ||||
} | } | ||||
return nullopt; | return std::nullopt; | ||||
} | } | ||||
CBlockLocator getTipLocator() override { | CBlockLocator getTipLocator() override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ::ChainActive().GetLocator(); | return ::ChainActive().GetLocator(); | ||||
} | } | ||||
bool contextualCheckTransactionForCurrentBlock( | bool contextualCheckTransactionForCurrentBlock( | ||||
const CTransaction &tx, TxValidationState &state) override { | const CTransaction &tx, TxValidationState &state) override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ContextualCheckTransactionForCurrentBlock( | return ContextualCheckTransactionForCurrentBlock( | ||||
m_params.GetConsensus(), tx, state); | m_params.GetConsensus(), tx, state); | ||||
} | } | ||||
Optional<int> findLocatorFork(const CBlockLocator &locator) override { | std::optional<int> | ||||
findLocatorFork(const CBlockLocator &locator) override { | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (CBlockIndex *fork = | if (CBlockIndex *fork = | ||||
FindForkInGlobalIndex(::ChainActive(), locator)) { | FindForkInGlobalIndex(::ChainActive(), locator)) { | ||||
return fork->nHeight; | return fork->nHeight; | ||||
} | } | ||||
return nullopt; | return std::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 { | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public: | ||||
return FindCoins(m_node, coins); | return FindCoins(m_node, coins); | ||||
} | } | ||||
double guessVerificationProgress(const BlockHash &block_hash) override { | double guessVerificationProgress(const BlockHash &block_hash) override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GuessVerificationProgress(Params().TxData(), | return GuessVerificationProgress(Params().TxData(), | ||||
LookupBlockIndex(block_hash)); | LookupBlockIndex(block_hash)); | ||||
} | } | ||||
bool hasBlocks(const BlockHash &block_hash, int min_height, | bool hasBlocks(const BlockHash &block_hash, int min_height, | ||||
Optional<int> max_height) override { | std::optional<int> max_height) override { | ||||
// hasBlocks returns true if all ancestors of block_hash in | // hasBlocks returns true if all ancestors of block_hash in | ||||
// specified range have block data (are not pruned), false if any | // specified range have block data (are not pruned), false if any | ||||
// ancestors in specified range are missing data. | // ancestors in specified range are missing data. | ||||
// | // | ||||
// For simplicity and robustness, min_height and max_height are only | // For simplicity and robustness, min_height and max_height are only | ||||
// used to limit the range, and passing min_height that's too low or | // used to limit the range, and passing min_height that's too low or | ||||
// max_height that's too high will not crash or change the result. | // max_height that's too high will not crash or change the result. | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |