diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -6,7 +6,7 @@ #include #include #include -#include + #include #include #include @@ -34,16 +34,16 @@ auto handler = chain->handleNotifications({&wallet, [](CWallet *) {}}); - const Optional address_mine{ - add_mine ? Optional{getnewaddress(config, wallet)} - : nullopt}; + const std::optional address_mine{ + add_mine ? std::optional{getnewaddress(config, wallet)} + : std::nullopt}; if (add_watchonly) { importaddress(wallet, ADDRESS_WATCHONLY); } for (int i = 0; i < 100; ++i) { generatetoaddress(config, g_testing_setup->m_node, - address_mine.get_value_or(ADDRESS_WATCHONLY)); + address_mine.value_or(ADDRESS_WATCHONLY)); generatetoaddress(config, g_testing_setup->m_node, ADDRESS_WATCHONLY); } SyncWithValidationInterfaceQueue(); diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -5,7 +5,6 @@ #ifndef BITCOIN_INTERFACES_CHAIN_H #define BITCOIN_INTERFACES_CHAIN_H -#include #include #include @@ -105,14 +104,14 @@ virtual ~Chain() {} //! 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 getHeight() = 0; + //! chain only contains genesis block, std::nullopt if chain does not + //! contain any blocks) + virtual std::optional 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 + //! 1 for following block, and so on. Returns std::nullopt for a block not //! included in the current chain. - virtual Optional getBlockHeight(const BlockHash &hash) = 0; + virtual std::optional getBlockHeight(const BlockHash &hash) = 0; //! Get block hash. Height must be valid or this function will abort. virtual BlockHash getBlockHash(int height) = 0; @@ -123,13 +122,13 @@ //! 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 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 //! parameter (to avoid the cost of a second lookup in case this information //! is needed.) - virtual Optional findFirstBlockWithTimeAndHeight(int64_t time, - int height, - BlockHash *hash) = 0; + virtual std::optional + findFirstBlockWithTimeAndHeight(int64_t time, int height, + BlockHash *hash) = 0; //! Get locator for the current chain tip. virtual CBlockLocator getTipLocator() = 0; @@ -137,7 +136,8 @@ //! 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. - virtual Optional findLocatorFork(const CBlockLocator &locator) = 0; + virtual std::optional + findLocatorFork(const CBlockLocator &locator) = 0; //! Check if transaction will be final given chain height current time. virtual bool @@ -197,7 +197,7 @@ //! of blocks. This checks all blocks that are ancestors of block_hash in //! the height range from min_height to max_height, inclusive. virtual bool hasBlocks(const BlockHash &block_hash, int min_height = 0, - Optional max_height = {}) = 0; + std::optional max_height = {}) = 0; //! Check if transaction has descendants in mempool. virtual bool hasDescendantsInMempool(const TxId &txid) = 0; diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -166,21 +166,21 @@ public: explicit ChainImpl(NodeContext &node, const CChainParams ¶ms) : m_node(node), m_params(params) {} - Optional getHeight() override { + std::optional getHeight() override { LOCK(::cs_main); int height = ::ChainActive().Height(); if (height >= 0) { return height; } - return nullopt; + return std::nullopt; } - Optional getBlockHeight(const BlockHash &hash) override { + std::optional getBlockHeight(const BlockHash &hash) override { LOCK(::cs_main); CBlockIndex *block = LookupBlockIndex(hash); if (block && ::ChainActive().Contains(block)) { return block->nHeight; } - return nullopt; + return std::nullopt; } BlockHash getBlockHash(int height) override { LOCK(::cs_main); @@ -193,7 +193,7 @@ CBlockIndex *block = ::ChainActive()[height]; return block && (block->nStatus.hasData() != 0) && block->nTx > 0; } - Optional + std::optional findFirstBlockWithTimeAndHeight(int64_t time, int height, BlockHash *hash) override { LOCK(cs_main); @@ -205,7 +205,7 @@ } return block->nHeight; } - return nullopt; + return std::nullopt; } CBlockLocator getTipLocator() override { LOCK(cs_main); @@ -217,13 +217,14 @@ return ContextualCheckTransactionForCurrentBlock( m_params.GetConsensus(), tx, state); } - Optional findLocatorFork(const CBlockLocator &locator) override { + std::optional + findLocatorFork(const CBlockLocator &locator) override { LOCK(cs_main); if (CBlockIndex *fork = FindForkInGlobalIndex(::ChainActive(), locator)) { return fork->nHeight; } - return nullopt; + return std::nullopt; } bool findBlock(const BlockHash &hash, const FoundBlock &block) override { @@ -297,7 +298,7 @@ LookupBlockIndex(block_hash)); } bool hasBlocks(const BlockHash &block_hash, int min_height, - Optional max_height) override { + std::optional max_height) override { // hasBlocks returns true if all ancestors of block_hash in // specified range have block data (are not pruned), false if any // ancestors in specified range are missing data. diff --git a/src/miner.h b/src/miner.h --- a/src/miner.h +++ b/src/miner.h @@ -6,7 +6,6 @@ #ifndef BITCOIN_MINER_H #define BITCOIN_MINER_H -#include #include #include @@ -175,8 +174,8 @@ uint64_t GetMaxGeneratedBlockSize() const { return nMaxGeneratedBlockSize; } - static Optional m_last_block_num_txs; - static Optional m_last_block_size; + static std::optional m_last_block_num_txs; + static std::optional m_last_block_size; private: // utility functions diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -115,8 +115,8 @@ nFees = Amount::zero(); } -Optional BlockAssembler::m_last_block_num_txs{nullopt}; -Optional BlockAssembler::m_last_block_size{nullopt}; +std::optional BlockAssembler::m_last_block_num_txs{std::nullopt}; +std::optional BlockAssembler::m_last_block_size{std::nullopt}; std::unique_ptr BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { diff --git a/src/node/psbt.h b/src/node/psbt.h --- a/src/node/psbt.h +++ b/src/node/psbt.h @@ -31,11 +31,11 @@ */ struct PSBTAnalysis { //! Estimated weight of the transaction - Optional estimated_vsize; + std::optional estimated_vsize; //! Estimated feerate (fee / weight) of the transaction - Optional estimated_feerate; + std::optional estimated_feerate; //! Amount of fee being paid by the transaction - Optional fee; + std::optional fee; //! More information about the individual inputs of the transaction std::vector inputs; //! Which of the BIP 174 roles needs to handle the transaction next @@ -44,9 +44,9 @@ std::string error; void SetInvalid(std::string err_msg) { - estimated_vsize = nullopt; - estimated_feerate = nullopt; - fee = nullopt; + estimated_vsize = std::nullopt; + estimated_feerate = std::nullopt; + fee = std::nullopt; inputs.clear(); next = PSBTRole::CREATOR; error = err_msg; diff --git a/src/optional.h b/src/optional.h deleted file mode 100644 --- a/src/optional.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2017 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_OPTIONAL_H -#define BITCOIN_OPTIONAL_H - -#include - -#include - -//! Substitute for C++17 std::optional -template using Optional = boost::optional; - -//! Substitute for C++17 std::make_optional -template Optional MakeOptional(bool condition, T &&value) { - return boost::make_optional(condition, std::forward(value)); -} - -//! Substitute for C++17 std::nullopt -static auto &nullopt = boost::none; - -#endif // BITCOIN_OPTIONAL_H diff --git a/src/psbt.h b/src/psbt.h --- a/src/psbt.h +++ b/src/psbt.h @@ -7,7 +7,7 @@ #include #include -#include + #include #include #include