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 current chain height, not including genesis block (returns 0 if | |||||
//! chain only contains genesis block, nullopt if chain does not contain | |||||
//! any blocks). | |||||
virtual Optional<int> getHeight() = 0; | |||||
//! Get block height above genesis block. Returns 0 for genesis block, | //! Get block height above genesis block. Returns 0 for genesis block, | ||||
//! 1 for following block, and so on. Returns nullopt for a block not | //! 1 for following block, and so on. Returns nullopt for a block not | ||||
//! included in the current chain. | //! included in the current chain. | ||||
virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0; | 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; | ||||
Show All 32 Lines | public: | ||||
const Consensus::Params ¶ms, const CTransaction &tx, | const Consensus::Params ¶ms, const CTransaction &tx, | ||||
TxValidationState &state) = 0; | TxValidationState &state) = 0; | ||||
}; | }; | ||||
//! Return Lock interface. Chain is locked when this is called, and | //! Return Lock interface. Chain is locked when this is called, and | ||||
//! 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 | |||||
//! chain only contains genesis block, nullopt if chain does not contain | |||||
//! any blocks) | |||||
virtual Optional<int> getHeight() = 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 |