diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2017-07-27 10:08:31 -0400 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2019-01-15 12:42:00 -0400 |
commit | 700c42b85d20e624bef4228eef062c93084efab5 (patch) | |
tree | 60f0213d9b6671995ae6e7d2015d57ffdda89f4b /src/interfaces/chain.h | |
parent | eb2aecfb80662a91c649ea1455d9812ced05c323 (diff) | |
download | bitcoin-700c42b85d20e624bef4228eef062c93084efab5.tar.xz |
Add height, depth, and hash methods to the Chain interface
And use them to remove uses of chainActive and mapBlockIndex in wallet code
This commit does not change behavior.
Co-authored-by: Ben Woosley <ben.woosley@gmail.com>
Diffstat (limited to 'src/interfaces/chain.h')
-rw-r--r-- | src/interfaces/chain.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index fe5658de4b..928b8af1f4 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -5,11 +5,14 @@ #ifndef BITCOIN_INTERFACES_CHAIN_H #define BITCOIN_INTERFACES_CHAIN_H +#include <optional.h> + #include <memory> #include <string> #include <vector> class CScheduler; +class uint256; namespace interfaces { @@ -28,6 +31,23 @@ public: { public: 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, + //! 1 for following block, and so on. Returns nullopt for a block not + //! included in the current chain. + virtual Optional<int> getBlockHeight(const uint256& hash) = 0; + + //! Get block depth. Returns 1 for chain tip, 2 for preceding block, and + //! so on. Returns 0 for a block not included in the current chain. + virtual int getBlockDepth(const uint256& hash) = 0; + + //! Get block hash. Height must be valid or this function will abort. + virtual uint256 getBlockHash(int height) = 0; }; //! Return Lock interface. Chain is locked when this is called, and |