merge bitcoin#20671: Replace boost::optional with std::optional

This commit is contained in:
Kittywhiskers Van Gogh 2022-07-03 00:14:47 +05:30
parent c8a5fa207d
commit e235d834da
8 changed files with 19 additions and 25 deletions

View File

@ -252,7 +252,7 @@ int CTransactionBuilder::GetSizeOfCompactSizeDiff(size_t nAdd) const
bool CTransactionBuilder::IsDust(CAmount nAmount) const
{
return ::IsDust(CTxOut(nAmount, ::GetScriptForDestination(tallyItem.txdest)), coinControl.m_discard_feerate.get());
return ::IsDust(CTxOut(nAmount, ::GetScriptForDestination(tallyItem.txdest)), coinControl.m_discard_feerate.value());
}
bool CTransactionBuilder::Commit(bilingual_str& strResult)

View File

@ -78,7 +78,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
WalletTxStatus MakeWalletTxStatus(CWallet& wallet, const CWalletTx& wtx)
{
WalletTxStatus result;
result.block_height = wallet.chain().getBlockHeight(wtx.m_confirm.hashBlock).get_value_or(std::numeric_limits<int>::max());
result.block_height = wallet.chain().getBlockHeight(wtx.m_confirm.hashBlock).value_or(std::numeric_limits<int>::max());
result.blocks_to_maturity = wtx.GetBlocksToMaturity();
result.depth_in_main_chain = wtx.GetDepthInMainChain();
result.time_received = wtx.nTimeReceived;
@ -395,7 +395,7 @@ public:
return false;
}
balances = getBalances();
num_blocks = m_wallet->chain().getHeight().get_value_or(-1);
num_blocks = m_wallet->chain().getHeight().value_or(-1);
return true;
}
CAmount getBalance() override

View File

@ -5,22 +5,16 @@
#ifndef BITCOIN_OPTIONAL_H
#define BITCOIN_OPTIONAL_H
#include <optional>
#include <utility>
#include <boost/optional.hpp>
//! Substitute for C++17 std::optional
//! DEPRECATED use std::optional in new code.
template <typename T>
using Optional = boost::optional<T>;
//! Substitute for C++17 std::make_optional
template <typename T>
Optional<T> MakeOptional(bool condition, T&& value)
{
return boost::make_optional(condition, std::forward<T>(value));
}
using Optional = std::optional<T>;
//! Substitute for C++17 std::nullopt
static auto& nullopt = boost::none;
//! DEPRECATED use std::nullopt in new code.
static auto& nullopt = std::nullopt;
#endif // BITCOIN_OPTIONAL_H

View File

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <psbt.h>
#include <util/check.h>
#include <util/strencodings.h>
bool PartiallySignedTransaction::IsNull() const
@ -165,7 +166,8 @@ void PSBTOutput::Merge(const PSBTOutput& output)
void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index)
{
const CTxOut& out = psbt.tx->vout.at(index);
CMutableTransaction& tx = *Assert(psbt.tx);
const CTxOut& out = tx.vout.at(index);
PSBTOutput& psbt_out = psbt.outputs.at(index);
// Fill a SignatureData with output info
@ -175,7 +177,7 @@ void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransactio
// Construct a would-be spend of this output, to update sigdata with.
// Note that ProduceSignature is used to fill in metadata (not actual signatures),
// so provider does not need to provide any private keys (it can be a HidingSigningProvider).
MutableTransactionSignatureCreator creator(psbt.tx.get_ptr(), /* index */ 0, out.nValue, SIGHASH_ALL);
MutableTransactionSignatureCreator creator(&tx, /* index */ 0, out.nValue, SIGHASH_ALL);
ProduceSignature(provider, creator, out.scriptPubKey, sigdata);
// Put redeem_script, key paths, into PSBTOutput.

View File

@ -948,7 +948,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
file << strprintf("# Wallet dump created by Dash Core %s\n", CLIENT_BUILD);
file << strprintf("# * Created on %s\n", FormatISO8601DateTime(GetTime()));
const Optional<int> tip_height = pwallet->chain().getHeight();
file << strprintf("# * Best block at time of backup was %i (%s),\n", tip_height.get_value_or(-1), tip_height ? pwallet->chain().getBlockHash(*tip_height).ToString() : "(missing block hash)");
file << strprintf("# * Best block at time of backup was %i (%s),\n", tip_height.value_or(-1), tip_height ? pwallet->chain().getBlockHash(*tip_height).ToString() : "(missing block hash)");
file << strprintf("# mined on %s\n", tip_height ? FormatISO8601DateTime(pwallet->chain().getBlockTime(*tip_height)) : "(missing block time)");
file << "\n";

View File

@ -1562,8 +1562,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
LOCK(pwallet->cs_wallet);
// The way the 'height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
Optional<int> height = MakeOptional(false, int()); // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
Optional<int> height; // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
Optional<int> altheight; // Height of the specified block, even if it's in a deactivated chain.
int target_confirms = 1;
isminefilter filter = ISMINE_SPENDABLE;

View File

@ -97,9 +97,9 @@ static void UpdateWalletSetting(interfaces::Chain& chain,
std::vector<bilingual_str>& warnings)
{
if (load_on_startup == nullopt) return;
if (load_on_startup.get() && !AddWalletSetting(chain, wallet_name)) {
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.get() && !RemoveWalletSetting(chain, wallet_name)) {
} else if (!load_on_startup.value() && !RemoveWalletSetting(chain, wallet_name)) {
warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so wallet may still be loaded next node startup."));
}
}
@ -2514,7 +2514,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
ShowProgress(strprintf("%s " + _("Rescanning...").translated, GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
uint256 tip_hash;
// The way the 'block_height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
Optional<int> block_height = MakeOptional(false, int());
Optional<int> block_height;
double progress_begin;
double progress_end;
{
@ -3558,7 +3558,7 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain)
return false;
}
constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60; // in seconds
if (chain.getBlockTime(chain.getHeight().get_value_or(-1)) < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
if (chain.getBlockTime(chain.getHeight().value_or(-1)) < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
return false;
}
return true;
@ -3592,7 +3592,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain)
// now we ensure code won't be written that makes assumptions about
// nLockTime that preclude a fix later.
if (IsCurrentForAntiFeeSniping(chain)) {
locktime = chain.getHeight().get_value_or(-1);
locktime = chain.getHeight().value_or(-1);
// Secondly occasionally randomly pick a nLockTime even further back, so
// that transactions that are delayed after signing for whatever reason,

View File

@ -62,7 +62,6 @@ EXPECTED_BOOST_INCLUDES=(
boost/multi_index/ordered_index.hpp
boost/multi_index/sequenced_index.hpp
boost/multi_index_container.hpp
boost/optional.hpp
boost/pool/pool_alloc.hpp
boost/preprocessor/cat.hpp
boost/preprocessor/stringize.hpp