Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.h
// Copyright (c) 2018-2019 The Bitcoin Core developers | // Copyright (c) 2018-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_INTERFACES_CHAIN_H | #ifndef BITCOIN_INTERFACES_CHAIN_H | ||||
#define BITCOIN_INTERFACES_CHAIN_H | #define BITCOIN_INTERFACES_CHAIN_H | ||||
#include <optional.h> | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <primitives/txid.h> | #include <primitives/txid.h> | ||||
#include <cstddef> | #include <cstddef> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | |||||
#include <memory> | #include <memory> | ||||
#include <optional> | |||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
class CBlock; | class CBlock; | ||||
class CChainParams; | class CChainParams; | ||||
class Coin; | class Coin; | ||||
class Config; | class Config; | ||||
class CRPCCommand; | class CRPCCommand; | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
//! * The `guessVerificationProgress`, `getBlockHeight`, `getBlockHash`, etc | //! * The `guessVerificationProgress`, `getBlockHeight`, `getBlockHash`, etc | ||||
//! methods can go away if rescan logic is moved on the node side, and wallet | //! methods can go away if rescan logic is moved on the node side, and wallet | ||||
//! only register rescan request. | //! only register rescan request. | ||||
class Chain { | class Chain { | ||||
public: | public: | ||||
virtual ~Chain() {} | virtual ~Chain() {} | ||||
//! 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, std::nullopt if chain does not | ||||
//! any blocks) | //! contain any blocks) | ||||
virtual Optional<int> getHeight() = 0; | virtual std::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 std::nullopt for a block not | ||||
//! included in the current chain. | //! included in the current chain. | ||||
virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0; | virtual std::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 | ||||
//! or greater than the given time and height equal or greater than the | //! or greater than the given time and height equal or greater than the | ||||
//! given height, or nullopt if there is no block with a high enough | //! given height, or std::nullopt if there is no block with a high enough | ||||
//! timestamp and height. Also return the block hash as an optional output | //! timestamp and height. Also return the block hash as an optional output | ||||
//! parameter (to avoid the cost of a second lookup in case this information | //! parameter (to avoid the cost of a second lookup in case this information | ||||
//! is needed.) | //! is needed.) | ||||
virtual Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, | virtual std::optional<int> | ||||
int height, | findFirstBlockWithTimeAndHeight(int64_t time, int height, | ||||
BlockHash *hash) = 0; | BlockHash *hash) = 0; | ||||
//! Get locator for the current chain tip. | //! Get locator for the current chain tip. | ||||
virtual CBlockLocator getTipLocator() = 0; | virtual CBlockLocator getTipLocator() = 0; | ||||
//! Return height of the highest block on chain in common with the locator, | //! Return height of the highest block on chain in common with the locator, | ||||
//! which will either be the original block used to create the locator, | //! which will either be the original block used to create the locator, | ||||
//! or one of its ancestors. | //! or one of its ancestors. | ||||
virtual Optional<int> findLocatorFork(const CBlockLocator &locator) = 0; | virtual std::optional<int> | ||||
findLocatorFork(const CBlockLocator &locator) = 0; | |||||
//! Check if transaction will be final given chain height current time. | //! Check if transaction will be final given chain height current time. | ||||
virtual bool | virtual bool | ||||
contextualCheckTransactionForCurrentBlock(const CTransaction &tx, | contextualCheckTransactionForCurrentBlock(const CTransaction &tx, | ||||
TxValidationState &state) = 0; | TxValidationState &state) = 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. | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public: | ||||
//! Estimate fraction of total transactions verified if blocks up to | //! Estimate fraction of total transactions verified if blocks up to | ||||
//! the specified block hash are verified. | //! the specified block hash are verified. | ||||
virtual double guessVerificationProgress(const BlockHash &block_hash) = 0; | virtual double guessVerificationProgress(const BlockHash &block_hash) = 0; | ||||
//! Return true if data is available for all blocks in the specified range | //! Return true if data is available for all blocks in the specified range | ||||
//! of blocks. This checks all blocks that are ancestors of block_hash in | //! of blocks. This checks all blocks that are ancestors of block_hash in | ||||
//! the height range from min_height to max_height, inclusive. | //! the height range from min_height to max_height, inclusive. | ||||
virtual bool hasBlocks(const BlockHash &block_hash, int min_height = 0, | virtual bool hasBlocks(const BlockHash &block_hash, int min_height = 0, | ||||
Optional<int> max_height = {}) = 0; | std::optional<int> max_height = {}) = 0; | ||||
//! Check if transaction has descendants in mempool. | //! Check if transaction has descendants in mempool. | ||||
virtual bool hasDescendantsInMempool(const TxId &txid) = 0; | virtual bool hasDescendantsInMempool(const TxId &txid) = 0; | ||||
//! Transaction is added to memory pool, if the transaction fee is below the | //! Transaction is added to memory pool, if the transaction fee is below the | ||||
//! amount specified by max_tx_fee, and broadcast to all peers if relay is | //! amount specified by max_tx_fee, and broadcast to all peers if relay is | ||||
//! set to true. Return false if the transaction could not be added due to | //! set to true. Return false if the transaction could not be added due to | ||||
//! the fee or for another reason. | //! the fee or for another reason. | ||||
▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines |