Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.h
Show All 30 Lines | |||||
struct Params; | struct Params; | ||||
} | } | ||||
namespace interfaces { | namespace interfaces { | ||||
class Handler; | class Handler; | ||||
class Wallet; | class Wallet; | ||||
//! Helper for findBlock to selectively return pieces of block data. | |||||
class FoundBlock { | |||||
public: | |||||
FoundBlock &hash(BlockHash &hash) { | |||||
m_hash = &hash; | |||||
return *this; | |||||
} | |||||
FoundBlock &height(int &height) { | |||||
m_height = &height; | |||||
return *this; | |||||
} | |||||
FoundBlock &time(int64_t &time) { | |||||
m_time = &time; | |||||
return *this; | |||||
} | |||||
FoundBlock &maxTime(int64_t &max_time) { | |||||
m_max_time = &max_time; | |||||
return *this; | |||||
} | |||||
FoundBlock &mtpTime(int64_t &mtp_time) { | |||||
m_mtp_time = &mtp_time; | |||||
return *this; | |||||
} | |||||
//! Read block data from disk. If the block exists but doesn't have data | |||||
//! (for example due to pruning), the CBlock variable will be set to null. | |||||
FoundBlock &data(CBlock &data) { | |||||
m_data = &data; | |||||
return *this; | |||||
} | |||||
BlockHash *m_hash = nullptr; | |||||
int *m_height = nullptr; | |||||
int64_t *m_time = nullptr; | |||||
int64_t *m_max_time = nullptr; | |||||
int64_t *m_mtp_time = nullptr; | |||||
CBlock *m_data = nullptr; | |||||
}; | |||||
//! Interface giving clients (wallet processes, maybe other analysis tools in | //! Interface giving clients (wallet processes, maybe other analysis tools in | ||||
//! the future) ability to access to the chain state, receive notifications, | //! the future) ability to access to the chain state, receive notifications, | ||||
//! estimate fees, and submit transactions. | //! estimate fees, and submit transactions. | ||||
//! | //! | ||||
//! TODO: Current chain methods are too low level, exposing too much of the | //! 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. | //! internal workings of the bitcoin node, and not being very convenient to use. | ||||
//! Chain methods should be cleaned up and simplified over time. Examples: | //! Chain methods should be cleaned up and simplified over time. Examples: | ||||
//! | //! | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | public: | ||||
}; | }; | ||||
//! 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; | ||||
//! 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, | ||||
//! If a block pointer is provided to retrieve the block contents, and the | const FoundBlock &block = {}) = 0; | ||||
//! block exists but doesn't have data (for example due to pruning), the | |||||
//! block will be empty and all fields set to null. | |||||
virtual bool findBlock(const BlockHash &hash, CBlock *block = nullptr, | |||||
int64_t *time = nullptr, | |||||
int64_t *max_time = nullptr) = 0; | |||||
//! Look up unspent output information. Returns coins in the mempool and in | //! 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 | //! the current chain UTXO set. Iterates through all the keys in the map and | ||||
//! populates the values. | //! populates the values. | ||||
virtual void findCoins(std::map<COutPoint, Coin> &coins) = 0; | virtual void findCoins(std::map<COutPoint, Coin> &coins) = 0; | ||||
//! 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. | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |