Skip to content

Commit 68c7acf

Browse files
committed
Merge #20671: Replace boost::optional with std::optional
fa4435e Replace boost::optional with std::optional (MarcoFalke) fa7e803 Remove unused MakeOptional (MarcoFalke) fadd402 psbt: Assert that tx has a value in UpdatePSBTOutput (MarcoFalke) Pull request description: Now that we can use std::optional from the vanilla standard library, drop the third-party boost dependency ACKs for top commit: practicalswift: cr ACK fa4435e: patch looks correct! laanwj: code review ACK fa4435e hebasto: ACK fa4435e, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 50c5a1a130cac65e043e0177ba5b009fc2ba09343af4e23322ff2eb32184a55f8f2dea66e7a1b9d9acf56bc164eef4e47448750549a07f3b661199ac9bf9afef
2 parents f061da2 + fa4435e commit 68c7acf

File tree

8 files changed

+20
-26
lines changed

8 files changed

+20
-26
lines changed

src/bench/wallet_balance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
3636
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
3737

3838
for (int i = 0; i < 100; ++i) {
39-
generatetoaddress(test_setup.m_node, address_mine.get_value_or(ADDRESS_WATCHONLY));
39+
generatetoaddress(test_setup.m_node, address_mine.value_or(ADDRESS_WATCHONLY));
4040
generatetoaddress(test_setup.m_node, ADDRESS_WATCHONLY);
4141
}
4242
SyncWithValidationInterfaceQueue();

src/optional.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
#ifndef BITCOIN_OPTIONAL_H
66
#define BITCOIN_OPTIONAL_H
77

8+
#include <optional>
89
#include <utility>
910

10-
#include <boost/optional.hpp>
11-
1211
//! Substitute for C++17 std::optional
12+
//! DEPRECATED use std::optional in new code.
1313
template <typename T>
14-
using Optional = boost::optional<T>;
15-
16-
//! Substitute for C++17 std::make_optional
17-
template <typename T>
18-
Optional<T> MakeOptional(bool condition, T&& value)
19-
{
20-
return boost::make_optional(condition, std::forward<T>(value));
21-
}
14+
using Optional = std::optional<T>;
2215

2316
//! Substitute for C++17 std::nullopt
24-
static auto& nullopt = boost::none;
17+
//! DEPRECATED use std::nullopt in new code.
18+
static auto& nullopt = std::nullopt;
2519

2620
#endif // BITCOIN_OPTIONAL_H

src/psbt.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <psbt.h>
6+
7+
#include <util/check.h>
68
#include <util/strencodings.h>
79

810

@@ -207,7 +209,8 @@ size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction& psbt) {
207209

208210
void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index)
209211
{
210-
const CTxOut& out = psbt.tx->vout.at(index);
212+
CMutableTransaction& tx = *Assert(psbt.tx);
213+
const CTxOut& out = tx.vout.at(index);
211214
PSBTOutput& psbt_out = psbt.outputs.at(index);
212215

213216
// Fill a SignatureData with output info
@@ -217,7 +220,7 @@ void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransactio
217220
// Construct a would-be spend of this output, to update sigdata with.
218221
// Note that ProduceSignature is used to fill in metadata (not actual signatures),
219222
// so provider does not need to provide any private keys (it can be a HidingSigningProvider).
220-
MutableTransactionSignatureCreator creator(psbt.tx.get_ptr(), /* index */ 0, out.nValue, SIGHASH_ALL);
223+
MutableTransactionSignatureCreator creator(&tx, /* index */ 0, out.nValue, SIGHASH_ALL);
221224
ProduceSignature(provider, creator, out.scriptPubKey, sigdata);
222225

223226
// Put redeem_script, witness_script, key paths, into PSBTOutput.

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
231231
// Write back transaction
232232
mtx = CMutableTransaction(*tx_new);
233233
// Mark new tx not replaceable, if requested.
234-
if (!coin_control.m_signal_bip125_rbf.get_value_or(wallet.m_signal_rbf)) {
234+
if (!coin_control.m_signal_bip125_rbf.value_or(wallet.m_signal_rbf)) {
235235
for (auto& input : mtx.vin) {
236236
if (input.nSequence < 0xfffffffe) input.nSequence = 0xfffffffe;
237237
}

src/wallet/fees.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ CFeeRate GetMinimumFeeRate(const CWallet& wallet, const CCoinControl& coin_contr
4949
// We will use smart fee estimation
5050
unsigned int target = coin_control.m_confirm_target ? *coin_control.m_confirm_target : wallet.m_confirm_target;
5151
// By default estimates are economical iff we are signaling opt-in-RBF
52-
bool conservative_estimate = !coin_control.m_signal_bip125_rbf.get_value_or(wallet.m_signal_rbf);
52+
bool conservative_estimate = !coin_control.m_signal_bip125_rbf.value_or(wallet.m_signal_rbf);
5353
// Allow to override the default fee estimate mode over the CoinControl instance
5454
if (coin_control.m_fee_mode == FeeEstimateMode::CONSERVATIVE) conservative_estimate = true;
5555
else if (coin_control.m_fee_mode == FeeEstimateMode::ECONOMICAL) conservative_estimate = false;

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static RPCHelpMan getrawchangeaddress()
309309
throw JSONRPCError(RPC_WALLET_ERROR, "Error: This wallet has no available keys");
310310
}
311311

312-
OutputType output_type = pwallet->m_default_change_type.get_value_or(pwallet->m_default_address_type);
312+
OutputType output_type = pwallet->m_default_change_type.value_or(pwallet->m_default_address_type);
313313
if (!request.params[0].isNull()) {
314314
if (!ParseOutputType(request.params[0].get_str(), output_type)) {
315315
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));
@@ -1573,8 +1573,7 @@ static RPCHelpMan listsinceblock()
15731573

15741574
LOCK(wallet.cs_wallet);
15751575

1576-
// The way the 'height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
1577-
Optional<int> height = MakeOptional(false, int()); // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
1576+
Optional<int> height; // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
15781577
Optional<int> altheight; // Height of the specified block, even if it's in a deactivated chain.
15791578
int target_confirms = 1;
15801579
isminefilter filter = ISMINE_SPENDABLE;
@@ -3597,7 +3596,7 @@ static RPCHelpMan rescanblockchain()
35973596
}
35983597

35993598
int start_height = 0;
3600-
Optional<int> stop_height = MakeOptional(false, int());
3599+
Optional<int> stop_height;
36013600
uint256 start_block;
36023601
{
36033602
LOCK(pwallet->cs_wallet);

src/wallet/wallet.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ static void UpdateWalletSetting(interfaces::Chain& chain,
8585
std::vector<bilingual_str>& warnings)
8686
{
8787
if (load_on_startup == nullopt) return;
88-
if (load_on_startup.get() && !AddWalletSetting(chain, wallet_name)) {
88+
if (load_on_startup.value() && !AddWalletSetting(chain, wallet_name)) {
8989
warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so wallet may not be loaded next node startup."));
90-
} else if (!load_on_startup.get() && !RemoveWalletSetting(chain, wallet_name)) {
90+
} else if (!load_on_startup.value() && !RemoveWalletSetting(chain, wallet_name)) {
9191
warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so wallet may still be loaded next node startup."));
9292
}
9393
}
@@ -3051,7 +3051,7 @@ bool CWallet::CreateTransactionInternal(
30513051
// to avoid conflicting with other possible uses of nSequence,
30523052
// and in the spirit of "smallest possible change from prior
30533053
// behavior."
3054-
const uint32_t nSequence = coin_control.m_signal_bip125_rbf.get_value_or(m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1);
3054+
const uint32_t nSequence = coin_control.m_signal_bip125_rbf.value_or(m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1);
30553055
for (const auto& coin : selected_coins) {
30563056
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
30573057
}
@@ -4055,8 +4055,7 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, const std::st
40554055

40564056
// No need to read and scan block if block was created before
40574057
// our wallet birthday (as adjusted for block time variability)
4058-
// The way the 'time_first_key' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
4059-
Optional<int64_t> time_first_key = MakeOptional(false, int64_t());;
4058+
Optional<int64_t> time_first_key;
40604059
for (auto spk_man : walletInstance->GetAllScriptPubKeyMans()) {
40614060
int64_t time = spk_man->GetTimeFirstKey();
40624061
if (!time_first_key || time < *time_first_key) time_first_key = time;

test/lint/lint-includes.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ EXPECTED_BOOST_INCLUDES=(
6060
boost/multi_index/ordered_index.hpp
6161
boost/multi_index/sequenced_index.hpp
6262
boost/multi_index_container.hpp
63-
boost/optional.hpp
6463
boost/preprocessor/cat.hpp
6564
boost/preprocessor/stringize.hpp
6665
boost/process.hpp

0 commit comments

Comments
 (0)