Bitcoin ABC  0.22.15
P2P Digital Currency
Classes | Public Member Functions | List of all members
interfaces::Chain Class Referenceabstract

Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to access to the chain state, receive notifications, estimate fees, and submit transactions. More...

#include <chain.h>

Classes

class  Notifications
 Chain notifications. More...
 

Public Member Functions

virtual ~Chain ()
 
virtual std::optional< int > getHeight ()=0
 Get current chain height, not including genesis block (returns 0 if chain only contains genesis block, std::nullopt if chain does not contain any blocks) More...
 
virtual std::optional< int > getBlockHeight (const BlockHash &hash)=0
 Get block height above genesis block. More...
 
virtual BlockHash getBlockHash (int height)=0
 Get block hash. Height must be valid or this function will abort. More...
 
virtual bool haveBlockOnDisk (int height)=0
 Check that the block is available on disk (i.e. More...
 
virtual std::optional< int > findFirstBlockWithTimeAndHeight (int64_t time, int height, BlockHash *hash)=0
 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 given height, or std::nullopt if there is no block with a high enough timestamp and height. More...
 
virtual CBlockLocator getTipLocator ()=0
 Get locator for the current chain tip. More...
 
virtual std::optional< int > findLocatorFork (const CBlockLocator &locator)=0
 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, or one of its ancestors. More...
 
virtual bool contextualCheckTransactionForCurrentBlock (const CTransaction &tx, TxValidationState &state)=0
 Check if transaction will be final given chain height current time. More...
 
virtual bool findBlock (const BlockHash &hash, const FoundBlock &block={})=0
 Return whether node has the block and optionally return block metadata or contents. More...
 
virtual bool findFirstBlockWithTimeAndHeight (int64_t min_time, int min_height, const FoundBlock &block={})=0
 Find first block in the chain with timestamp >= the given time and height >= than the given height, return false if there is no block with a high enough timestamp and height. More...
 
virtual bool findNextBlock (const BlockHash &block_hash, int block_height, const FoundBlock &next={}, bool *reorg=nullptr)=0
 Find next block if block is part of current chain. More...
 
virtual bool findAncestorByHeight (const BlockHash &block_hash, int ancestor_height, const FoundBlock &ancestor_out={})=0
 Find ancestor of block at specified height and optionally return ancestor information. More...
 
virtual bool findAncestorByHash (const BlockHash &block_hash, const BlockHash &ancestor_hash, const FoundBlock &ancestor_out={})=0
 Return whether block descends from a specified ancestor, and optionally return ancestor information. More...
 
virtual bool findCommonAncestor (const BlockHash &block_hash1, const BlockHash &block_hash2, const FoundBlock &ancestor_out={}, const FoundBlock &block1_out={}, const FoundBlock &block2_out={})=0
 Find most recent common ancestor between two blocks and optionally return block information. More...
 
virtual void findCoins (std::map< COutPoint, Coin > &coins)=0
 Look up unspent output information. More...
 
virtual double guessVerificationProgress (const BlockHash &block_hash)=0
 Estimate fraction of total transactions verified if blocks up to the specified block hash are verified. More...
 
virtual bool hasBlocks (const BlockHash &block_hash, int min_height=0, std::optional< int > max_height={})=0
 Return true if data is available for all blocks in the specified range of blocks. More...
 
virtual bool hasDescendantsInMempool (const TxId &txid)=0
 Check if transaction has descendants in mempool. More...
 
virtual bool broadcastTransaction (const Config &config, const CTransactionRef &tx, const Amount &max_tx_fee, bool relay, std::string &err_string)=0
 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 set to true. More...
 
virtual void getTransactionAncestry (const TxId &txid, size_t &ancestors, size_t &descendants)=0
 Calculate mempool ancestor and descendant counts for the given transaction. More...
 
virtual void getPackageLimits (size_t &limit_ancestor_count, size_t &limit_descendant_count)=0
 Get the node's package limits. More...
 
virtual bool checkChainLimits (const CTransactionRef &tx)=0
 Check if transaction will pass the mempool's chain limits. More...
 
virtual CFeeRate estimateFee () const =0
 Estimate fee. More...
 
virtual CFeeRate relayMinFee ()=0
 Relay current minimum fee (from -minrelaytxfee settings). More...
 
virtual CFeeRate relayDustFee ()=0
 Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend. More...
 
virtual bool havePruned ()=0
 Check if any block has been pruned. More...
 
virtual bool isReadyToBroadcast ()=0
 Check if the node is ready to broadcast transactions. More...
 
virtual bool isInitialBlockDownload ()=0
 Check if in IBD. More...
 
virtual bool shutdownRequested ()=0
 Check if shutdown requested. More...
 
virtual int64_t getAdjustedTime ()=0
 Get adjusted time. More...
 
virtual void initMessage (const std::string &message)=0
 Send init message. More...
 
virtual void initWarning (const bilingual_str &message)=0
 Send init warning. More...
 
virtual void initError (const bilingual_str &message)=0
 Send init error. More...
 
virtual void showProgress (const std::string &title, int progress, bool resume_possible)=0
 Send progress indicator. More...
 
virtual std::unique_ptr< HandlerhandleNotifications (std::shared_ptr< Notifications > notifications)=0
 Register handler for notifications. More...
 
virtual void waitForNotificationsIfTipChanged (const BlockHash &old_tip)=0
 Wait for pending notifications to be processed unless block hash points to the current chain tip. More...
 
virtual std::unique_ptr< HandlerhandleRpc (const CRPCCommand &command)=0
 Register handler for RPC. More...
 
virtual bool rpcEnableDeprecated (const std::string &method)=0
 Check if deprecated RPC is enabled. More...
 
virtual void rpcRunLater (const std::string &name, std::function< void()> fn, int64_t seconds)=0
 Run function after given number of seconds. More...
 
virtual int rpcSerializationFlags ()=0
 Current RPC serialization flags. More...
 
virtual void requestMempoolTransactions (Notifications &notifications)=0
 Synchronously send transactionAddedToMempool notifications about all current mempool transactions to the specified handler and return after the last one is sent. More...
 
virtual const CChainParamsparams () const =0
 This Chain's parameters. More...
 

Detailed Description

Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to access to the chain state, receive notifications, estimate fees, and submit transactions.

TODO: Current chain methods are too low level, exposing too much of the internal workings of the bitcoin node, and not being very convenient to use. Chain methods should be cleaned up and simplified over time. Examples:

Definition at line 105 of file chain.h.

Constructor & Destructor Documentation

◆ ~Chain()

virtual interfaces::Chain::~Chain ( )
inlinevirtual

Definition at line 107 of file chain.h.

Member Function Documentation

◆ broadcastTransaction()

virtual bool interfaces::Chain::broadcastTransaction ( const Config config,
const CTransactionRef tx,
const Amount max_tx_fee,
bool  relay,
std::string &  err_string 
)
pure virtual

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 set to true.

Return false if the transaction could not be added due to the fee or for another reason.

◆ checkChainLimits()

virtual bool interfaces::Chain::checkChainLimits ( const CTransactionRef tx)
pure virtual

Check if transaction will pass the mempool's chain limits.

◆ contextualCheckTransactionForCurrentBlock()

virtual bool interfaces::Chain::contextualCheckTransactionForCurrentBlock ( const CTransaction tx,
TxValidationState state 
)
pure virtual

Check if transaction will be final given chain height current time.

◆ estimateFee()

virtual CFeeRate interfaces::Chain::estimateFee ( ) const
pure virtual

Estimate fee.

Here is the caller graph for this function:

◆ findAncestorByHash()

virtual bool interfaces::Chain::findAncestorByHash ( const BlockHash block_hash,
const BlockHash ancestor_hash,
const FoundBlock ancestor_out = {} 
)
pure virtual

Return whether block descends from a specified ancestor, and optionally return ancestor information.

Here is the caller graph for this function:

◆ findAncestorByHeight()

virtual bool interfaces::Chain::findAncestorByHeight ( const BlockHash block_hash,
int  ancestor_height,
const FoundBlock ancestor_out = {} 
)
pure virtual

Find ancestor of block at specified height and optionally return ancestor information.

Here is the caller graph for this function:

◆ findBlock()

virtual bool interfaces::Chain::findBlock ( const BlockHash hash,
const FoundBlock block = {} 
)
pure virtual

Return whether node has the block and optionally return block metadata or contents.

Here is the caller graph for this function:

◆ findCoins()

virtual void interfaces::Chain::findCoins ( std::map< COutPoint, Coin > &  coins)
pure virtual

Look up unspent output information.

Returns coins in the mempool and in the current chain UTXO set. Iterates through all the keys in the map and populates the values.

Here is the caller graph for this function:

◆ findCommonAncestor()

virtual bool interfaces::Chain::findCommonAncestor ( const BlockHash block_hash1,
const BlockHash block_hash2,
const FoundBlock ancestor_out = {},
const FoundBlock block1_out = {},
const FoundBlock block2_out = {} 
)
pure virtual

Find most recent common ancestor between two blocks and optionally return block information.

Here is the caller graph for this function:

◆ findFirstBlockWithTimeAndHeight() [1/2]

virtual std::optional<int> interfaces::Chain::findFirstBlockWithTimeAndHeight ( int64_t  time,
int  height,
BlockHash hash 
)
pure virtual

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 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 parameter (to avoid the cost of a second lookup in case this information is needed.)

Here is the caller graph for this function:

◆ findFirstBlockWithTimeAndHeight() [2/2]

virtual bool interfaces::Chain::findFirstBlockWithTimeAndHeight ( int64_t  min_time,
int  min_height,
const FoundBlock block = {} 
)
pure virtual

Find first block in the chain with timestamp >= the given time and height >= than the given height, return false if there is no block with a high enough timestamp and height.

Optionally return block information.

◆ findLocatorFork()

virtual std::optional<int> interfaces::Chain::findLocatorFork ( const CBlockLocator locator)
pure virtual

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, or one of its ancestors.

Here is the caller graph for this function:

◆ findNextBlock()

virtual bool interfaces::Chain::findNextBlock ( const BlockHash block_hash,
int  block_height,
const FoundBlock next = {},
bool *  reorg = nullptr 
)
pure virtual

Find next block if block is part of current chain.

Also flag if there was a reorg and the specified block hash is no longer in the current chain, and optionally return block information.

◆ getAdjustedTime()

virtual int64_t interfaces::Chain::getAdjustedTime ( )
pure virtual

Get adjusted time.

◆ getBlockHash()

virtual BlockHash interfaces::Chain::getBlockHash ( int  height)
pure virtual

Get block hash. Height must be valid or this function will abort.

Here is the caller graph for this function:

◆ getBlockHeight()

virtual std::optional<int> interfaces::Chain::getBlockHeight ( const BlockHash hash)
pure virtual

Get block height above genesis block.

Returns 0 for genesis block, 1 for following block, and so on. Returns std::nullopt for a block not included in the current chain.

◆ getHeight()

virtual std::optional<int> interfaces::Chain::getHeight ( )
pure virtual

Get current chain height, not including genesis block (returns 0 if chain only contains genesis block, std::nullopt if chain does not contain any blocks)

Here is the caller graph for this function:

◆ getPackageLimits()

virtual void interfaces::Chain::getPackageLimits ( size_t &  limit_ancestor_count,
size_t &  limit_descendant_count 
)
pure virtual

Get the node's package limits.

Currently only returns the ancestor and descendant count limits, but could be enhanced to return more policy settings.

◆ getTipLocator()

virtual CBlockLocator interfaces::Chain::getTipLocator ( )
pure virtual

Get locator for the current chain tip.

Here is the caller graph for this function:

◆ getTransactionAncestry()

virtual void interfaces::Chain::getTransactionAncestry ( const TxId txid,
size_t &  ancestors,
size_t &  descendants 
)
pure virtual

Calculate mempool ancestor and descendant counts for the given transaction.

◆ guessVerificationProgress()

virtual double interfaces::Chain::guessVerificationProgress ( const BlockHash block_hash)
pure virtual

Estimate fraction of total transactions verified if blocks up to the specified block hash are verified.

◆ handleNotifications()

virtual std::unique_ptr<Handler> interfaces::Chain::handleNotifications ( std::shared_ptr< Notifications notifications)
pure virtual

Register handler for notifications.

Here is the caller graph for this function:

◆ handleRpc()

virtual std::unique_ptr<Handler> interfaces::Chain::handleRpc ( const CRPCCommand command)
pure virtual

Register handler for RPC.

Command is not copied, so reference needs to remain valid until Handler is disconnected.

◆ hasBlocks()

virtual bool interfaces::Chain::hasBlocks ( const BlockHash block_hash,
int  min_height = 0,
std::optional< int >  max_height = {} 
)
pure virtual

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 the height range from min_height to max_height, inclusive.

Here is the caller graph for this function:

◆ hasDescendantsInMempool()

virtual bool interfaces::Chain::hasDescendantsInMempool ( const TxId txid)
pure virtual

Check if transaction has descendants in mempool.

◆ haveBlockOnDisk()

virtual bool interfaces::Chain::haveBlockOnDisk ( int  height)
pure virtual

Check that the block is available on disk (i.e.

has not been pruned), and contains transactions.

Here is the caller graph for this function:

◆ havePruned()

virtual bool interfaces::Chain::havePruned ( )
pure virtual

Check if any block has been pruned.

Here is the caller graph for this function:

◆ initError()

virtual void interfaces::Chain::initError ( const bilingual_str message)
pure virtual

Send init error.

Here is the caller graph for this function:

◆ initMessage()

virtual void interfaces::Chain::initMessage ( const std::string &  message)
pure virtual

Send init message.

Here is the caller graph for this function:

◆ initWarning()

virtual void interfaces::Chain::initWarning ( const bilingual_str message)
pure virtual

Send init warning.

Here is the caller graph for this function:

◆ isInitialBlockDownload()

virtual bool interfaces::Chain::isInitialBlockDownload ( )
pure virtual

Check if in IBD.

Here is the caller graph for this function:

◆ isReadyToBroadcast()

virtual bool interfaces::Chain::isReadyToBroadcast ( )
pure virtual

Check if the node is ready to broadcast transactions.

◆ params()

virtual const CChainParams& interfaces::Chain::params ( ) const
pure virtual

This Chain's parameters.

◆ relayDustFee()

virtual CFeeRate interfaces::Chain::relayDustFee ( )
pure virtual

Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend.

◆ relayMinFee()

virtual CFeeRate interfaces::Chain::relayMinFee ( )
pure virtual

Relay current minimum fee (from -minrelaytxfee settings).

Here is the caller graph for this function:

◆ requestMempoolTransactions()

virtual void interfaces::Chain::requestMempoolTransactions ( Notifications notifications)
pure virtual

Synchronously send transactionAddedToMempool notifications about all current mempool transactions to the specified handler and return after the last one is sent.

These notifications aren't coordinated with async notifications sent by handleNotifications, so out of date async notifications from handleNotifications can arrive during and after synchronous notifications from requestMempoolTransactions. Clients need to be prepared to handle this by ignoring notifications about unknown removed transactions and already added new transactions.

◆ rpcEnableDeprecated()

virtual bool interfaces::Chain::rpcEnableDeprecated ( const std::string &  method)
pure virtual

Check if deprecated RPC is enabled.

Here is the caller graph for this function:

◆ rpcRunLater()

virtual void interfaces::Chain::rpcRunLater ( const std::string &  name,
std::function< void()>  fn,
int64_t  seconds 
)
pure virtual

Run function after given number of seconds.

Cancel any previous calls with same name.

Here is the caller graph for this function:

◆ rpcSerializationFlags()

virtual int interfaces::Chain::rpcSerializationFlags ( )
pure virtual

Current RPC serialization flags.

Here is the caller graph for this function:

◆ showProgress()

virtual void interfaces::Chain::showProgress ( const std::string &  title,
int  progress,
bool  resume_possible 
)
pure virtual

Send progress indicator.

Here is the caller graph for this function:

◆ shutdownRequested()

virtual bool interfaces::Chain::shutdownRequested ( )
pure virtual

Check if shutdown requested.

◆ waitForNotificationsIfTipChanged()

virtual void interfaces::Chain::waitForNotificationsIfTipChanged ( const BlockHash old_tip)
pure virtual

Wait for pending notifications to be processed unless block hash points to the current chain tip.


The documentation for this class was generated from the following file: