Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.h
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | public: | ||||
//! assumes state won't change between calls. New code should avoid using | //! assumes state won't change between calls. New code should avoid using | ||||
//! the Lock interface and instead call higher-level Chain methods | //! the Lock interface and instead call higher-level Chain methods | ||||
//! that return more information so the chain doesn't need to stay locked | //! that return more information so the chain doesn't need to stay locked | ||||
//! between calls. | //! between calls. | ||||
class Lock { | class Lock { | ||||
public: | public: | ||||
virtual ~Lock() {} | virtual ~Lock() {} | ||||
//! Get block height above genesis block. Returns 0 for genesis block, | |||||
//! 1 for following block, and so on. Returns nullopt for a block not | |||||
//! included in the current chain. | |||||
virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0; | |||||
//! Get block hash. Height must be valid or this function will abort. | //! Get block hash. Height must be valid or this function will abort. | ||||
virtual BlockHash getBlockHash(int height) = 0; | virtual BlockHash getBlockHash(int height) = 0; | ||||
//! Check that the block is available on disk (i.e. has not been | //! Check that the block is available on disk (i.e. has not been | ||||
//! pruned), and contains transactions. | //! pruned), and contains transactions. | ||||
virtual bool haveBlockOnDisk(int height) = 0; | virtual bool haveBlockOnDisk(int height) = 0; | ||||
//! Return height of the first block in the chain with timestamp equal | //! Return height of the first block in the chain with timestamp equal | ||||
Show All 32 Lines | public: | ||||
//! unlocked when the returned interface is freed. | //! unlocked when the returned interface is freed. | ||||
virtual std::unique_ptr<Lock> lock(bool try_lock = false) = 0; | virtual std::unique_ptr<Lock> lock(bool try_lock = false) = 0; | ||||
//! Get current chain height, not including genesis block (returns 0 if | //! Get current chain height, not including genesis block (returns 0 if | ||||
//! chain only contains genesis block, nullopt if chain does not contain | //! chain only contains genesis block, nullopt if chain does not contain | ||||
//! any blocks) | //! any blocks) | ||||
virtual Optional<int> getHeight() = 0; | virtual Optional<int> getHeight() = 0; | ||||
//! Get block height above genesis block. Returns 0 for genesis block, | |||||
//! 1 for following block, and so on. Returns nullopt for a block not | |||||
//! included in the current chain. | |||||
virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0; | |||||
//! Return whether node has the block and optionally return block metadata | //! Return whether node has the block and optionally return block metadata | ||||
//! or contents. | //! or contents. | ||||
virtual bool findBlock(const BlockHash &hash, | virtual bool findBlock(const BlockHash &hash, | ||||
const FoundBlock &block = {}) = 0; | const FoundBlock &block = {}) = 0; | ||||
//! Find first block in the chain with timestamp >= the given time | //! Find first block in the chain with timestamp >= the given time | ||||
//! and height >= than the given height, return false if there is no block | //! and height >= than the given height, return false if there is no block | ||||
//! with a high enough timestamp and height. Optionally return block | //! with a high enough timestamp and height. Optionally return block | ||||
▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines |