From 174482409b1734aba96683a06a9e12fb46ceb81d Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Wed, 1 Jun 2022 11:20:56 +0100 Subject: [PATCH 1/2] Remove Boost Optional --- src/Makefile.am | 1 - src/bench/wallet_balance.cpp | 7 ++++--- src/chainparams.cpp | 4 ++-- src/flushablestorage.h | 15 +++++++------- src/interfaces/chain.cpp | 32 ++++++++++++++--------------- src/interfaces/chain.h | 19 +++++++++-------- src/masternodes/accounts.cpp | 2 +- src/masternodes/accounts.h | 2 +- src/masternodes/accountshistory.cpp | 2 +- src/masternodes/accountshistory.h | 2 +- src/masternodes/anchors.cpp | 2 +- src/masternodes/anchors.h | 2 +- src/masternodes/loan.cpp | 24 ++++++++++++---------- src/masternodes/loan.h | 24 +++++++++++----------- src/masternodes/masternodes.cpp | 28 ++++++++++++------------- src/masternodes/masternodes.h | 28 ++++++++++++------------- src/masternodes/mn_checks.cpp | 10 ++++----- src/masternodes/mn_checks.h | 4 ++-- src/masternodes/mn_rpc.cpp | 14 ++++++------- src/masternodes/oracles.h | 4 ++-- src/masternodes/poolpairs.cpp | 14 +++++++------ src/masternodes/poolpairs.h | 6 +++--- src/masternodes/res.h | 3 +-- src/masternodes/rpc_loan.cpp | 4 ++-- src/masternodes/rpc_oracles.cpp | 2 +- src/masternodes/tokens.cpp | 8 ++++---- src/masternodes/tokens.h | 10 ++++----- src/masternodes/undos.cpp | 2 +- src/masternodes/undos.h | 2 +- src/masternodes/vault.cpp | 10 ++++----- src/masternodes/vault.h | 10 ++++----- src/miner.cpp | 5 +---- src/miner.h | 6 +++--- src/node/psbt.h | 6 +++--- src/optional.h | 26 ----------------------- src/pos.cpp | 4 ++-- src/pos.h | 6 ++---- src/primitives/block.h | 2 -- src/psbt.cpp | 9 ++++++-- src/psbt.h | 5 +++-- src/rpc/rawtransaction.cpp | 6 +++--- src/rpc/rawtransaction_util.cpp | 2 +- src/rpc/rawtransaction_util.h | 2 -- src/script/sign.h | 1 - src/serialize_optional.h | 7 ++++--- src/test/blockencodings_tests.cpp | 2 +- src/test/storage_tests.cpp | 2 +- src/txmempool.cpp | 6 +++--- src/txmempool.h | 2 +- src/validation.cpp | 7 +++---- src/wallet/coincontrol.h | 10 ++++----- src/wallet/coinselection.cpp | 4 +--- src/wallet/feebumper.cpp | 4 ++-- src/wallet/fees.cpp | 2 +- src/wallet/rpcdump.cpp | 10 ++++----- src/wallet/rpcwallet.cpp | 11 +++++----- src/wallet/wallet.cpp | 27 ++++++++++++------------ src/wallet/wallet.h | 2 +- test/lint/lint-includes.sh | 1 - 59 files changed, 220 insertions(+), 254 deletions(-) delete mode 100644 src/optional.h diff --git a/src/Makefile.am b/src/Makefile.am index 3fa0f075bb..df16134615 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -195,7 +195,6 @@ DEFI_CORE_H = \ node/psbt.h \ node/transaction.h \ noui.h \ - optional.h \ outputtype.h \ policy/feerate.h \ policy/fees.h \ diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index a0889b97f3..8412920a2a 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -4,11 +4,12 @@ #include #include -#include #include #include #include +#include + static void WalletBalance(benchmark::State& state, const bool set_dirty, const bool add_watchonly, const bool add_mine) { const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE; @@ -22,11 +23,11 @@ static void WalletBalance(benchmark::State& state, const bool set_dirty, const b } - const Optional address_mine{add_mine ? Optional{getnewaddress(wallet)} : nullopt}; + const std::optional address_mine{add_mine ? std::optional{getnewaddress(wallet)} : std::nullopt}; if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY); for (int i = 0; i < 100; ++i) { - generatetoaddress(address_mine.get_value_or(ADDRESS_WATCHONLY)); + generatetoaddress(address_mine.value_or(ADDRESS_WATCHONLY)); generatetoaddress(ADDRESS_WATCHONLY); } SyncWithValidationInterfaceQueue(); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f38480304e..315fd21f43 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -925,7 +925,7 @@ class CRegTestParams : public CChainParams { }; /// Check for fork height based flag, validate and set the value to a target var -boost::optional UpdateHeightValidation(const std::string& argName, const std::string& argFlag, int& argTarget) { +std::optional UpdateHeightValidation(const std::string& argName, const std::string& argFlag, int& argTarget) { if (gArgs.IsArgSet(argFlag)) { int64_t height = gArgs.GetArg(argFlag, argTarget); if (height < -1 || height >= std::numeric_limits::max()) { @@ -953,7 +953,7 @@ void SetupCommonArgActivationParams(Consensus::Params &consensus) { UpdateHeightValidation("Dakota Crescent", "-dakotacrescentheight", consensus.DakotaCrescentHeight); auto eunosHeight = UpdateHeightValidation("Eunos", "-eunosheight", consensus.EunosHeight); if (eunosHeight.has_value()){ - consensus.EunosKampungHeight = static_cast(eunosHeight.get()); + consensus.EunosKampungHeight = static_cast(eunosHeight.value()); } UpdateHeightValidation("Eunos Paya", "-eunospayaheight", consensus.EunosPayaHeight); UpdateHeightValidation("Fort Canning", "-fortcanningheight", consensus.FortCanningHeight); diff --git a/src/flushablestorage.h b/src/flushablestorage.h index acb886022f..c1abd0ef1a 100644 --- a/src/flushablestorage.h +++ b/src/flushablestorage.h @@ -7,14 +7,15 @@ #include #include -#include #include #include +#include + #include using TBytes = std::vector; -using MapKV = std::map>; +using MapKV = std::map>; template static TBytes DbTypeToBytes(const T& value) { @@ -291,7 +292,7 @@ class CFlushableStorageKV : public CStorageKV { if (it == changed.end()) { return db.Read(key, value); } else if (it->second) { - value = it->second.get(); + value = it->second.value(); return true; } else { return false; @@ -303,7 +304,7 @@ class CFlushableStorageKV : public CStorageKV { if (!db.Erase(it.first)) { return false; } - } else if (!db.Write(it.first, it.second.get())) { + } else if (!db.Write(it.first, it.second.value())) { return false; } } @@ -331,7 +332,7 @@ class CFlushableStorageKV : public CStorageKV { template class CLazySerialize { - Optional value; + std::optional value; std::unique_ptr& it; public: @@ -482,10 +483,10 @@ class CStorageView { } // second type of 'ReadBy' (may be 'GetBy'?) template - boost::optional ReadBy(KeyType const & id) const { + std::optional ReadBy(KeyType const & id) const { ResultType result{}; if (ReadBy(id, result)) - return {result}; + return result; return {}; } template diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 126b2241b3..8ee95ceeee 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -47,28 +47,28 @@ class LockImpl : public Chain::Lock LockImpl(CCriticalSection& mutex) : m_mutex(mutex) { } - Optional getHeight() override + std::optional getHeight() override { LockAssertion lock(m_mutex); int height = ::ChainActive().Height(); if (height >= 0) { return height; } - return nullopt; + return std::nullopt; } - Optional getBlockHeight(const uint256& hash) override + std::optional getBlockHeight(const uint256& hash) override { LockAssertion lock(m_mutex); CBlockIndex* block = LookupBlockIndex(hash); if (block && ::ChainActive().Contains(block)) { return block->nHeight; } - return nullopt; + return std::nullopt; } int getBlockDepth(const uint256& hash) override { - const Optional tip_height = getHeight(); - const Optional height = getBlockHeight(hash); + const std::optional tip_height = getHeight(); + const std::optional height = getBlockHeight(hash); return tip_height && height ? *tip_height - *height + 1 : 0; } uint256 getBlockHash(int height) override @@ -98,7 +98,7 @@ class LockImpl : public Chain::Lock CBlockIndex* block = ::ChainActive()[height]; return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0; } - Optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override + std::optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override { LockAssertion lock(m_mutex); CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height); @@ -106,9 +106,9 @@ class LockImpl : public Chain::Lock if (hash) *hash = block->GetBlockHash(); return block->nHeight; } - return nullopt; + return std::nullopt; } - Optional findPruned(int start_height, Optional stop_height) override + std::optional findPruned(int start_height, std::optional stop_height) override { LockAssertion lock(m_mutex); if (::fPruneMode) { @@ -120,9 +120,9 @@ class LockImpl : public Chain::Lock block = block->pprev; } } - return nullopt; + return std::nullopt; } - Optional findFork(const uint256& hash, Optional* height) override + std::optional findFork(const uint256& hash, std::optional* height) override { LockAssertion lock(m_mutex); const CBlockIndex* block = LookupBlockIndex(hash); @@ -137,20 +137,20 @@ class LockImpl : public Chain::Lock if (fork) { return fork->nHeight; } - return nullopt; + return std::nullopt; } CBlockLocator getTipLocator() override { LockAssertion lock(m_mutex); return ::ChainActive().GetLocator(); } - Optional findLocatorFork(const CBlockLocator& locator) override + std::optional findLocatorFork(const CBlockLocator& locator) override { LockAssertion lock(m_mutex); if (CBlockIndex* fork = FindForkInGlobalIndex(::ChainActive(), locator)) { return fork->nHeight; } - return nullopt; + return std::nullopt; } bool checkFinalTx(const CTransaction& tx) override { @@ -280,12 +280,12 @@ class ChainImpl : public Chain return pcustomcsview->CanSpend(nodeId, height); } - boost::optional mnExists(const uint256 & nodeId) const override + std::optional mnExists(const uint256 & nodeId) const override { LOCK(cs_main); return pcustomcsview->GetMasternode(nodeId); } - boost::optional existTokenGuessId(const std::string & str, DCT_ID & id) const override + std::optional existTokenGuessId(const std::string & str, DCT_ID & id) const override { LOCK(cs_main); return pcustomcsview->GetTokenGuessId(str, id); diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 55a9b6f96b..143c35d2cc 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -5,11 +5,12 @@ #ifndef DEFI_INTERFACES_CHAIN_H #define DEFI_INTERFACES_CHAIN_H -#include // For Optional and nullopt #include // For CTransactionRef #include +#include #include +#include #include #include #include @@ -71,12 +72,12 @@ class 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; + 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 //! included in the current chain. - virtual Optional getBlockHeight(const uint256& hash) = 0; + virtual std::optional getBlockHeight(const uint256& hash) = 0; //! Get block depth. Returns 1 for chain tip, 2 for preceding block, and //! so on. Returns 0 for a block not included in the current chain. @@ -101,11 +102,11 @@ class Chain //! given height, or 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, uint256* hash) = 0; + virtual std::optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) = 0; //! Return height of last block in the specified range which is pruned, or //! nullopt if no block in the range is pruned. Range is inclusive. - virtual Optional findPruned(int start_height = 0, Optional stop_height = nullopt) = 0; + virtual std::optional findPruned(int start_height = 0, std::optional stop_height = std::nullopt) = 0; //! Return height of the specified block if it is on the chain, otherwise //! return the height of the highest block on chain that's an ancestor @@ -113,7 +114,7 @@ class Chain //! Also return the height of the specified block as an optional output //! parameter (to avoid the cost of a second hash lookup in case this //! information is desired). - virtual Optional findFork(const uint256& hash, Optional* height) = 0; + virtual std::optional findFork(const uint256& hash, std::optional* height) = 0; //! Get locator for the current chain tip. virtual CBlockLocator getTipLocator() = 0; @@ -121,7 +122,7 @@ class Chain //! 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 checkFinalTx(const CTransaction& tx) = 0; @@ -151,8 +152,8 @@ class Chain virtual void findCoins(std::map& coins) = 0; virtual bool mnCanSpend(const uint256 & nodeId, int height) const = 0; - virtual boost::optional mnExists(const uint256 & nodeId) const = 0; - virtual boost::optional existTokenGuessId(const std::string & str, DCT_ID & id) const = 0; + virtual std::optional mnExists(const uint256 & nodeId) const = 0; + virtual std::optional existTokenGuessId(const std::string & str, DCT_ID & id) const = 0; //! Estimate fraction of total transactions verified if blocks up to //! the specified block hash are verified. diff --git a/src/masternodes/accounts.cpp b/src/masternodes/accounts.cpp index bef8fe94d8..23459f803d 100644 --- a/src/masternodes/accounts.cpp +++ b/src/masternodes/accounts.cpp @@ -122,7 +122,7 @@ Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey& key) return Res::Ok(); } -boost::optional CAccountsView::GetMostRecentFuturesHeight() +std::optional CAccountsView::GetMostRecentFuturesHeight() { const CFuturesUserKey key{std::numeric_limits::max(), {}, std::numeric_limits::max()}; auto it = LowerBound(key); diff --git a/src/masternodes/accounts.h b/src/masternodes/accounts.h index b44c991a05..01f6445e3f 100644 --- a/src/masternodes/accounts.h +++ b/src/masternodes/accounts.h @@ -72,7 +72,7 @@ class CAccountsView : public virtual CStorageView Res StoreFuturesUserValues(const CFuturesUserKey& key, const CFuturesUserValue& futures); ResVal GetFuturesUserValues(const CFuturesUserKey& key); Res EraseFuturesUserValues(const CFuturesUserKey& key); - boost::optional GetMostRecentFuturesHeight(); + std::optional GetMostRecentFuturesHeight(); void ForEachFuturesUserValues(std::function callback, const CFuturesUserKey& start = {std::numeric_limits::max(), {}, std::numeric_limits::max()}); diff --git a/src/masternodes/accountshistory.cpp b/src/masternodes/accountshistory.cpp index f28c6f1929..85ee769769 100644 --- a/src/masternodes/accountshistory.cpp +++ b/src/masternodes/accountshistory.cpp @@ -19,7 +19,7 @@ Res CAccountsHistoryView::WriteAccountHistory(const AccountHistoryKey& key, cons return Res::Ok(); } -boost::optional CAccountsHistoryView::ReadAccountHistory(AccountHistoryKey const & key) const +std::optional CAccountsHistoryView::ReadAccountHistory(AccountHistoryKey const & key) const { return ReadBy(key); } diff --git a/src/masternodes/accountshistory.h b/src/masternodes/accountshistory.h index 55477dd51f..9cd1a2c501 100644 --- a/src/masternodes/accountshistory.h +++ b/src/masternodes/accountshistory.h @@ -60,7 +60,7 @@ class CAccountsHistoryView : public virtual CStorageView { public: Res WriteAccountHistory(AccountHistoryKey const & key, AccountHistoryValue const & value); - boost::optional ReadAccountHistory(AccountHistoryKey const & key) const; + std::optional ReadAccountHistory(AccountHistoryKey const & key) const; Res EraseAccountHistory(AccountHistoryKey const & key); void ForEachAccountHistory(std::function)> callback, AccountHistoryKey const & start = {}); diff --git a/src/masternodes/anchors.cpp b/src/masternodes/anchors.cpp index 6f873f65fa..bda583ea7d 100644 --- a/src/masternodes/anchors.cpp +++ b/src/masternodes/anchors.cpp @@ -914,7 +914,7 @@ uint256 CAnchorConfirmDataPlus::GetSignHash() const return Hash(ss.begin(), ss.end()); } -boost::optional CAnchorConfirmMessage::CreateSigned(const CAnchor& anchor, const THeight prevAnchorHeight, +std::optional CAnchorConfirmMessage::CreateSigned(const CAnchor& anchor, const THeight prevAnchorHeight, const uint256 &btcTxHash, CKey const & key, const THeight btcTxHeight) { // Potential post-fork unrewarded anchor diff --git a/src/masternodes/anchors.h b/src/masternodes/anchors.h index fca5381317..575e0a7bc2 100644 --- a/src/masternodes/anchors.h +++ b/src/masternodes/anchors.h @@ -403,7 +403,7 @@ class CAnchorConfirmMessage : public CAnchorConfirmDataPlus , signature() {} - static boost::optional CreateSigned(const CAnchor &anchor, const THeight prevAnchorHeight, + static std::optional CreateSigned(const CAnchor &anchor, const THeight prevAnchorHeight, const uint256 &btcTxHash, CKey const & key, const THeight btcTxHeight); uint256 GetHash() const; CKeyID GetSigner() const; diff --git a/src/masternodes/loan.cpp b/src/masternodes/loan.cpp index 05d9b9b236..e85db5515f 100644 --- a/src/masternodes/loan.cpp +++ b/src/masternodes/loan.cpp @@ -6,7 +6,7 @@ #include -boost::optional CLoanView::GetLoanCollateralToken(uint256 const & txid) const +std::optional CLoanView::GetLoanCollateralToken(uint256 const & txid) const { return ReadBy(txid); } @@ -43,7 +43,7 @@ void CLoanView::ForEachLoanCollateralToken(std::function(callback, start); } -boost::optional CLoanView::HasLoanCollateralToken(CollateralTokenKey const & key) +std::optional CLoanView::HasLoanCollateralToken(CollateralTokenKey const & key) { auto it = LowerBound(key); if (it.Valid() && it.Key().id == key.id) @@ -52,7 +52,7 @@ boost::optional CLoanView::HasLoanCollat return GetCollateralTokenFromAttributes(key.id); } -boost::optional CLoanView::GetLoanToken(uint256 const & txid) const +std::optional CLoanView::GetLoanToken(uint256 const & txid) const { auto id = ReadBy(txid); if (id) @@ -134,7 +134,7 @@ Res CLoanView::StoreDefaultLoanScheme(const std::string& loanSchemeID) return Res::Ok(); } -boost::optional CLoanView::GetDefaultLoanScheme() +std::optional CLoanView::GetDefaultLoanScheme() { std::string loanSchemeID; if (Read(DefaultLoanSchemeKey::prefix(), loanSchemeID)) { @@ -144,14 +144,16 @@ boost::optional CLoanView::GetDefaultLoanScheme() return {}; } -boost::optional CLoanView::GetLoanScheme(const std::string& loanSchemeID) +std::optional CLoanView::GetLoanScheme(const std::string& loanSchemeID) { return ReadBy(loanSchemeID); } -boost::optional CLoanView::GetDestroyLoanScheme(const std::string& loanSchemeID) +std::optional CLoanView::GetDestroyLoanScheme(const std::string& loanSchemeID) { - return ReadBy(loanSchemeID); + if (const auto res = ReadBy(loanSchemeID)) + return res; + return {}; } Res CLoanView::EraseLoanScheme(const std::string& loanSchemeID) @@ -184,7 +186,7 @@ void CLoanView::EraseDelayedDestroyScheme(const std::string& loanSchemeID) EraseBy(loanSchemeID); } -boost::optional CLoanView::GetInterestRate(const CVaultId& vaultId, DCT_ID id, uint32_t height) +std::optional CLoanView::GetInterestRate(const CVaultId& vaultId, DCT_ID id, uint32_t height) { if (height >= static_cast(Params().GetConsensus().FortCanningHillHeight)) return ReadBy(std::make_pair(vaultId, id)); @@ -451,7 +453,7 @@ Res CLoanView::SubLoanToken(const CVaultId& vaultId, CTokenAmount amount) return Res::Ok(); } -boost::optional CLoanView::GetLoanTokens(const CVaultId& vaultId) +std::optional CLoanView::GetLoanTokens(const CVaultId& vaultId) { return ReadBy(vaultId); } @@ -476,7 +478,7 @@ CAmount CLoanView::GetLoanLiquidationPenalty() return 5 * COIN / 100; } -boost::optional GetInterestPerBlockHighPrecisionString(const base_uint<128>& value) { +std::optional GetInterestPerBlockHighPrecisionString(const base_uint<128>& value) { struct HighPrecisionInterestValue { typedef boost::multiprecision::int128_t int128; typedef int64_t int64; @@ -504,7 +506,7 @@ boost::optional GetInterestPerBlockHighPrecisionString(const base_u return v == 0 ? value : value % (int128(HIGH_PRECISION_SCALER) * COIN); } - boost::optional GetInterestPerBlockString() const { + std::optional GetInterestPerBlockString() const { std::ostringstream result; auto mag = GetInterestPerBlockMagnitude(); auto dec = GetInterestPerBlockDecimal(); diff --git a/src/masternodes/loan.h b/src/masternodes/loan.h index 422c4b0ab3..ac3d39f301 100644 --- a/src/masternodes/loan.h +++ b/src/masternodes/loan.h @@ -266,7 +266,7 @@ CAmount TotalInterest(const CInterestRateV2& rate, uint32_t height); CAmount InterestPerBlock(const CInterestRateV2& rate, uint32_t height); base_uint<128> TotalInterestCalculation(const CInterestRateV2& rate, uint32_t height); CAmount CeilInterest(const base_uint<128>& value, uint32_t height); -boost::optional GetInterestPerBlockHighPrecisionString(const base_uint<128>& value); +std::optional GetInterestPerBlockHighPrecisionString(const base_uint<128>& value); base_uint<128> InterestPerBlockCalculationV2(CAmount amount, CAmount tokenInterest, CAmount schemeInterest); @@ -326,14 +326,14 @@ class CLoanView : public virtual CStorageView { using CLoanSetCollateralTokenImpl = CLoanSetCollateralTokenImplementation; using CLoanSetLoanTokenImpl = CLoanSetLoanTokenImplementation; - boost::optional GetLoanCollateralToken(uint256 const & txid) const; + std::optional GetLoanCollateralToken(uint256 const & txid) const; Res CreateLoanCollateralToken(CLoanSetCollateralTokenImpl const & collToken); Res EraseLoanCollateralToken(const CLoanSetCollateralTokenImpl& collToken); void ForEachLoanCollateralToken(std::function callback, CollateralTokenKey const & start = {DCT_ID{0}, UINT_MAX}); - boost::optional HasLoanCollateralToken(CollateralTokenKey const & key); + std::optional HasLoanCollateralToken(CollateralTokenKey const & key); - boost::optional GetLoanToken(uint256 const & txid) const; - [[nodiscard]] virtual boost::optional GetLoanTokenByID(DCT_ID const & id) const = 0; + std::optional GetLoanToken(uint256 const & txid) const; + [[nodiscard]] virtual std::optional GetLoanTokenByID(DCT_ID const & id) const = 0; Res SetLoanToken(CLoanSetLoanTokenImpl const & loanToken, DCT_ID const & id); Res UpdateLoanToken(CLoanSetLoanTokenImpl const & loanToken, DCT_ID const & id); Res EraseLoanToken(const DCT_ID& id); @@ -346,16 +346,16 @@ class CLoanView : public virtual CStorageView { Res EraseLoanScheme(const std::string& loanSchemeID); void EraseDelayedLoanScheme(const std::string& loanSchemeID, uint64_t height); void EraseDelayedDestroyScheme(const std::string& loanSchemeID); - boost::optional GetDefaultLoanScheme(); - boost::optional GetLoanScheme(const std::string& loanSchemeID); - boost::optional GetDestroyLoanScheme(const std::string& loanSchemeID); + std::optional GetDefaultLoanScheme(); + std::optional GetLoanScheme(const std::string& loanSchemeID); + std::optional GetDestroyLoanScheme(const std::string& loanSchemeID); void ForEachLoanScheme(std::function callback); void ForEachDelayedLoanScheme(std::function&, const CLoanSchemeMessage&)> callback); void ForEachDelayedDestroyScheme(std::function callback); Res DeleteInterest(const CVaultId& vaultId, uint32_t height); void EraseInterestDirect(const CVaultId& vaultId, DCT_ID id); - boost::optional GetInterestRate(const CVaultId& loanSchemeID, DCT_ID id, uint32_t height); + std::optional GetInterestRate(const CVaultId& loanSchemeID, DCT_ID id, uint32_t height); void WriteInterestRate(const std::pair& pair, const CInterestRateV2& rate, uint32_t height); Res StoreInterest(uint32_t height, const CVaultId& vaultId, const std::string& loanSchemeID, DCT_ID id, CAmount loanIncreased); Res EraseInterest(uint32_t height, const CVaultId& vaultId, const std::string& loanSchemeID, DCT_ID id, CAmount loanDecreased, CAmount interestDecreased); @@ -366,14 +366,14 @@ class CLoanView : public virtual CStorageView { Res AddLoanToken(const CVaultId& vaultId, CTokenAmount amount); Res SubLoanToken(const CVaultId& vaultId, CTokenAmount amount); - boost::optional GetLoanTokens(const CVaultId& vaultId); + std::optional GetLoanTokens(const CVaultId& vaultId); void ForEachLoanTokenAmount(std::function callback); Res SetLoanLiquidationPenalty(CAmount penalty); CAmount GetLoanLiquidationPenalty(); - [[nodiscard]] virtual boost::optional GetLoanTokenFromAttributes(const DCT_ID& id) const = 0; - [[nodiscard]] virtual boost::optional GetCollateralTokenFromAttributes(const DCT_ID& id) const = 0; + [[nodiscard]] virtual std::optional GetLoanTokenFromAttributes(const DCT_ID& id) const = 0; + [[nodiscard]] virtual std::optional GetCollateralTokenFromAttributes(const DCT_ID& id) const = 0; struct LoanSetCollateralTokenCreationTx { static constexpr uint8_t prefix() { return 0x10; } }; struct LoanSetCollateralTokenKey { static constexpr uint8_t prefix() { return 0x11; } }; diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index 05a88fd2d9..6c6c13e895 100644 --- a/src/masternodes/masternodes.cpp +++ b/src/masternodes/masternodes.cpp @@ -186,17 +186,17 @@ bool operator!=(CMasternode const & a, CMasternode const & b) /* * CMasternodesView */ -boost::optional CMasternodesView::GetMasternode(const uint256 & id) const +std::optional CMasternodesView::GetMasternode(const uint256 & id) const { return ReadBy(id); } -boost::optional CMasternodesView::GetMasternodeIdByOperator(const CKeyID & id) const +std::optional CMasternodesView::GetMasternodeIdByOperator(const CKeyID & id) const { return ReadBy(id); } -boost::optional CMasternodesView::GetMasternodeIdByOwner(const CKeyID & id) const +std::optional CMasternodesView::GetMasternodeIdByOwner(const CKeyID & id) const { return ReadBy(id); } @@ -222,7 +222,7 @@ void CMasternodesView::DecrementMintedBy(const uint256& nodeId) WriteBy(nodeId, *node); } -boost::optional > CMasternodesView::AmIOperator() const +std::optional > CMasternodesView::AmIOperator() const { auto const operators = gArgs.GetArgs("-masternode_operator"); for(auto const & key : operators) { @@ -256,7 +256,7 @@ std::set> CMasternodesView::GetOperatorsMulti() const return operatorPairs; } -boost::optional > CMasternodesView::AmIOwner() const +std::optional > CMasternodesView::AmIOwner() const { CTxDestination dest = DecodeDestination(gArgs.GetArg("-masternode_owner", "")); CKeyID const authAddress = dest.which() == PKHashType ? CKeyID(*boost::get(&dest)) : (dest.which() == WitV0KeyHashType ? CKeyID(*boost::get(&dest)) : CKeyID()); @@ -407,7 +407,7 @@ void CMasternodesView::SetMasternodeLastBlockTime(const CKeyID & minter, const u WriteBy(MNBlockTimeKey{*nodeId, blockHeight}, time); } -boost::optional CMasternodesView::GetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t height) +std::optional CMasternodesView::GetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t height) { auto nodeId = GetMasternodeIdByOperator(minter); assert(nodeId); @@ -549,7 +549,7 @@ uint16_t CMasternodesView::GetTimelock(const uint256& nodeId, const CMasternode& std::vector CMasternodesView::GetBlockTimes(const CKeyID& keyID, const uint32_t blockHeight, const int32_t creationHeight, const uint16_t timelock) { // Get last block time for non-subnode staking - boost::optional stakerBlockTime = GetMasternodeLastBlockTime(keyID, blockHeight); + std::optional stakerBlockTime = GetMasternodeLastBlockTime(keyID, blockHeight); // Get times for sub nodes, defaults to {0, 0, 0, 0} for MNs created before EunosPayaHeight std::vector subNodesBlockTime = GetSubNodesBlockTime(keyID, blockHeight); @@ -654,14 +654,14 @@ void CTeamView::SetAnchorTeams(const CTeam& authTeam, const CTeam& confirmTeam, } } -boost::optional CTeamView::GetAuthTeam(int height) const +std::optional CTeamView::GetAuthTeam(int height) const { height -= height % Params().GetConsensus().mn.anchoringTeamChange; return ReadBy(height); } -boost::optional CTeamView::GetConfirmTeam(int height) const +std::optional CTeamView::GetConfirmTeam(int height) const { height -= height % Params().GetConsensus().mn.anchoringTeamChange; @@ -671,7 +671,7 @@ boost::optional CTeamView::GetConfirmTeam(int height) const /* * CAnchorRewardsView */ -boost::optional CAnchorRewardsView::GetRewardForAnchor(const CAnchorRewardsView::AnchorTxHash & btcTxHash) const +std::optional CAnchorRewardsView::GetRewardForAnchor(const CAnchorRewardsView::AnchorTxHash & btcTxHash) const { return ReadBy(btcTxHash); } @@ -1078,7 +1078,7 @@ bool CCustomCSView::AreTokensLocked(const std::set& tokenIds) const return false; } -boost::optional CCustomCSView::GetTokenGuessId(const std::string & str, DCT_ID & id) const +std::optional CCustomCSView::GetTokenGuessId(const std::string & str, DCT_ID & id) const { std::string const key = trim_ws(str); @@ -1106,7 +1106,7 @@ boost::optional CCustomCSView::GetTokenGuessId(const st return {}; } -boost::optional CCustomCSView::GetLoanTokenByID(DCT_ID const & id) const +std::optional CCustomCSView::GetLoanTokenByID(DCT_ID const & id) const { auto loanToken = ReadBy(id); if (loanToken) { @@ -1147,7 +1147,7 @@ std::map AmISignerNow(int height, CAnchorData::CTeam const & team) return operatorDetails; } -boost::optional CCustomCSView::GetLoanTokenFromAttributes(const DCT_ID& id) const { +std::optional CCustomCSView::GetLoanTokenFromAttributes(const DCT_ID& id) const { if (const auto token = GetToken(id)) { if (const auto attributes = GetAttributes()) { CLoanView::CLoanSetLoanTokenImpl loanToken; @@ -1172,7 +1172,7 @@ boost::optional CCustomCSView::GetLoanTokenFro return {}; } -boost::optional CCustomCSView::GetCollateralTokenFromAttributes(const DCT_ID& id) const { +std::optional CCustomCSView::GetCollateralTokenFromAttributes(const DCT_ID& id) const { if (const auto attributes = GetAttributes()) { CLoanSetCollateralTokenImplementation collToken; diff --git a/src/masternodes/masternodes.h b/src/masternodes/masternodes.h index 0a80d00f2c..81bace5c3a 100644 --- a/src/masternodes/masternodes.h +++ b/src/masternodes/masternodes.h @@ -29,8 +29,6 @@ #include #include -#include - class CBlockIndex; class CTransaction; @@ -183,16 +181,16 @@ class CMasternodesView : public virtual CStorageView public: // CMasternodesView() = default; - boost::optional GetMasternode(uint256 const & id) const; - boost::optional GetMasternodeIdByOperator(CKeyID const & id) const; - boost::optional GetMasternodeIdByOwner(CKeyID const & id) const; + std::optional GetMasternode(uint256 const & id) const; + std::optional GetMasternodeIdByOperator(CKeyID const & id) const; + std::optional GetMasternodeIdByOwner(CKeyID const & id) const; void ForEachMasternode(std::function)> callback, uint256 const & start = uint256()); void IncrementMintedBy(const uint256& nodeId); void DecrementMintedBy(const uint256& nodeId); - boost::optional> AmIOperator() const; - boost::optional> AmIOwner() const; + std::optional> AmIOperator() const; + std::optional> AmIOwner() const; // Multiple operator support std::set> GetOperatorsMulti() const; @@ -210,7 +208,7 @@ class CMasternodesView : public virtual CStorageView // Non-subnode block times void SetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t &blockHeight, const int64_t &time); - boost::optional GetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t height); + std::optional GetMasternodeLastBlockTime(const CKeyID & minter, const uint32_t height); void EraseMasternodeLastBlockTime(const uint256 &minter, const uint32_t& blockHeight); void ForEachMinterNode(std::function)> callback, MNBlockTimeKey const & start = {}); @@ -262,8 +260,8 @@ class CTeamView : public virtual CStorageView void SetAnchorTeams(CTeam const & authTeam, CTeam const & confirmTeam, const int height); CTeam GetCurrentTeam() const; - boost::optional GetAuthTeam(int height) const; - boost::optional GetConfirmTeam(int height) const; + std::optional GetAuthTeam(int height) const; + std::optional GetConfirmTeam(int height) const; struct AuthTeam { static constexpr uint8_t prefix() { return 'v'; } }; struct ConfirmTeam { static constexpr uint8_t prefix() { return 'V'; } }; @@ -276,7 +274,7 @@ class CAnchorRewardsView : public virtual CStorageView using RewardTxHash = uint256; using AnchorTxHash = uint256; - boost::optional GetRewardForAnchor(AnchorTxHash const &btcTxHash) const; + std::optional GetRewardForAnchor(AnchorTxHash const &btcTxHash) const; void AddRewardForAnchor(AnchorTxHash const &btcTxHash, RewardTxHash const & rewardTxHash); void RemoveRewardForAnchor(AnchorTxHash const &btcTxHash); @@ -433,10 +431,10 @@ class CCustomCSView ResVal GetValidatedIntervalPrice(const CTokenCurrencyPair& priceFeedId, bool useNextPrice, bool requireLivePrice); [[nodiscard]] bool AreTokensLocked(const std::set& tokenIds) const override; - [[nodiscard]] boost::optional GetTokenGuessId(const std::string & str, DCT_ID & id) const override; - [[nodiscard]] boost::optional GetLoanTokenByID(DCT_ID const & id) const override; - [[nodiscard]] boost::optional GetLoanTokenFromAttributes(const DCT_ID& id) const override; - [[nodiscard]] boost::optional GetCollateralTokenFromAttributes(const DCT_ID& id) const override; + [[nodiscard]] std::optional GetTokenGuessId(const std::string & str, DCT_ID & id) const override; + [[nodiscard]] std::optional GetLoanTokenByID(DCT_ID const & id) const override; + [[nodiscard]] std::optional GetLoanTokenFromAttributes(const DCT_ID& id) const override; + [[nodiscard]] std::optional GetCollateralTokenFromAttributes(const DCT_ID& id) const override; void SetDbVersion(int version); diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index 6d063b3fe5..056d4e7067 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -1305,7 +1305,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor return Res::Err("tx must have at least one input from account owner"); } - CPoolPair& pool = pair.get(); + CPoolPair& pool = pair.value(); // subtract liq.balance BEFORE RemoveLiquidity call to check balance correctness { @@ -2968,7 +2968,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor { if (auto collaterals = mnview.GetVaultCollaterals(obj.vaultId)) { - boost::optional>> tokenDUSD; + std::optional>> tokenDUSD; if (static_cast(height) >= consensus.FortCanningRoadHeight) { tokenDUSD = mnview.GetToken("DUSD"); } @@ -3086,7 +3086,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor return res; } - boost::optional>> tokenDUSD; + std::optional>> tokenDUSD; if (static_cast(height) >= consensus.FortCanningRoadHeight) { tokenDUSD = mnview.GetToken("DUSD"); } @@ -4236,7 +4236,7 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView& view, std::vector poolIDs, boo // Single swap if no pool IDs provided auto poolPrice = POOLPRICE_MAX; - boost::optional > poolPair; + std::optional > poolPair; if (poolIDs.empty()) { poolPair = view.GetPoolPair(obj.idTokenFrom, obj.idTokenTo); if (!poolPair) { @@ -4266,7 +4266,7 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView& view, std::vector poolIDs, boo currentID = poolIDs[i]; // Use single swap pool if already found - boost::optional pool; + std::optional pool; if (poolPair) { pool = poolPair->second; } diff --git a/src/masternodes/mn_checks.h b/src/masternodes/mn_checks.h index 0163c56213..a47b702d27 100644 --- a/src/masternodes/mn_checks.h +++ b/src/masternodes/mn_checks.h @@ -450,7 +450,7 @@ inline bool IsMintTokenTx(const CTransaction& tx) return GuessCustomTxType(tx, metadata) == CustomTxType::MintToken; } -inline boost::optional> GetAccountToUtxosMetadata(const CTransaction & tx) +inline std::optional> GetAccountToUtxosMetadata(const CTransaction & tx) { std::vector metadata; if (GuessCustomTxType(tx, metadata) == CustomTxType::AccountToUtxos) { @@ -459,7 +459,7 @@ inline boost::optional> GetAccountToUtxosMetadata(con return {}; } -inline boost::optional GetAccountToUtxosMsg(const CTransaction & tx) +inline std::optional GetAccountToUtxosMsg(const CTransaction & tx) { const auto metadata = GetAccountToUtxosMetadata(tx); if (metadata) { diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index be8c5e2c6e..3a22d08459 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -273,7 +273,7 @@ static std::vector GetInputs(UniValue const& inputs) { return vin; } -boost::optional AmIFounder(CWallet* const pwallet) { +std::optional AmIFounder(CWallet* const pwallet) { for(auto const & script : Params().GetConsensus().foundationMembers) { if(IsMineCached(*pwallet, script) == ISMINE_SPENDABLE) return { script }; @@ -281,7 +281,7 @@ boost::optional AmIFounder(CWallet* const pwallet) { return {}; } -static boost::optional GetAuthInputOnly(CWalletCoinsUnlocker& pwallet, CTxDestination const& auth) { +static std::optional GetAuthInputOnly(CWalletCoinsUnlocker& pwallet, CTxDestination const& auth) { std::vector vecOutputs; CCoinControl cctl; @@ -347,7 +347,7 @@ static CTransactionRef CreateAuthTx(CWalletCoinsUnlocker& pwallet, std::set GetAnyFoundationAuthInput(CWalletCoinsUnlocker& pwallet) { +static std::optional GetAnyFoundationAuthInput(CWalletCoinsUnlocker& pwallet) { for (auto const & founderScript : Params().GetConsensus().foundationMembers) { if (IsMineCached(*pwallet, founderScript) == ISMINE_SPENDABLE) { CTxDestination destination; @@ -380,7 +380,7 @@ std::vector GetAuthInputsSmart(CWalletCoinsUnlocker& pwallet, int32_t txV } auto authInput = GetAuthInputOnly(pwallet, destination); if (authInput) { - result.push_back(authInput.get()); + result.push_back(authInput.value()); } else { notFoundYet.insert(auth); @@ -395,13 +395,13 @@ std::vector GetAuthInputsSmart(CWalletCoinsUnlocker& pwallet, int32_t txV throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Need foundation member authorization"); } } else { - auths.insert(anyFounder.get()); + auths.insert(anyFounder.value()); auto authInput = GetAnyFoundationAuthInput(pwallet); if (authInput) { - result.push_back(authInput.get()); + result.push_back(authInput.value()); } else { - notFoundYet.insert(anyFounder.get()); + notFoundYet.insert(anyFounder.value()); } } } diff --git a/src/masternodes/oracles.h b/src/masternodes/oracles.h index ef2572913a..b35950e93b 100644 --- a/src/masternodes/oracles.h +++ b/src/masternodes/oracles.h @@ -160,8 +160,8 @@ class COracleView : public virtual CStorageView uint32_t GetIntervalBlock() const; [[nodiscard]] virtual bool AreTokensLocked(const std::set& tokenIds) const = 0; - [[nodiscard]] virtual boost::optional GetTokenGuessId(const std::string & str, DCT_ID & id) const = 0; - [[nodiscard]] virtual boost::optional GetLoanTokenByID(DCT_ID const & id) const = 0; + [[nodiscard]] virtual std::optional GetTokenGuessId(const std::string & str, DCT_ID & id) const = 0; + [[nodiscard]] virtual std::optional GetLoanTokenByID(DCT_ID const & id) const = 0; struct ByName { static constexpr uint8_t prefix() { return 'O'; } }; struct PriceDeviation { static constexpr uint8_t prefix() { return 'Y'; } }; diff --git a/src/masternodes/poolpairs.cpp b/src/masternodes/poolpairs.cpp index d3145edc9f..1620a6d15d 100644 --- a/src/masternodes/poolpairs.cpp +++ b/src/masternodes/poolpairs.cpp @@ -123,7 +123,7 @@ Res CPoolPairView::UpdatePoolPair(DCT_ID const & poolId, uint32_t height, bool s return Res::Err("Pool with poolId %s does not exist", poolId.ToString()); } - CPoolPair & pool = poolPair.get(); + CPoolPair & pool = poolPair.value(); if (pool.status != status) { pool.status = status; @@ -157,7 +157,7 @@ Res CPoolPairView::UpdatePoolPair(DCT_ID const & poolId, uint32_t height, bool s return Res::Ok(); } -boost::optional CPoolPairView::GetPoolPair(const DCT_ID &poolId) const +std::optional CPoolPairView::GetPoolPair(const DCT_ID &poolId) const { auto pool = ReadBy(poolId); if (!pool) { @@ -184,7 +184,7 @@ boost::optional CPoolPairView::GetPoolPair(const DCT_ID &poolId) cons return pool; } -boost::optional > CPoolPairView::GetPoolPair(const DCT_ID &tokenA, const DCT_ID &tokenB) const +std::optional > CPoolPairView::GetPoolPair(const DCT_ID &tokenA, const DCT_ID &tokenB) const { DCT_ID poolId; ByPairKey key {tokenA, tokenB}; @@ -493,7 +493,7 @@ std::pair CPoolPairView::UpdatePoolRewards(std::function ownerAddress; + std::optional ownerAddress; PoolHeightKey poolKey = {poolId, uint32_t(nHeight)}; @@ -628,8 +628,10 @@ Res CPoolPairView::DelShare(DCT_ID const & poolId, CScript const & provider) { return Res::Ok(); } -boost::optional CPoolPairView::GetShare(DCT_ID const & poolId, CScript const & provider) { - return ReadBy(PoolShareKey{poolId, provider}); +std::optional CPoolPairView::GetShare(DCT_ID const & poolId, CScript const & provider) { + if (const auto res = ReadBy(PoolShareKey{poolId, provider})) + return res; + return {}; } inline CAmount PoolRewardPerBlock(CAmount dailyReward, CAmount rewardPct) { diff --git a/src/masternodes/poolpairs.h b/src/masternodes/poolpairs.h index e729743645..f413e5ef13 100644 --- a/src/masternodes/poolpairs.h +++ b/src/masternodes/poolpairs.h @@ -211,8 +211,8 @@ class CPoolPairView : public virtual CStorageView Res SetPoolPair(const DCT_ID &poolId, uint32_t height, CPoolPair const & pool); Res UpdatePoolPair(DCT_ID const & poolId, uint32_t height, bool status, CAmount const & commission, CScript const & ownerAddress, CBalances const & rewards); - boost::optional GetPoolPair(const DCT_ID &poolId) const; - boost::optional > GetPoolPair(DCT_ID const & tokenA, DCT_ID const & tokenB) const; + std::optional GetPoolPair(const DCT_ID &poolId) const; + std::optional > GetPoolPair(DCT_ID const & tokenA, DCT_ID const & tokenB) const; void ForEachPoolId(std::function callback, DCT_ID const & start = DCT_ID{0}); void ForEachPoolPair(std::function callback, DCT_ID const & start = DCT_ID{0}); @@ -221,7 +221,7 @@ class CPoolPairView : public virtual CStorageView Res SetShare(DCT_ID const & poolId, CScript const & provider, uint32_t height); Res DelShare(DCT_ID const & poolId, CScript const & provider); - boost::optional GetShare(DCT_ID const & poolId, CScript const & provider); + std::optional GetShare(DCT_ID const & poolId, CScript const & provider); void CalculatePoolRewards(DCT_ID const & poolId, std::function onLiquidity, uint32_t begin, uint32_t end, std::function onReward); diff --git a/src/masternodes/res.h b/src/masternodes/res.h index 8e1514155a..a1c1390816 100644 --- a/src/masternodes/res.h +++ b/src/masternodes/res.h @@ -3,7 +3,6 @@ #include #include -#include struct Res { @@ -47,7 +46,7 @@ struct Res template struct ResVal : public Res { - boost::optional val{}; + std::optional val{}; ResVal() = delete; diff --git a/src/masternodes/rpc_loan.cpp b/src/masternodes/rpc_loan.cpp index 4465fba022..0e9ca74bb2 100644 --- a/src/masternodes/rpc_loan.cpp +++ b/src/masternodes/rpc_loan.cpp @@ -427,8 +427,8 @@ UniValue updateloantoken(const JSONRPCRequest& request) { UniValue metaObj = request.params[1].get_obj(); UniValue const & txInputs = request.params[2]; - boost::optional loanToken; - boost::optional token; + std::optional loanToken; + std::optional token; int targetHeight; { diff --git a/src/masternodes/rpc_oracles.cpp b/src/masternodes/rpc_oracles.cpp index 4326d5faaf..b2e695dcdc 100644 --- a/src/masternodes/rpc_oracles.cpp +++ b/src/masternodes/rpc_oracles.cpp @@ -739,7 +739,7 @@ UniValue listlatestrawprices(const JSONRPCRequest &request) { RPCTypeCheck(request.params, {UniValue::VOBJ}, false); - boost::optional tokenPair; + std::optional tokenPair; // parse pagination COracleId start = {}; diff --git a/src/masternodes/tokens.cpp b/src/masternodes/tokens.cpp index bb927ffb57..c2616277f0 100644 --- a/src/masternodes/tokens.cpp +++ b/src/masternodes/tokens.cpp @@ -27,12 +27,12 @@ std::string trim_ws(std::string const & str) return str.substr(first, (last - first + 1)); } -boost::optional CTokensView::GetToken(DCT_ID id) const +std::optional CTokensView::GetToken(DCT_ID id) const { return ReadBy(id); } -boost::optional>> CTokensView::GetToken(const std::string & symbolKey) const +std::optional>> CTokensView::GetToken(const std::string & symbolKey) const { DCT_ID id; if (ReadBy(symbolKey, id)) { @@ -41,7 +41,7 @@ boost::optional>> CTo return {}; } -boost::optional > CTokensView::GetTokenByCreationTx(const uint256 & txid) const +std::optional > CTokensView::GetTokenByCreationTx(const uint256 & txid) const { DCT_ID id; if (ReadBy(txid, id)) { @@ -285,7 +285,7 @@ DCT_ID CTokensView::DecrementLastDctId() return *lastDctId; } -boost::optional CTokensView::ReadLastDctId() const +std::optional CTokensView::ReadLastDctId() const { DCT_ID lastDctId{DCT_ID_START}; if (Read(LastDctId::prefix(), lastDctId)) { diff --git a/src/masternodes/tokens.h b/src/masternodes/tokens.h index d75c53af74..b677fcb494 100644 --- a/src/masternodes/tokens.h +++ b/src/masternodes/tokens.h @@ -140,11 +140,11 @@ class CTokensView : public virtual CStorageView static const unsigned char DB_TOKEN_LASTID; // = 'L'; using CTokenImpl = CTokenImplementation; - boost::optional GetToken(DCT_ID id) const; - boost::optional>> GetToken(std::string const & symbol) const; + std::optional GetToken(DCT_ID id) const; + std::optional>> GetToken(std::string const & symbol) const; // the only possible type of token (with creationTx) is CTokenImpl - boost::optional> GetTokenByCreationTx(uint256 const & txid) const; - [[nodiscard]] virtual boost::optional GetTokenGuessId(const std::string & str, DCT_ID & id) const = 0; + std::optional> GetTokenByCreationTx(uint256 const & txid) const; + [[nodiscard]] virtual std::optional GetTokenGuessId(const std::string & str, DCT_ID & id) const = 0; void ForEachToken(std::function)> callback, DCT_ID const & start = DCT_ID{0}); @@ -167,7 +167,7 @@ class CTokensView : public virtual CStorageView // have to incapsulate "last token id" related methods here DCT_ID IncrementLastDctId(); DCT_ID DecrementLastDctId(); - boost::optional ReadLastDctId() const; + std::optional ReadLastDctId() const; }; #endif // DEFI_MASTERNODES_TOKENS_H diff --git a/src/masternodes/undos.cpp b/src/masternodes/undos.cpp index 08618aabc2..47bd1d9bfd 100644 --- a/src/masternodes/undos.cpp +++ b/src/masternodes/undos.cpp @@ -21,7 +21,7 @@ Res CUndosView::DelUndo(UndoKey const & key) return Res::Ok(); } -boost::optional CUndosView::GetUndo(UndoKey const & key) const +std::optional CUndosView::GetUndo(UndoKey const & key) const { CUndo val; bool ok = ReadBy(key, val); diff --git a/src/masternodes/undos.h b/src/masternodes/undos.h index 8788c5eddb..bf9ebe1f1c 100644 --- a/src/masternodes/undos.h +++ b/src/masternodes/undos.h @@ -13,7 +13,7 @@ class CUndosView : public virtual CStorageView { public: void ForEachUndo(std::function)> callback, UndoKey const & start = {}); - boost::optional GetUndo(UndoKey const & key) const; + std::optional GetUndo(UndoKey const & key) const; Res SetUndo(UndoKey const & key, CUndo const & undo); Res DelUndo(UndoKey const & key); diff --git a/src/masternodes/vault.cpp b/src/masternodes/vault.cpp index f5d86b052a..b305fc9f22 100644 --- a/src/masternodes/vault.cpp +++ b/src/masternodes/vault.cpp @@ -35,7 +35,7 @@ Res CVaultView::EraseVault(const CVaultId& vaultId) return Res::Ok(); } -boost::optional CVaultView::GetVault(const CVaultId& vaultId) const +std::optional CVaultView::GetVault(const CVaultId& vaultId) const { return ReadBy(vaultId); } @@ -94,7 +94,7 @@ Res CVaultView::SubVaultCollateral(const CVaultId& vaultId, CTokenAmount amount) return Res::Ok(); } -boost::optional CVaultView::GetVaultCollaterals(const CVaultId& vaultId) +std::optional CVaultView::GetVaultCollaterals(const CVaultId& vaultId) { return ReadBy(vaultId); } @@ -127,7 +127,7 @@ Res CVaultView::EraseAuction(const CVaultId& vaultId, uint32_t height) return Res::Err("Auction for vault <%s> not found", vaultId.GetHex()); } -boost::optional CVaultView::GetAuction(const CVaultId& vaultId, uint32_t height) +std::optional CVaultView::GetAuction(const CVaultId& vaultId, uint32_t height) { auto it = LowerBound(CAuctionKey{vaultId, height}); for (; it.Valid(); it.Next()) { @@ -152,7 +152,7 @@ Res CVaultView::EraseAuctionBatch(const AuctionStoreKey& key) return Res::Ok(); } -boost::optional CVaultView::GetAuctionBatch(const AuctionStoreKey& key) +std::optional CVaultView::GetAuctionBatch(const AuctionStoreKey& key) { return ReadBy(key); } @@ -182,7 +182,7 @@ Res CVaultView::EraseAuctionBid(const AuctionStoreKey& key) return Res::Ok(); } -boost::optional CVaultView::GetAuctionBid(const AuctionStoreKey& key) +std::optional CVaultView::GetAuctionBid(const AuctionStoreKey& key) { return ReadBy(key); } diff --git a/src/masternodes/vault.h b/src/masternodes/vault.h index bfb851fa27..9abd72412d 100644 --- a/src/masternodes/vault.h +++ b/src/masternodes/vault.h @@ -158,27 +158,27 @@ class CVaultView : public virtual CStorageView Res StoreVault(const CVaultId&, const CVaultData&); Res EraseVault(const CVaultId&); - boost::optional GetVault(const CVaultId&) const; + std::optional GetVault(const CVaultId&) const; Res UpdateVault(const CVaultId& vaultId, const CVaultMessage& newVault); void ForEachVault(std::function callback, const CVaultId& start = {}, const CScript& ownerAddress = {}); Res AddVaultCollateral(const CVaultId& vaultId, CTokenAmount amount); Res SubVaultCollateral(const CVaultId& vaultId, CTokenAmount amount); - boost::optional GetVaultCollaterals(const CVaultId& vaultId); + std::optional GetVaultCollaterals(const CVaultId& vaultId); void ForEachVaultCollateral(std::function callback); Res StoreAuction(const CVaultId& vaultId, const CAuctionData& data); Res EraseAuction(const CVaultId& vaultId, uint32_t height); - boost::optional GetAuction(const CVaultId& vaultId, uint32_t height); + std::optional GetAuction(const CVaultId& vaultId, uint32_t height); Res StoreAuctionBatch(const AuctionStoreKey& key, const CAuctionBatch& batch); Res EraseAuctionBatch(const AuctionStoreKey& key); - boost::optional GetAuctionBatch(const AuctionStoreKey& vaultId); + std::optional GetAuctionBatch(const AuctionStoreKey& vaultId); void ForEachVaultAuction(std::function callback, uint32_t height, const CVaultId& vaultId = {}); void ForEachAuctionBatch(std::function callback); Res StoreAuctionBid(const AuctionStoreKey& key, COwnerTokenAmount amount); Res EraseAuctionBid(const AuctionStoreKey& key); - boost::optional GetAuctionBid(const AuctionStoreKey& key); + std::optional GetAuctionBid(const AuctionStoreKey& key); void ForEachAuctionBid(std::function callback); struct VaultKey { static constexpr uint8_t prefix() { return 0x20; } }; diff --git a/src/miner.cpp b/src/miner.cpp index e54f86e08c..6234b04c4e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -93,9 +93,6 @@ void BlockAssembler::resetBlock() nFees = 0; } -Optional BlockAssembler::m_last_block_num_txs{nullopt}; -Optional BlockAssembler::m_last_block_weight{nullopt}; - std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, int64_t blockTime) { int64_t nTimeStart = GetTimeMicros(); @@ -118,7 +115,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc assert(pindexPrev != nullptr); nHeight = pindexPrev->nHeight + 1; // in fact, this may be redundant cause it was checked upthere in the miner - boost::optional> myIDs; + std::optional> myIDs; if (!blockTime) { myIDs = pcustomcsview->AmIOperator(); if (!myIDs) diff --git a/src/miner.h b/src/miner.h index b95ed88fc6..254a9a1018 100644 --- a/src/miner.h +++ b/src/miner.h @@ -6,7 +6,6 @@ #ifndef DEFI_MINER_H #define DEFI_MINER_H -#include #include #include #include @@ -14,6 +13,7 @@ #include #include +#include #include #include @@ -176,8 +176,8 @@ class BlockAssembler /** Construct a new block template with coinbase to scriptPubKeyIn */ std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn, int64_t blockTime = 0); - static Optional m_last_block_num_txs; - static Optional m_last_block_weight; + inline static std::optional m_last_block_num_txs{}; + inline static std::optional m_last_block_weight{}; private: // utility functions diff --git a/src/node/psbt.h b/src/node/psbt.h index 949ecdd283..5a8c44ff10 100644 --- a/src/node/psbt.h +++ b/src/node/psbt.h @@ -25,9 +25,9 @@ struct PSBTInputAnalysis { * Holds the results of AnalyzePSBT (miscellaneous information about a PSBT) */ struct PSBTAnalysis { - Optional estimated_vsize; //!< Estimated weight of the transaction - Optional estimated_feerate; //!< Estimated feerate (fee / weight) of the transaction - Optional fee; //!< Amount of fee being paid by the transaction + std::optional estimated_vsize; //!< Estimated weight of the transaction + std::optional estimated_feerate; //!< Estimated feerate (fee / weight) of the transaction + std::optional fee; //!< Amount of fee being paid by the transaction std::vector inputs; //!< More information about the individual inputs of the transaction PSBTRole next; //!< Which of the BIP 174 roles needs to handle the transaction next }; diff --git a/src/optional.h b/src/optional.h deleted file mode 100644 index e17dd01288..0000000000 --- a/src/optional.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2017 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file LICENSE or http://www.opensource.org/licenses/mit-license.php. - -#ifndef DEFI_OPTIONAL_H -#define DEFI_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 // DEFI_OPTIONAL_H diff --git a/src/pos.cpp b/src/pos.cpp index c432eceb92..81cd0a856e 100644 --- a/src/pos.cpp +++ b/src/pos.cpp @@ -183,7 +183,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, int64_t blockTim return pos::CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params.pos, newDifficultyAdjust); } -boost::optional SignPosBlock(std::shared_ptr pblock, const CKey &key) { +std::optional SignPosBlock(std::shared_ptr pblock, const CKey &key) { // if we are trying to sign a signed proof-of-stake block if (!pblock->sig.empty()) { throw std::logic_error{"Only non-complete PoS block templates are accepted"}; @@ -197,7 +197,7 @@ boost::optional SignPosBlock(std::shared_ptr pblock, const return {}; } -boost::optional CheckSignedBlock(const std::shared_ptr& pblock, const CBlockIndex* pindexPrev, const CChainParams& chainparams) { +std::optional CheckSignedBlock(const std::shared_ptr& pblock, const CBlockIndex* pindexPrev, const CChainParams& chainparams) { uint256 hashBlock = pblock->GetHash(); // verify hash target and signature of coinstake tx diff --git a/src/pos.h b/src/pos.h index 76c2f97b7a..1df8ad8b3d 100644 --- a/src/pos.h +++ b/src/pos.h @@ -6,8 +6,6 @@ #include #include -#include - class CBlock; class CBlockIndex; @@ -46,9 +44,9 @@ namespace pos { unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params::PoS& params, bool newDifficultyAdjust = false); - boost::optional SignPosBlock(std::shared_ptr pblock, const CKey &key); + std::optional SignPosBlock(std::shared_ptr pblock, const CKey &key); - boost::optional CheckSignedBlock(const std::shared_ptr& pblock, const CBlockIndex* pindexPrev, const CChainParams& chainparams); + std::optional CheckSignedBlock(const std::shared_ptr& pblock, const CBlockIndex* pindexPrev, const CChainParams& chainparams); } #endif // DEFI_POS_H diff --git a/src/primitives/block.h b/src/primitives/block.h index 8968ec636c..1342eb1617 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -11,8 +11,6 @@ #include #include -#include - /** Nodes collect new transactions into a block, hash them into a hash tree, * and scan through nonce values to make the block's hash satisfy proof-of-work * requirements. When they solve the proof-of-work, they broadcast the block diff --git a/src/psbt.cpp b/src/psbt.cpp index dde14dc1f7..46dcfda9d2 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -214,7 +214,12 @@ bool PSBTInputSigned(const PSBTInput& input) void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index) { - const CTxOut& out = psbt.tx->vout.at(index); + if (!psbt.tx) { + return; + } + + CMutableTransaction& tx = *psbt.tx; + const CTxOut& out = tx.vout.at(index); PSBTOutput& psbt_out = psbt.outputs.at(index); // Fill a SignatureData with output info @@ -224,7 +229,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, witness_script, key paths, into PSBTOutput. diff --git a/src/psbt.h b/src/psbt.h index 473719e513..f9fcf9d9c4 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -7,13 +7,14 @@ #include #include -#include #include #include #include #include