Skip to content

Commit 57e980d

Browse files
committed
scripted-diff: remove Optional & nullopt
-BEGIN VERIFY SCRIPT- git rm src/optional.h sed -i -e 's/Optional</std::optional</g' $(git grep -l 'Optional<' src) sed -i -e 's/{nullopt}/{std::nullopt}/g' $(git grep -l 'nullopt' src) sed -i -e 's/ nullopt;/ std::nullopt;/g' $(git grep -l 'nullopt' src) sed -i -e 's/ nullopt)/ std::nullopt)/g' $(git grep -l 'nullopt' src) sed -i -e 's/(nullopt)/(std::nullopt)/g' $(git grep -l 'nullopt' src) sed -i -e 's/ nullopt,/ std::nullopt,/g' $(git grep -l 'nullopt' src) sed -i -e 's/? nullopt :/? std::nullopt :/g' $(git grep -l 'nullopt' src) sed -i -e 's/: nullopt}/: std::nullopt}/g' $(git grep -l 'nullopt' src) sed -i -e '/optional.h \\/d' src/Makefile.am sed -i -e '/#include <optional.h>/d' src/test/fuzz/autofile.cpp src/test/fuzz/buffered_file.cpp src/test/fuzz/node_eviction.cpp sed -i -e 's/#include <optional.h>/#include <optional>/g' $(git grep -l '#include <optional.h>' src) -END VERIFY SCRIPT-
1 parent 3c63191 commit 57e980d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+165
-189
lines changed

src/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ BITCOIN_CORE_H = \
182182
node/ui_interface.h \
183183
node/utxo_snapshot.h \
184184
noui.h \
185-
optional.h \
186185
outputtype.h \
187186
policy/feerate.h \
188187
policy/fees.h \

src/bench/wallet_balance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <bench/bench.h>
66
#include <interfaces/chain.h>
77
#include <node/context.h>
8-
#include <optional.h>
8+
#include <optional>
99
#include <test/util/mining.h>
1010
#include <test/util/setup_common.h>
1111
#include <test/util/wallet.h>
@@ -26,7 +26,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
2626
}
2727
auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}});
2828

29-
const Optional<std::string> address_mine{add_mine ? Optional<std::string>{getnewaddress(wallet)} : nullopt};
29+
const std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{getnewaddress(wallet)} : std::nullopt};
3030
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
3131

3232
for (int i = 0; i < 100; ++i) {

src/bitcoin-cli.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <chainparamsbase.h>
1111
#include <clientversion.h>
12-
#include <optional.h>
12+
#include <optional>
1313
#include <rpc/client.h>
1414
#include <rpc/mining.h>
1515
#include <rpc/protocol.h>
@@ -611,7 +611,7 @@ class DefaultRequestHandler: public BaseRequestHandler {
611611
}
612612
};
613613

614-
static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, const std::vector<std::string>& args, const Optional<std::string>& rpcwallet = {})
614+
static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, const std::vector<std::string>& args, const std::optional<std::string>& rpcwallet = {})
615615
{
616616
std::string host;
617617
// In preference order, we choose the following for the port:
@@ -733,7 +733,7 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
733733
* @returns the RPC response as a UniValue object.
734734
* @throws a CConnectionFailed std::runtime_error if connection failed or RPC server still in warmup.
735735
*/
736-
static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& strMethod, const std::vector<std::string>& args, const Optional<std::string>& rpcwallet = {})
736+
static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& strMethod, const std::vector<std::string>& args, const std::optional<std::string>& rpcwallet = {})
737737
{
738738
UniValue response(UniValue::VOBJ);
739739
// Execute and handle connection failures with -rpcwait.
@@ -817,7 +817,7 @@ static void GetWalletBalances(UniValue& result)
817817
*/
818818
static UniValue GetNewAddress()
819819
{
820-
Optional<std::string> wallet_name{};
820+
std::optional<std::string> wallet_name{};
821821
if (gArgs.IsArgSet("-rpcwallet")) wallet_name = gArgs.GetArg("-rpcwallet", "");
822822
DefaultRequestHandler rh;
823823
return ConnectAndCallRPC(&rh, "getnewaddress", /* args=*/{}, wallet_name);
@@ -922,7 +922,7 @@ static int CommandLineRPC(int argc, char *argv[])
922922
}
923923
if (nRet == 0) {
924924
// Perform RPC call
925-
Optional<std::string> wallet_name{};
925+
std::optional<std::string> wallet_name{};
926926
if (gArgs.IsArgSet("-rpcwallet")) wallet_name = gArgs.GetArg("-rpcwallet", "");
927927
const UniValue reply = ConnectAndCallRPC(rh.get(), method, args, wallet_name);
928928

src/interfaces/chain.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef BITCOIN_INTERFACES_CHAIN_H
66
#define BITCOIN_INTERFACES_CHAIN_H
77

8-
#include <optional.h> // For Optional and nullopt
8+
#include <optional> // For Optional and nullopt
99
#include <primitives/transaction.h> // For CTransactionRef
1010
#include <util/settings.h> // For util::SettingsValue
1111

@@ -94,7 +94,7 @@ class Chain
9494
//! Get current chain height, not including genesis block (returns 0 if
9595
//! chain only contains genesis block, nullopt if chain does not contain
9696
//! any blocks)
97-
virtual Optional<int> getHeight() = 0;
97+
virtual std::optional<int> getHeight() = 0;
9898

9999
//! Get block hash. Height must be valid or this function will abort.
100100
virtual uint256 getBlockHash(int height) = 0;
@@ -109,7 +109,7 @@ class Chain
109109
//! Return height of the highest block on chain in common with the locator,
110110
//! which will either be the original block used to create the locator,
111111
//! or one of its ancestors.
112-
virtual Optional<int> findLocatorFork(const CBlockLocator& locator) = 0;
112+
virtual std::optional<int> findLocatorFork(const CBlockLocator& locator) = 0;
113113

114114
//! Check if transaction will be final given chain height current time.
115115
virtual bool checkFinalTx(const CTransaction& tx) = 0;
@@ -154,7 +154,7 @@ class Chain
154154
//! Return true if data is available for all blocks in the specified range
155155
//! of blocks. This checks all blocks that are ancestors of block_hash in
156156
//! the height range from min_height to max_height, inclusive.
157-
virtual bool hasBlocks(const uint256& block_hash, int min_height = 0, Optional<int> max_height = {}) = 0;
157+
virtual bool hasBlocks(const uint256& block_hash, int min_height = 0, std::optional<int> max_height = {}) = 0;
158158

159159
//! Check if transaction is RBF opt in.
160160
virtual RBFTransactionState isRBFOptIn(const CTransaction& tx) = 0;

src/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void BlockAssembler::resetBlock()
9696
nFees = 0;
9797
}
9898

99-
Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt};
100-
Optional<int64_t> BlockAssembler::m_last_block_weight{nullopt};
99+
std::optional<int64_t> BlockAssembler::m_last_block_num_txs{std::nullopt};
100+
std::optional<int64_t> BlockAssembler::m_last_block_weight{std::nullopt};
101101

102102
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn)
103103
{

src/miner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef BITCOIN_MINER_H
77
#define BITCOIN_MINER_H
88

9-
#include <optional.h>
9+
#include <optional>
1010
#include <primitives/block.h>
1111
#include <txmempool.h>
1212
#include <validation.h>
@@ -160,8 +160,8 @@ class BlockAssembler
160160
/** Construct a new block template with coinbase to scriptPubKeyIn */
161161
std::unique_ptr<CBlockTemplate> CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn);
162162

163-
static Optional<int64_t> m_last_block_num_txs;
164-
static Optional<int64_t> m_last_block_weight;
163+
static std::optional<int64_t> m_last_block_num_txs;
164+
static std::optional<int64_t> m_last_block_weight;
165165

166166
private:
167167
// utility functions

src/net.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <net_permissions.h>
1919
#include <netbase.h>
2020
#include <node/ui_interface.h>
21-
#include <optional.h>
21+
#include <optional>
2222
#include <protocol.h>
2323
#include <random.h>
2424
#include <scheduler.h>
@@ -193,7 +193,7 @@ bool IsPeerAddrLocalGood(CNode *pnode)
193193
IsReachable(addrLocal.GetNetwork());
194194
}
195195

196-
Optional<CAddress> GetLocalAddrForPeer(CNode *pnode)
196+
std::optional<CAddress> GetLocalAddrForPeer(CNode *pnode)
197197
{
198198
CAddress addrLocal = GetLocalAddress(&pnode->addr, pnode->GetLocalServices());
199199
if (gArgs.GetBoolArg("-addrmantest", false)) {
@@ -215,7 +215,7 @@ Optional<CAddress> GetLocalAddrForPeer(CNode *pnode)
215215
return addrLocal;
216216
}
217217
// Address is unroutable. Don't advertise.
218-
return nullopt;
218+
return std::nullopt;
219219
}
220220

221221
// learn a new local address
@@ -632,7 +632,7 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
632632
if (m_deserializer->Complete()) {
633633
// decompose a transport agnostic CNetMessage from the deserializer
634634
uint32_t out_err_raw_size{0};
635-
Optional<CNetMessage> result{m_deserializer->GetMessage(time, out_err_raw_size)};
635+
std::optional<CNetMessage> result{m_deserializer->GetMessage(time, out_err_raw_size)};
636636
if (!result) {
637637
// Message deserialization failed. Drop the message but don't disconnect the peer.
638638
// store the size of the corrupt message
@@ -723,10 +723,10 @@ const uint256& V1TransportDeserializer::GetMessageHash() const
723723
return data_hash;
724724
}
725725

726-
Optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono::microseconds time, uint32_t& out_err_raw_size)
726+
std::optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono::microseconds time, uint32_t& out_err_raw_size)
727727
{
728728
// decompose a single CNetMessage from the TransportDeserializer
729-
Optional<CNetMessage> msg(std::move(vRecv));
729+
std::optional<CNetMessage> msg(std::move(vRecv));
730730

731731
// store command string, time, and sizes
732732
msg->m_command = hdr.GetCommand();
@@ -747,12 +747,12 @@ Optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono::mic
747747
HexStr(hdr.pchChecksum),
748748
m_node_id);
749749
out_err_raw_size = msg->m_raw_message_size;
750-
msg = nullopt;
750+
msg = std::nullopt;
751751
} else if (!hdr.IsCommandValid()) {
752752
LogPrint(BCLog::NET, "HEADER ERROR - COMMAND (%s, %u bytes), peer=%d\n",
753753
hdr.GetCommand(), msg->m_message_size, m_node_id);
754754
out_err_raw_size = msg->m_raw_message_size;
755-
msg = nullopt;
755+
msg = std::nullopt;
756756
}
757757

758758
// Always reset the network deserializer (prepare for the next message)
@@ -879,7 +879,7 @@ static void EraseLastKElements(std::vector<T> &elements, Comparator comparator,
879879
elements.erase(elements.end() - eraseSize, elements.end());
880880
}
881881

882-
[[nodiscard]] Optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates)
882+
[[nodiscard]] std::optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates)
883883
{
884884
// Protect connections with certain characteristics
885885

@@ -918,7 +918,7 @@ static void EraseLastKElements(std::vector<T> &elements, Comparator comparator,
918918
total_protect_size -= initial_size - vEvictionCandidates.size();
919919
EraseLastKElements(vEvictionCandidates, ReverseCompareNodeTimeConnected, total_protect_size);
920920

921-
if (vEvictionCandidates.empty()) return nullopt;
921+
if (vEvictionCandidates.empty()) return std::nullopt;
922922

923923
// If any remaining peers are preferred for eviction consider only them.
924924
// This happens after the other preferences since if a peer is really the best by other criteria (esp relaying blocks)
@@ -989,7 +989,7 @@ bool CConnman::AttemptToEvictConnection()
989989
vEvictionCandidates.push_back(candidate);
990990
}
991991
}
992-
const Optional<NodeId> node_id_to_evict = SelectNodeToEvict(std::move(vEvictionCandidates));
992+
const std::optional<NodeId> node_id_to_evict = SelectNodeToEvict(std::move(vEvictionCandidates));
993993
if (!node_id_to_evict) {
994994
return false;
995995
}

src/net.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <net_permissions.h>
1919
#include <netaddress.h>
2020
#include <netbase.h>
21-
#include <optional.h>
21+
#include <optional>
2222
#include <policy/feerate.h>
2323
#include <protocol.h>
2424
#include <random.h>
@@ -200,7 +200,7 @@ enum
200200

201201
bool IsPeerAddrLocalGood(CNode *pnode);
202202
/** Returns a local address that we should advertise to this peer */
203-
Optional<CAddress> GetLocalAddrForPeer(CNode *pnode);
203+
std::optional<CAddress> GetLocalAddrForPeer(CNode *pnode);
204204

205205
/**
206206
* Mark a network as reachable or unreachable (no automatic connects to it)
@@ -311,7 +311,7 @@ class TransportDeserializer {
311311
/** read and deserialize data, advances msg_bytes data pointer */
312312
virtual int Read(Span<const uint8_t>& msg_bytes) = 0;
313313
// decomposes a message from the context
314-
virtual Optional<CNetMessage> GetMessage(std::chrono::microseconds time, uint32_t& out_err) = 0;
314+
virtual std::optional<CNetMessage> GetMessage(std::chrono::microseconds time, uint32_t& out_err) = 0;
315315
virtual ~TransportDeserializer() {}
316316
};
317317

@@ -375,7 +375,7 @@ class V1TransportDeserializer final : public TransportDeserializer
375375
}
376376
return ret;
377377
}
378-
Optional<CNetMessage> GetMessage(std::chrono::microseconds time, uint32_t& out_err_raw_size) override;
378+
std::optional<CNetMessage> GetMessage(std::chrono::microseconds time, uint32_t& out_err_raw_size) override;
379379
};
380380

381381
/** The TransportSerializer prepares messages for the network transport
@@ -1283,6 +1283,6 @@ struct NodeEvictionCandidate
12831283
bool m_is_local;
12841284
};
12851285

1286-
[[nodiscard]] Optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates);
1286+
[[nodiscard]] std::optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates);
12871287

12881288
#endif // BITCOIN_NET_H

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4222,7 +4222,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
42224222
if (pto->m_next_local_addr_send != 0us) {
42234223
pto->m_addr_known->reset();
42244224
}
4225-
if (Optional<CAddress> local_addr = GetLocalAddrForPeer(pto)) {
4225+
if (std::optional<CAddress> local_addr = GetLocalAddrForPeer(pto)) {
42264226
FastRandomContext insecure_rand;
42274227
pto->PushAddress(*local_addr, insecure_rand);
42284228
}

src/node/interfaces.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,15 @@ class ChainImpl : public Chain
415415
{
416416
public:
417417
explicit ChainImpl(NodeContext& node) : m_node(node) {}
418-
Optional<int> getHeight() override
418+
std::optional<int> getHeight() override
419419
{
420420
LOCK(::cs_main);
421421
const CChain& active = Assert(m_node.chainman)->ActiveChain();
422422
int height = active.Height();
423423
if (height >= 0) {
424424
return height;
425425
}
426-
return nullopt;
426+
return std::nullopt;
427427
}
428428
uint256 getBlockHash(int height) override
429429
{
@@ -452,15 +452,15 @@ class ChainImpl : public Chain
452452
assert(std::addressof(::ChainActive()) == std::addressof(m_node.chainman->ActiveChain()));
453453
return CheckFinalTx(m_node.chainman->ActiveChain().Tip(), tx);
454454
}
455-
Optional<int> findLocatorFork(const CBlockLocator& locator) override
455+
std::optional<int> findLocatorFork(const CBlockLocator& locator) override
456456
{
457457
LOCK(cs_main);
458458
const CChain& active = Assert(m_node.chainman)->ActiveChain();
459459
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
460460
if (CBlockIndex* fork = m_node.chainman->m_blockman.FindForkInGlobalIndex(active, locator)) {
461461
return fork->nHeight;
462462
}
463-
return nullopt;
463+
return std::nullopt;
464464
}
465465
bool findBlock(const uint256& hash, const FoundBlock& block) override
466466
{
@@ -518,7 +518,7 @@ class ChainImpl : public Chain
518518
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
519519
return GuessVerificationProgress(Params().TxData(), m_node.chainman->m_blockman.LookupBlockIndex(block_hash));
520520
}
521-
bool hasBlocks(const uint256& block_hash, int min_height, Optional<int> max_height) override
521+
bool hasBlocks(const uint256& block_hash, int min_height, std::optional<int> max_height) override
522522
{
523523
// hasBlocks returns true if all ancestors of block_hash in specified
524524
// range have block data (are not pruned), false if any ancestors in

0 commit comments

Comments
 (0)