diff options
author | fanquake <fanquake@gmail.com> | 2021-03-15 11:59:05 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-03-17 14:56:20 +0800 |
commit | ebc4ab721b0371c0ef217c0f5bd7d42613e951e6 (patch) | |
tree | c4f91deb60589d4d6e5c347d99ca7c611a01ee79 | |
parent | 57e980d13ca488031bde6ef197cf34d493d36796 (diff) |
refactor: post Optional<> removal cleanups
37 files changed, 53 insertions, 39 deletions
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index 867be7296b..d7cc167885 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -5,13 +5,14 @@ #include <bench/bench.h> #include <interfaces/chain.h> #include <node/context.h> -#include <optional> #include <test/util/mining.h> #include <test/util/setup_common.h> #include <test/util/wallet.h> #include <validationinterface.h> #include <wallet/wallet.h> +#include <optional> + static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_watchonly, const bool add_mine) { const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index de3c73c78a..ecd08c62eb 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -9,7 +9,6 @@ #include <chainparamsbase.h> #include <clientversion.h> -#include <optional> #include <rpc/client.h> #include <rpc/mining.h> #include <rpc/protocol.h> @@ -24,6 +23,7 @@ #include <cmath> #include <functional> #include <memory> +#include <optional> #include <stdio.h> #include <string> #include <tuple> diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 32f06aec2c..1b4ca3e9a8 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -25,6 +25,7 @@ #include <util/url.h> #include <functional> +#include <optional> const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr; UrlDecodeFn* const URL_DECODE = urlDecode; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 50294ee375..3395741b1b 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -5,12 +5,12 @@ #ifndef BITCOIN_INTERFACES_CHAIN_H #define BITCOIN_INTERFACES_CHAIN_H -#include <optional> // For Optional and nullopt #include <primitives/transaction.h> // For CTransactionRef #include <util/settings.h> // For util::SettingsValue #include <functional> #include <memory> +#include <optional> #include <stddef.h> #include <stdint.h> #include <string> diff --git a/src/miner.cpp b/src/miner.cpp index 53404e2b9d..fe7a54c052 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -96,9 +96,6 @@ void BlockAssembler::resetBlock() nFees = 0; } -std::optional<int64_t> BlockAssembler::m_last_block_num_txs{std::nullopt}; -std::optional<int64_t> BlockAssembler::m_last_block_weight{std::nullopt}; - std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn) { int64_t nTimeStart = GetTimeMicros(); diff --git a/src/miner.h b/src/miner.h index 236d792f1e..023635814c 100644 --- a/src/miner.h +++ b/src/miner.h @@ -6,12 +6,12 @@ #ifndef BITCOIN_MINER_H #define BITCOIN_MINER_H -#include <optional> #include <primitives/block.h> #include <txmempool.h> #include <validation.h> #include <memory> +#include <optional> #include <stdint.h> #include <boost/multi_index_container.hpp> @@ -160,8 +160,8 @@ public: /** Construct a new block template with coinbase to scriptPubKeyIn */ std::unique_ptr<CBlockTemplate> CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn); - static std::optional<int64_t> m_last_block_num_txs; - static std::optional<int64_t> m_last_block_weight; + inline static std::optional<int64_t> m_last_block_num_txs{}; + inline static std::optional<int64_t> m_last_block_weight{}; private: // utility functions diff --git a/src/net.cpp b/src/net.cpp index fb8e06d14b..6a2469f950 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -18,7 +18,6 @@ #include <net_permissions.h> #include <netbase.h> #include <node/ui_interface.h> -#include <optional> #include <protocol.h> #include <random.h> #include <scheduler.h> @@ -39,6 +38,7 @@ #include <algorithm> #include <cstdint> #include <functional> +#include <optional> #include <unordered_map> #include <math.h> @@ -752,7 +752,7 @@ std::optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono LogPrint(BCLog::NET, "HEADER ERROR - COMMAND (%s, %u bytes), peer=%d\n", hdr.GetCommand(), msg->m_message_size, m_node_id); out_err_raw_size = msg->m_raw_message_size; - msg = std::nullopt; + msg.reset(); } // Always reset the network deserializer (prepare for the next message) @@ -18,7 +18,6 @@ #include <net_permissions.h> #include <netaddress.h> #include <netbase.h> -#include <optional> #include <policy/feerate.h> #include <protocol.h> #include <random.h> @@ -35,6 +34,7 @@ #include <deque> #include <map> #include <memory> +#include <optional> #include <thread> #include <vector> diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 4d9dc2204d..b600cc3a1a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -34,6 +34,7 @@ #include <validation.h> #include <memory> +#include <optional> #include <typeinfo> /** How long to cache transactions in mapRelay for normal relay */ diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 7a4fa0a613..50c8c29175 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -50,6 +50,7 @@ #endif #include <memory> +#include <optional> #include <utility> using interfaces::BlockTip; diff --git a/src/node/psbt.h b/src/node/psbt.h index 009e0941e1..def4385c09 100644 --- a/src/node/psbt.h +++ b/src/node/psbt.h @@ -7,6 +7,8 @@ #include <psbt.h> +#include <optional> + /** * Holds an analysis of one input from a PSBT */ @@ -28,9 +30,9 @@ struct PSBTAnalysis { std::optional<size_t> estimated_vsize; //!< Estimated weight of the transaction std::optional<CFeeRate> estimated_feerate; //!< Estimated feerate (fee / weight) of the transaction std::optional<CAmount> fee; //!< Amount of fee being paid by the transaction - std::vector<PSBTInputAnalysis> inputs; //!< More information about the individual inputs of the transaction - PSBTRole next; //!< Which of the BIP 174 roles needs to handle the transaction next - std::string error; //!< Error message + std::vector<PSBTInputAnalysis> inputs; //!< More information about the individual inputs of the transaction + PSBTRole next; //!< Which of the BIP 174 roles needs to handle the transaction next + std::string error; //!< Error message void SetInvalid(std::string err_msg) { diff --git a/src/psbt.h b/src/psbt.h index 319eb48cb0..96ae39fdb8 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -7,13 +7,14 @@ #include <attributes.h> #include <node/transaction.h> -#include <optional> #include <policy/feerate.h> #include <primitives/transaction.h> #include <pubkey.h> #include <script/sign.h> #include <script/signingprovider.h> +#include <optional> + // Magic bytes static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}; diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index cfe1da12e8..30399dca51 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -17,6 +17,7 @@ #include <util/vector.h> #include <memory> +#include <optional> #include <string> #include <vector> diff --git a/src/script/descriptor.h b/src/script/descriptor.h index c8d9efb11f..332ae2f230 100644 --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -5,12 +5,12 @@ #ifndef BITCOIN_SCRIPT_DESCRIPTOR_H #define BITCOIN_SCRIPT_DESCRIPTOR_H -#include <optional> #include <outputtype.h> #include <script/script.h> #include <script/sign.h> #include <script/signingprovider.h> +#include <optional> #include <vector> using ExtPubKeyMap = std::unordered_map<uint32_t, CExtPubKey>; diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index 791480a6c5..aecf955fee 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -10,6 +10,7 @@ #include <boost/test/unit_test.hpp> +#include <optional> #include <string> #include <vector> diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp index 66b0fdc090..1290c78712 100644 --- a/src/test/fuzz/deserialize.cpp +++ b/src/test/fuzz/deserialize.cpp @@ -15,7 +15,6 @@ #include <net.h> #include <netbase.h> #include <node/utxo_snapshot.h> -#include <optional> #include <primitives/block.h> #include <protocol.h> #include <psbt.h> @@ -26,6 +25,7 @@ #include <version.h> #include <exception> +#include <optional> #include <stdexcept> #include <stdint.h> #include <unistd.h> diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index dc2f1e2160..272f6415a9 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -7,7 +7,6 @@ #include <net.h> #include <net_permissions.h> #include <netaddress.h> -#include <optional> #include <protocol.h> #include <random.h> #include <test/fuzz/FuzzedDataProvider.h> @@ -17,6 +16,7 @@ #include <test/util/setup_common.h> #include <cstdint> +#include <optional> #include <string> #include <vector> diff --git a/src/test/fuzz/p2p_transport_deserializer.cpp b/src/test/fuzz/p2p_transport_deserializer.cpp index c07cf9322e..3a1fdaad8f 100644 --- a/src/test/fuzz/p2p_transport_deserializer.cpp +++ b/src/test/fuzz/p2p_transport_deserializer.cpp @@ -10,6 +10,7 @@ #include <cassert> #include <cstdint> #include <limits> +#include <optional> #include <vector> void initialize_p2p_transport_deserializer() diff --git a/src/test/fuzz/psbt.cpp b/src/test/fuzz/psbt.cpp index e06f9d33bc..d1cc6f9c7e 100644 --- a/src/test/fuzz/psbt.cpp +++ b/src/test/fuzz/psbt.cpp @@ -5,7 +5,6 @@ #include <test/fuzz/fuzz.h> #include <node/psbt.h> -#include <optional> #include <psbt.h> #include <pubkey.h> #include <script/script.h> @@ -13,6 +12,7 @@ #include <version.h> #include <cstdint> +#include <optional> #include <string> #include <vector> diff --git a/src/test/fuzz/script_descriptor_cache.cpp b/src/test/fuzz/script_descriptor_cache.cpp index 7c88fb2f47..6ce13d5679 100644 --- a/src/test/fuzz/script_descriptor_cache.cpp +++ b/src/test/fuzz/script_descriptor_cache.cpp @@ -2,7 +2,6 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include <optional> #include <pubkey.h> #include <script/descriptor.h> #include <test/fuzz/FuzzedDataProvider.h> @@ -10,6 +9,7 @@ #include <test/fuzz/util.h> #include <cstdint> +#include <optional> #include <string> #include <vector> diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 4509d0b68c..3172f119bd 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -9,7 +9,6 @@ #include <cstdint> #include <net.h> #include <netbase.h> -#include <optional> #include <serialize.h> #include <span.h> #include <streams.h> @@ -24,6 +23,7 @@ #include <algorithm> #include <ios> #include <memory> +#include <optional> #include <string> using namespace std::literals; diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index deb5e1e720..55f1069d0c 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -7,7 +7,6 @@ #include <clientversion.h> #include <hash.h> // For Hash() #include <key.h> // For CKey -#include <optional> #include <sync.h> #include <test/util/logging.h> #include <test/util/setup_common.h> @@ -23,6 +22,7 @@ #include <util/vector.h> #include <array> +#include <optional> #include <stdint.h> #include <string.h> #include <thread> diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 5691a5faf5..faccd1ade0 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -8,7 +8,6 @@ #include <consensus/consensus.h> #include <consensus/tx_verify.h> #include <consensus/validation.h> -#include <optional> #include <policy/fees.h> #include <policy/policy.h> #include <policy/settings.h> @@ -19,6 +18,8 @@ #include <validation.h> #include <validationinterface.h> +#include <optional> + CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, int64_t _nTime, unsigned int _entryHeight, bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp) @@ -894,7 +895,7 @@ std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const uint256& txid) const { auto it = mapTx.find(txid); if (it != mapTx.end()) return it; - return std::optional<txiter>{}; + return {}; } CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>& hashes) const diff --git a/src/txmempool.h b/src/txmempool.h index 658efbce83..9d4ea760e7 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -8,6 +8,7 @@ #include <atomic> #include <map> +#include <optional> #include <set> #include <string> #include <utility> @@ -16,7 +17,6 @@ #include <amount.h> #include <coins.h> #include <indirectmap.h> -#include <optional> #include <policy/feerate.h> #include <primitives/transaction.h> #include <random.h> diff --git a/src/util/system.h b/src/util/system.h index 4c965ce114..291f3f5541 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -19,7 +19,6 @@ #include <compat/assumptions.h> #include <fs.h> #include <logging.h> -#include <optional> #include <sync.h> #include <tinyformat.h> #include <util/settings.h> @@ -28,6 +27,7 @@ #include <exception> #include <map> +#include <optional> #include <set> #include <stdint.h> #include <string> diff --git a/src/util/tokenpipe.cpp b/src/util/tokenpipe.cpp index 79465dd430..4c091cd2e6 100644 --- a/src/util/tokenpipe.cpp +++ b/src/util/tokenpipe.cpp @@ -9,6 +9,7 @@ #include <errno.h> #include <fcntl.h> +#include <optional> #include <unistd.h> TokenPipeEnd TokenPipe::TakeReadEnd() diff --git a/src/validation.cpp b/src/validation.cpp index e48bea4b89..b50edeb6fa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -23,7 +23,6 @@ #include <logging/timer.h> #include <node/coinstats.h> #include <node/ui_interface.h> -#include <optional> #include <policy/policy.h> #include <policy/settings.h> #include <pow.h> @@ -50,6 +49,7 @@ #include <validationinterface.h> #include <warnings.h> +#include <optional> #include <string> #include <boost/algorithm/string/replace.hpp> diff --git a/src/validation.h b/src/validation.h index 119e4bb544..1d3be63a56 100644 --- a/src/validation.h +++ b/src/validation.h @@ -17,7 +17,6 @@ #include <crypto/common.h> // for ReadLE64 #include <fs.h> #include <node/utxo_snapshot.h> -#include <optional> #include <policy/feerate.h> #include <protocol.h> // For CMessageHeader::MessageStartChars #include <script/script_error.h> @@ -32,6 +31,7 @@ #include <atomic> #include <map> #include <memory> +#include <optional> #include <set> #include <stdint.h> #include <string> @@ -205,8 +205,7 @@ struct MempoolAcceptResult { /** Constructor for failure case */ explicit MempoolAcceptResult(TxValidationState state) - : m_result_type(ResultType::INVALID), - m_state(state), m_replaced_transactions(std::nullopt), m_base_fees(std::nullopt) { + : m_result_type(ResultType::INVALID), m_state(state) { Assume(!state.IsValid()); // Can be invalid or error } diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index bf7107d0d5..d25a3fb3fa 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -5,13 +5,14 @@ #ifndef BITCOIN_WALLET_COINCONTROL_H #define BITCOIN_WALLET_COINCONTROL_H -#include <optional> #include <outputtype.h> #include <policy/feerate.h> #include <policy/fees.h> #include <primitives/transaction.h> #include <script/standard.h> +#include <optional> + const int DEFAULT_MIN_DEPTH = 0; const int DEFAULT_MAX_DEPTH = 9999999; diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp index fe4ef21d28..5a18308a73 100644 --- a/src/wallet/coinselection.cpp +++ b/src/wallet/coinselection.cpp @@ -4,11 +4,12 @@ #include <wallet/coinselection.h> -#include <optional> #include <policy/feerate.h> #include <util/system.h> #include <util/moneystr.h> +#include <optional> + // Descending order comparator struct { bool operator()(const OutputGroup& a, const OutputGroup& b) const diff --git a/src/wallet/db.h b/src/wallet/db.h index 2bc50bacfd..7a0d3d2e07 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -8,12 +8,12 @@ #include <clientversion.h> #include <fs.h> -#include <optional> #include <streams.h> #include <support/allocators/secure.h> #include <atomic> #include <memory> +#include <optional> #include <string> struct bilingual_str; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index a6e7956262..0737e68cf3 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1788,7 +1788,7 @@ RPCHelpMan listdescriptors() const bool active = active_spk_mans.count(desc_spk_man) != 0; spk.pushKV("active", active); const auto& type = wallet_descriptor.descriptor->GetOutputType(); - if (active && type != std::nullopt) { + if (active && type) { spk.pushKV("internal", wallet->GetScriptPubKeyMan(*type, true) == desc_spk_man); } if (wallet_descriptor.descriptor->IsRange()) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cf71f1e163..f6bae47365 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8,7 +8,6 @@ #include <interfaces/chain.h> #include <key_io.h> #include <node/context.h> -#include <optional> #include <outputtype.h> #include <policy/feerate.h> #include <policy/fees.h> @@ -38,6 +37,7 @@ #include <wallet/walletdb.h> #include <wallet/walletutil.h> +#include <optional> #include <stdint.h> #include <univalue.h> @@ -219,7 +219,7 @@ static void SetFeeEstimateMode(const CWallet& wallet, CCoinControl& cc, const Un cc.m_feerate = CFeeRate(AmountFromValue(fee_rate), COIN); if (override_min_fee) cc.fOverrideFeeRate = true; // Default RBF to true for explicit fee_rate, if unset. - if (cc.m_signal_bip125_rbf == std::nullopt) cc.m_signal_bip125_rbf = true; + if (!cc.m_signal_bip125_rbf) cc.m_signal_bip125_rbf = true; return; } if (!estimate_mode.isNull() && !FeeModeFromString(estimate_mode.get_str(), cc.m_fee_mode)) { diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 2ec1430c83..54319ca662 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -16,6 +16,8 @@ #include <wallet/external_signer.h> #include <wallet/scriptpubkeyman.h> +#include <optional> + //! Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value. See BIP 32 for more details. const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ad1d04d084..2b36da2e0e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -13,7 +13,6 @@ #include <interfaces/wallet.h> #include <key.h> #include <key_io.h> -#include <optional> #include <outputtype.h> #include <policy/fees.h> #include <policy/policy.h> @@ -40,6 +39,7 @@ #include <algorithm> #include <assert.h> +#include <optional> #include <boost/algorithm/string/replace.hpp> @@ -87,7 +87,7 @@ static void UpdateWalletSetting(interfaces::Chain& chain, std::optional<bool> load_on_startup, std::vector<bilingual_str>& warnings) { - if (load_on_startup == std::nullopt) return; + if (!load_on_startup) return; if (load_on_startup.value() && !AddWalletSetting(chain, wallet_name)) { warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so wallet may not be loaded next node startup.")); } else if (!load_on_startup.value() && !RemoveWalletSetting(chain, wallet_name)) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 5087ffb35c..13a856afb0 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -30,6 +30,7 @@ #include <atomic> #include <map> #include <memory> +#include <optional> #include <set> #include <stdexcept> #include <stdint.h> diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index c9bb73bb7c..3d9248009f 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -23,6 +23,7 @@ #include <wallet/wallet.h> #include <atomic> +#include <optional> #include <string> namespace DBKeys { |