aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/chain.h
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2020-02-24 14:34:17 -0500
committerRussell Yanofsky <russ@yanofsky.org>2020-03-31 08:36:02 -0500
commitbf30cd4922ea62577d7bf63f5029e8be62665d45 (patch)
tree73c53b3583a3870d5620ff06cc724f2b944029e5 /src/interfaces/chain.h
parentd52ba21dfff99173abb927bc964ce7ceb711d789 (diff)
downloadbitcoin-bf30cd4922ea62577d7bf63f5029e8be62665d45.tar.xz
refactor: Add interfaces::FoundBlock class to selectively return block data
FoundBlock class allows interfaces::Chain::findBlock to return more block information without having lots of optional output parameters. FoundBlock class is also used by other chain methods in upcoming commits. There is mostly no change in behavior. Only exception is CWallet::RescanFromTime now throwing NonFatalCheckError instead of std::logic_error.
Diffstat (limited to 'src/interfaces/chain.h')
-rw-r--r--src/interfaces/chain.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index e1bc9bbbf3..3778ab9a8b 100644
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -30,6 +30,27 @@ namespace interfaces {
class Handler;
class Wallet;
+//! Helper for findBlock to selectively return pieces of block data.
+class FoundBlock
+{
+public:
+ FoundBlock& hash(uint256& 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; }
+
+ uint256* 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
//! the future) ability to access to the chain state, receive notifications,
//! estimate fees, and submit transactions.
@@ -127,14 +148,7 @@ public:
//! Return whether node has the block and optionally return block metadata
//! or contents.
- //!
- //! If a block pointer is provided to retrieve the block contents, and the
- //! 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 uint256& hash,
- CBlock* block = nullptr,
- int64_t* time = nullptr,
- int64_t* max_time = nullptr) = 0;
+ virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0;
//! 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