diff --git a/src/chain.h b/src/chain.h index 2458d9690..01204fdc8 100644 --- a/src/chain.h +++ b/src/chain.h @@ -229,7 +229,7 @@ public: //! Branch ID corresponding to the consensus rules used to validate this block. //! Only cached if block validity is BLOCK_VALID_CONSENSUS. //! Persisted at each activation height, memory-only for intervening blocks. - boost::optional nCachedBranchId; + std::optional nCachedBranchId; //! The anchor for the tree state up to the start of this block uint256 hashSproutAnchor; @@ -238,22 +238,22 @@ public: uint256 hashFinalSproutRoot; //! Change in value held by the Sprout circuit over this block. - //! Will be boost::none for older blocks on old nodes until a reindex has taken place. - boost::optional nSproutValue; + //! Will be std::nullopt for older blocks on old nodes until a reindex has taken place. + std::optional nSproutValue; //! (memory only) Total value held by the Sprout circuit up to and including this block. - //! Will be boost::none for on old nodes until a reindex has taken place. - //! Will be boost::none if nChainTx is zero. - boost::optional nChainSproutValue; + //! Will be std::nullopt for on old nodes until a reindex has taken place. + //! Will be std::nullopt if nChainTx is zero. + std::optional nChainSproutValue; //! Change in value held by the Sapling circuit over this block. - //! Not a boost::optional because this was added before Sapling activated, so we can + //! Not a std::optional because this was added before Sapling activated, so we can //! rely on the invariant that every block before this was added had nSaplingValue = 0. CAmount nSaplingValue; //! (memory only) Total value held by the Sapling circuit up to and including this block. - //! Will be boost::none if nChainTx is zero. - boost::optional nChainSaplingValue; + //! Will be std::nullopt if nChainTx is zero. + std::optional nChainSaplingValue; //! Root of the Sapling commitment tree as of the end of this block. //! @@ -296,14 +296,14 @@ public: nTx = 0; nChainTx = 0; nStatus = 0; - nCachedBranchId = boost::none; + nCachedBranchId = std::nullopt; hashSproutAnchor = uint256(); hashFinalSproutRoot = uint256(); nSequenceId = 0; - nSproutValue = boost::none; - nChainSproutValue = boost::none; + nSproutValue = std::nullopt; + nChainSproutValue = std::nullopt; nSaplingValue = 0; - nChainSaplingValue = boost::none; + nChainSaplingValue = std::nullopt; nVersion = 0; hashMerkleRoot = uint256(); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 774a3f064..4f4b81130 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -105,7 +105,7 @@ public: consensus.nPowMaxAdjustUp = 16; // 16% adjustment up consensus.nPreBlossomPowTargetSpacing = Consensus::PRE_BLOSSOM_POW_TARGET_SPACING; consensus.nPostBlossomPowTargetSpacing = Consensus::POST_BLOSSOM_POW_TARGET_SPACING; - consensus.nPowAllowMinDifficultyBlocksAfterHeight = boost::none; + consensus.nPowAllowMinDifficultyBlocksAfterHeight = std::nullopt; consensus.fPowNoRetargeting = false; consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = diff --git a/src/consensus/params.h b/src/consensus/params.h index 51e36c209..464ca0347 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -14,7 +14,6 @@ #include #include -#include namespace Consensus { @@ -81,7 +80,7 @@ struct NetworkUpgrade { * scrutiny than regular releases. nMinimumChainWork MUST be set to at least the chain * work of this block, otherwise this detection will have false positives. */ - boost::optional hashActivationBlock; + std::optional hashActivationBlock; }; typedef std::variant FundingStreamAddress; @@ -212,7 +211,7 @@ struct Params { NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]; int nFundingPeriodLength; - boost::optional vFundingStreams[MAX_FUNDING_STREAMS]; + std::optional vFundingStreams[MAX_FUNDING_STREAMS]; void AddZIP207FundingStream( const KeyConstants& keyConstants, FundingStreamIndex idx, @@ -264,7 +263,7 @@ struct Params { unsigned int nEquihashN = 0; unsigned int nEquihashK = 0; uint256 powLimit; - boost::optional nPowAllowMinDifficultyBlocksAfterHeight; + std::optional nPowAllowMinDifficultyBlocksAfterHeight; bool fPowNoRetargeting; int64_t nPowAveragingWindow; int64_t nPowMaxAdjustDown; diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 07003907b..29f8acce7 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -140,9 +140,9 @@ bool IsActivationHeightForAnyUpgrade( return false; } -boost::optional NextEpoch(int nHeight, const Consensus::Params& params) { +std::optional NextEpoch(int nHeight, const Consensus::Params& params) { if (nHeight < 0) { - return boost::none; + return std::nullopt; } // Sprout is never pending @@ -152,10 +152,10 @@ boost::optional NextEpoch(int nHeight, const Consensus::Params& params) { } } - return boost::none; + return std::nullopt; } -boost::optional NextActivationHeight( +std::optional NextActivationHeight( int nHeight, const Consensus::Params& params) { @@ -163,5 +163,5 @@ boost::optional NextActivationHeight( if (idx) { return params.vUpgrades[idx.value()].nActivationHeight; } - return boost::none; + return std::nullopt; } diff --git a/src/consensus/upgrades.h b/src/consensus/upgrades.h index b06d34542..812c0ad18 100644 --- a/src/consensus/upgrades.h +++ b/src/consensus/upgrades.h @@ -8,7 +8,6 @@ #include "consensus/params.h" #include -#include enum UpgradeState { UPGRADE_DISABLED, @@ -84,15 +83,15 @@ bool IsActivationHeightForAnyUpgrade( /** * Returns the index of the next upgrade after the given block height, or - * boost::none if there are no more known upgrades. + * std::nullopt if there are no more known upgrades. */ -boost::optional NextEpoch(int nHeight, const Consensus::Params& params); +std::optional NextEpoch(int nHeight, const Consensus::Params& params); /** * Returns the activation height for the next upgrade after the given block height, - * or boost::none if there are no more known upgrades. + * or std::nullopt if there are no more known upgrades. */ -boost::optional NextActivationHeight( +std::optional NextActivationHeight( int nHeight, const Consensus::Params& params); diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index ffe293b2d..ad64a37fc 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -151,7 +151,6 @@ std::vector GetMinimalFromIndices(std::vector indices, #include #include -#include static EhSolverCancelledException solver_cancelled; @@ -648,7 +647,7 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, size_t hashLen; size_t lenIndices; unsigned char tmpHash[HashOutput]; - std::vector>>> X; + std::vector>>> X; X.reserve(K+1); // 3) Repeat steps 1 and 2 for each partial index @@ -666,7 +665,7 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, N/8, HashLength, CollisionBitLength, newIndex); if (cancelled(PartialGeneration)) throw solver_cancelled; } - boost::optional>> ic = icv; + std::optional>> ic = icv; // 2a) For each pair of lists: hashLen = HashLength; @@ -691,7 +690,7 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, if (ic->size() == 0) goto invalidsolution; - X[r] = boost::none; + X[r] = std::nullopt; hashLen -= CollisionByteLength; lenIndices *= 2; rti = lti; diff --git a/src/experimental_features.cpp b/src/experimental_features.cpp index 93a4fd2ed..67afbf7fc 100644 --- a/src/experimental_features.cpp +++ b/src/experimental_features.cpp @@ -12,7 +12,7 @@ bool fExperimentalPaymentDisclosure = false; bool fExperimentalInsightExplorer = false; bool fExperimentalLightWalletd = false; -boost::optional InitExperimentalMode() +std::optional InitExperimentalMode() { auto fExperimentalMode = GetBoolArg("-experimentalfeatures", false); fExperimentalDeveloperEncryptWallet = GetBoolArg("-developerencryptwallet", false); @@ -35,7 +35,7 @@ boost::optional InitExperimentalMode() return _("Light Walletd requires -experimentalfeatures."); } } - return boost::none; + return std::nullopt; } std::vector GetExperimentalFeatures() diff --git a/src/experimental_features.h b/src/experimental_features.h index 48d916492..d607f1d53 100644 --- a/src/experimental_features.h +++ b/src/experimental_features.h @@ -8,7 +8,6 @@ #include #include #include -#include extern bool fExperimentalDeveloperEncryptWallet; extern bool fExperimentalDeveloperSetPoolSizeZero; @@ -16,7 +15,7 @@ extern bool fExperimentalPaymentDisclosure; extern bool fExperimentalInsightExplorer; extern bool fExperimentalLightWalletd; -boost::optional InitExperimentalMode(); +std::optional InitExperimentalMode(); std::vector GetExperimentalFeatures(); #endif // ZCASH_EXPERIMENTAL_FEATURES_H diff --git a/src/gtest/test_mempoollimit.cpp b/src/gtest/test_mempoollimit.cpp index 5d9d01739..8869b27d7 100644 --- a/src/gtest/test_mempoollimit.cpp +++ b/src/gtest/test_mempoollimit.cpp @@ -94,12 +94,12 @@ TEST(MempoolLimitTests, WeightedTxTreeCheckSizeAfterDropping) tree.add(WeightedTxInfo(TX_ID2, TxWeight(MIN_TX_COST, MIN_TX_COST))); EXPECT_EQ(8000, tree.getTotalWeight().cost); EXPECT_EQ(8000, tree.getTotalWeight().evictionWeight); - EXPECT_FALSE(tree.maybeDropRandom().is_initialized()); + EXPECT_FALSE(tree.maybeDropRandom().has_value()); tree.add(WeightedTxInfo(TX_ID3, TxWeight(MIN_TX_COST, MIN_TX_COST + LOW_FEE_PENALTY))); EXPECT_EQ(12000, tree.getTotalWeight().cost); EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight); - boost::optional drop = tree.maybeDropRandom(); - ASSERT_TRUE(drop.is_initialized()); + std::optional drop = tree.maybeDropRandom(); + ASSERT_TRUE(drop.has_value()); uint256 txid = drop.value(); testedDropping.insert(txid); // Do not continue to test if a particular trial fails diff --git a/src/gtest/test_noteencryption.cpp b/src/gtest/test_noteencryption.cpp index d59afd485..640dd64d6 100644 --- a/src/gtest/test_noteencryption.cpp +++ b/src/gtest/test_noteencryption.cpp @@ -443,7 +443,7 @@ TEST(NoteEncryption, SaplingApi) librustzcash_sapling_generate_r(esk.begin()); // Invalid diversifier - ASSERT_EQ(boost::none, SaplingNoteEncryption::FromDiversifier({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, esk)); + ASSERT_EQ(std::nullopt, SaplingNoteEncryption::FromDiversifier({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, esk)); // Encrypt to pk_1 auto enc = *SaplingNoteEncryption::FromDiversifier(pk_1.d, esk); diff --git a/src/gtest/test_upgrades.cpp b/src/gtest/test_upgrades.cpp index 71a0e3256..d7ff0d791 100644 --- a/src/gtest/test_upgrades.cpp +++ b/src/gtest/test_upgrades.cpp @@ -4,7 +4,6 @@ #include "consensus/upgrades.h" #include -#include class UpgradesTest : public ::testing::Test { protected: @@ -149,28 +148,28 @@ TEST_F(UpgradesTest, NextEpoch) { const Consensus::Params& params = Params().GetConsensus(); // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT - EXPECT_EQ(NextEpoch(-1, params), boost::none); - EXPECT_EQ(NextEpoch(0, params), boost::none); - EXPECT_EQ(NextEpoch(1, params), boost::none); - EXPECT_EQ(NextEpoch(1000000, params), boost::none); + EXPECT_EQ(NextEpoch(-1, params), std::nullopt); + EXPECT_EQ(NextEpoch(0, params), std::nullopt); + EXPECT_EQ(NextEpoch(1, params), std::nullopt); + EXPECT_EQ(NextEpoch(1000000, params), std::nullopt); UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE); - EXPECT_EQ(NextEpoch(-1, params), boost::none); - EXPECT_EQ(NextEpoch(0, params), boost::none); - EXPECT_EQ(NextEpoch(1, params), boost::none); - EXPECT_EQ(NextEpoch(1000000, params), boost::none); + EXPECT_EQ(NextEpoch(-1, params), std::nullopt); + EXPECT_EQ(NextEpoch(0, params), std::nullopt); + EXPECT_EQ(NextEpoch(1, params), std::nullopt); + EXPECT_EQ(NextEpoch(1000000, params), std::nullopt); int nActivationHeight = 100; UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight); - EXPECT_EQ(NextEpoch(-1, params), boost::none); + EXPECT_EQ(NextEpoch(-1, params), std::nullopt); EXPECT_EQ(NextEpoch(0, params), static_cast(Consensus::UPGRADE_TESTDUMMY)); EXPECT_EQ(NextEpoch(1, params), static_cast(Consensus::UPGRADE_TESTDUMMY)); EXPECT_EQ(NextEpoch(nActivationHeight - 1, params), static_cast(Consensus::UPGRADE_TESTDUMMY)); - EXPECT_EQ(NextEpoch(nActivationHeight, params), boost::none); - EXPECT_EQ(NextEpoch(nActivationHeight + 1, params), boost::none); - EXPECT_EQ(NextEpoch(1000000, params), boost::none); + EXPECT_EQ(NextEpoch(nActivationHeight, params), std::nullopt); + EXPECT_EQ(NextEpoch(nActivationHeight + 1, params), std::nullopt); + EXPECT_EQ(NextEpoch(1000000, params), std::nullopt); } TEST_F(UpgradesTest, NextActivationHeight) { @@ -178,26 +177,26 @@ TEST_F(UpgradesTest, NextActivationHeight) { const Consensus::Params& params = Params().GetConsensus(); // Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT - EXPECT_EQ(NextActivationHeight(-1, params), boost::none); - EXPECT_EQ(NextActivationHeight(0, params), boost::none); - EXPECT_EQ(NextActivationHeight(1, params), boost::none); - EXPECT_EQ(NextActivationHeight(1000000, params), boost::none); + EXPECT_EQ(NextActivationHeight(-1, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(0, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(1, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(1000000, params), std::nullopt); UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, Consensus::NetworkUpgrade::ALWAYS_ACTIVE); - EXPECT_EQ(NextActivationHeight(-1, params), boost::none); - EXPECT_EQ(NextActivationHeight(0, params), boost::none); - EXPECT_EQ(NextActivationHeight(1, params), boost::none); - EXPECT_EQ(NextActivationHeight(1000000, params), boost::none); + EXPECT_EQ(NextActivationHeight(-1, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(0, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(1, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(1000000, params), std::nullopt); int nActivationHeight = 100; UpdateNetworkUpgradeParameters(Consensus::UPGRADE_TESTDUMMY, nActivationHeight); - EXPECT_EQ(NextActivationHeight(-1, params), boost::none); + EXPECT_EQ(NextActivationHeight(-1, params), std::nullopt); EXPECT_EQ(NextActivationHeight(0, params), nActivationHeight); EXPECT_EQ(NextActivationHeight(1, params), nActivationHeight); EXPECT_EQ(NextActivationHeight(nActivationHeight - 1, params), nActivationHeight); - EXPECT_EQ(NextActivationHeight(nActivationHeight, params), boost::none); - EXPECT_EQ(NextActivationHeight(nActivationHeight + 1, params), boost::none); - EXPECT_EQ(NextActivationHeight(1000000, params), boost::none); + EXPECT_EQ(NextActivationHeight(nActivationHeight, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(nActivationHeight + 1, params), std::nullopt); + EXPECT_EQ(NextActivationHeight(1000000, params), std::nullopt); } diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp index 4d195f2ce..0710ae30d 100644 --- a/src/gtest/test_validation.cpp +++ b/src/gtest/test_validation.cpp @@ -16,7 +16,7 @@ extern bool ReceivedBlockTransactions( CBlockIndex *pindexNew, const CDiskBlockPos& pos); -void ExpectOptionalAmount(CAmount expected, boost::optional actual) { +void ExpectOptionalAmount(CAmount expected, std::optional actual) { EXPECT_TRUE((bool)actual); if (actual) { EXPECT_EQ(expected, *actual); @@ -26,7 +26,7 @@ void ExpectOptionalAmount(CAmount expected, boost::optional actual) { // Fake a view that optionally contains a single coin. class ValidationFakeCoinsViewDB : public CCoinsView { public: - boost::optional, std::pair>> coin; + std::optional, std::pair>> coin; ValidationFakeCoinsViewDB() {} ValidationFakeCoinsViewDB(uint256 blockHash, uint256 txid, CTxOut txOut, int nHeight) : diff --git a/src/main.cpp b/src/main.cpp index 137256d46..67326de8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,7 +86,7 @@ uint64_t nPruneTarget = 0; bool fAlerts = DEFAULT_ALERTS; int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE; -boost::optional expiryDeltaArg = boost::none; +std::optional expiryDeltaArg = std::nullopt; CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE; @@ -2793,7 +2793,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // Sapling // // If we've reached ConnectBlock, we have all transactions of - // parents and can expect nChainSaplingValue not to be boost::none. + // parents and can expect nChainSaplingValue not to be std::nullopt. // However, the miner and mining RPCs may not have populated this // value and will call `TestBlockValidity`. So, we act // conditionally. @@ -3853,7 +3853,7 @@ void FallbackSproutValuePoolBalance( assert(*pindex->nChainSproutValue == chainparams.SproutValuePoolCheckpointBalance()); // And we should expect non-none for the delta stored in the block index here, // or the checkpoint is too early. - assert(pindex->nSproutValue != boost::none); + assert(pindex->nSproutValue != std::nullopt); } } else { LogPrintf( @@ -3889,9 +3889,9 @@ bool ReceivedBlockTransactions( } } pindexNew->nSproutValue = sproutValue; - pindexNew->nChainSproutValue = boost::none; + pindexNew->nChainSproutValue = std::nullopt; pindexNew->nSaplingValue = saplingValue; - pindexNew->nChainSaplingValue = boost::none; + pindexNew->nChainSaplingValue = std::nullopt; pindexNew->nFile = pos.nFile; pindexNew->nDataPos = pos.nPos; pindexNew->nUndoPos = 0; @@ -3913,12 +3913,12 @@ bool ReceivedBlockTransactions( if (pindex->pprev->nChainSproutValue && pindex->nSproutValue) { pindex->nChainSproutValue = *pindex->pprev->nChainSproutValue + *pindex->nSproutValue; } else { - pindex->nChainSproutValue = boost::none; + pindex->nChainSproutValue = std::nullopt; } if (pindex->pprev->nChainSaplingValue) { pindex->nChainSaplingValue = *pindex->pprev->nChainSaplingValue + pindex->nSaplingValue; } else { - pindex->nChainSaplingValue = boost::none; + pindex->nChainSaplingValue = std::nullopt; } } else { pindex->nChainSproutValue = pindex->nSproutValue; @@ -4659,17 +4659,17 @@ bool static LoadBlockIndexDB() if (pindex->pprev->nChainSproutValue && pindex->nSproutValue) { pindex->nChainSproutValue = *pindex->pprev->nChainSproutValue + *pindex->nSproutValue; } else { - pindex->nChainSproutValue = boost::none; + pindex->nChainSproutValue = std::nullopt; } if (pindex->pprev->nChainSaplingValue) { pindex->nChainSaplingValue = *pindex->pprev->nChainSaplingValue + pindex->nSaplingValue; } else { - pindex->nChainSaplingValue = boost::none; + pindex->nChainSaplingValue = std::nullopt; } } else { pindex->nChainTx = 0; - pindex->nChainSproutValue = boost::none; - pindex->nChainSaplingValue = boost::none; + pindex->nChainSproutValue = std::nullopt; + pindex->nChainSaplingValue = std::nullopt; mapBlocksUnlinked.insert(std::make_pair(pindex->pprev, pindex)); } } else { diff --git a/src/main.h b/src/main.h index a4b176905..b04354967 100644 --- a/src/main.h +++ b/src/main.h @@ -134,7 +134,7 @@ struct BlockHasher size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); } }; -extern boost::optional expiryDeltaArg; +extern std::optional expiryDeltaArg; extern CScript COINBASE_FLAGS; extern CCriticalSection cs_main; extern CTxMemPool mempool; diff --git a/src/mempool_limit.cpp b/src/mempool_limit.cpp index efa15a8c5..78c6e7320 100644 --- a/src/mempool_limit.cpp +++ b/src/mempool_limit.cpp @@ -118,11 +118,11 @@ void WeightedTxTree::remove(const uint256& txId) childWeights.pop_back(); } -boost::optional WeightedTxTree::maybeDropRandom() +std::optional WeightedTxTree::maybeDropRandom() { TxWeight totalTxWeight = getTotalWeight(); if (totalTxWeight.cost <= capacity) { - return boost::none; + return std::nullopt; } LogPrint("mempool", "Mempool cost limit exceeded (cost=%d, limit=%d)\n", totalTxWeight.cost, capacity); int randomWeight = GetRand(totalTxWeight.evictionWeight); diff --git a/src/mempool_limit.h b/src/mempool_limit.h index c00f94384..9d8ef3f44 100644 --- a/src/mempool_limit.h +++ b/src/mempool_limit.h @@ -10,7 +10,6 @@ #include #include -#include "boost/optional.hpp" #include "primitives/transaction.h" #include "uint256.h" @@ -123,7 +122,7 @@ public: // If the total cost limit is exceeded, pick a random number based on the total cost // of the collection and remove the associated transaction. - boost::optional maybeDropRandom(); + std::optional maybeDropRandom(); }; diff --git a/src/metrics.cpp b/src/metrics.cpp index 68fff8122..c921da15e 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -14,7 +14,6 @@ #include "utilmoneystr.h" #include "utilstrencodings.h" -#include #include #include #include @@ -277,13 +276,13 @@ std::string DisplayHashRate(double value) return strprintf(_("%.3f TSol/s"), value / coef); } -boost::optional SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight) +std::optional SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight) { auto nextHeight = NextActivationHeight(currentHeight, params); if (nextHeight) { return (nextHeight.value() - currentHeight) * params.PoWTargetSpacing(nextHeight.value() - 1); } else { - return boost::none; + return std::nullopt; } } @@ -643,7 +642,7 @@ void ThreadShowMetricsScreen() } // Lock and fetch stats before erasing the screen, in case we block. - boost::optional metricsStats; + std::optional metricsStats; if (loaded) { metricsStats = loadStats(); } diff --git a/src/metrics.h b/src/metrics.h index a3f2f67d0..e20473287 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -76,7 +76,7 @@ void TrackMinedBlock(uint256 hash); void MarkStartTime(); double GetLocalSolPS(); int EstimateNetHeight(const Consensus::Params& params, int currentBlockHeight, int64_t currentBlockTime); -boost::optional SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight); +std::optional SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight); std::string DisplayDuration(int64_t time, DurationFormat format); std::string DisplaySize(size_t value); std::string DisplayHashRate(double value); diff --git a/src/miner.cpp b/src/miner.cpp index fbfa3fe3c..9465352bb 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -111,7 +111,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, pblock->nTime = nTime; // Updating time can change work required on testnet: - if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) { + if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != std::nullopt) { pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } } @@ -931,7 +931,7 @@ void static BitcoinMiner(const CChainParams& chainparams) // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - if (chainparams.GetConsensus().nPowAllowMinDifficultyBlocksAfterHeight != boost::none) + if (chainparams.GetConsensus().nPowAllowMinDifficultyBlocksAfterHeight != std::nullopt) { // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); diff --git a/src/miner.h b/src/miner.h index d9c4947b2..9f3eacecf 100644 --- a/src/miner.h +++ b/src/miner.h @@ -8,7 +8,6 @@ #include "primitives/block.h" -#include #include #include #include diff --git a/src/pow.cpp b/src/pow.cpp index 181e9d710..28b8f2bf4 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -30,7 +30,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { // Comparing to pindexLast->nHeight with >= because this function // returns the work required for the block after pindexLast. - if (params.nPowAllowMinDifficultyBlocksAfterHeight != boost::none && + if (params.nPowAllowMinDifficultyBlocksAfterHeight != std::nullopt && pindexLast->nHeight >= params.nPowAllowMinDifficultyBlocksAfterHeight.value()) { // Special difficulty rule for testnet: diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1cc1e4598..7e5bf469c 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -84,8 +84,8 @@ double GetNetworkDifficulty(const CBlockIndex* blockindex) static UniValue ValuePoolDesc( const std::string &name, - const boost::optional chainValue, - const boost::optional valueDelta) + const std::optional chainValue, + const std::optional valueDelta) { UniValue rv(UniValue::VOBJ); rv.pushKV("id", name); @@ -1060,8 +1060,8 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) CBlockIndex* tip = chainActive.Tip(); UniValue valuePools(UniValue::VARR); - valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, boost::none)); - valuePools.push_back(ValuePoolDesc("sapling", tip->nChainSaplingValue, boost::none)); + valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, std::nullopt)); + valuePools.push_back(ValuePoolDesc("sapling", tip->nChainSaplingValue, std::nullopt)); obj.pushKV("valuePools", valuePools); const Consensus::Params& consensusParams = Params().GetConsensus(); diff --git a/src/serialize.h b/src/serialize.h index 29d35900b..2c933bc0f 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -24,7 +24,6 @@ #include #include -#include #include @@ -539,8 +538,8 @@ template inline void Unserialize(Stream /** * optional */ -template void Serialize(Stream& os, const boost::optional& item); -template void Unserialize(Stream& is, boost::optional& item); +template void Serialize(Stream& os, const std::optional& item); +template void Unserialize(Stream& is, std::optional& item); /** * array @@ -785,7 +784,7 @@ inline void Unserialize(Stream& is, std::vector& v) * optional */ template -void Serialize(Stream& os, const boost::optional& item) +void Serialize(Stream& os, const std::optional& item) { // If the value is there, put 0x01 and then serialize the value. // If it's not, put 0x00. @@ -800,13 +799,13 @@ void Serialize(Stream& os, const boost::optional& item) } template -void Unserialize(Stream& is, boost::optional& item) +void Unserialize(Stream& is, std::optional& item) { unsigned char discriminant = 0x00; Unserialize(is, discriminant); if (discriminant == 0x00) { - item = boost::none; + item = std::nullopt; } else if (discriminant == 0x01) { T object; Unserialize(is, object); diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index ac79ef82d..b00fa69a4 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -13,7 +13,6 @@ #include #include -#include using namespace std; @@ -84,15 +83,15 @@ public: BOOST_AUTO_TEST_CASE(boost_optional) { - check_ser_rep>(0xff, {0x01, 0xff}); - check_ser_rep>(boost::none, {0x00}); - check_ser_rep>(std::string("Test"), {0x01, 0x04, 'T', 'e', 's', 't'}); + check_ser_rep>(0xff, {0x01, 0xff}); + check_ser_rep>(std::nullopt, {0x00}); + check_ser_rep>(std::string("Test"), {0x01, 0x04, 'T', 'e', 's', 't'}); { // Ensure that canonical optional discriminant is used CDataStream ss(SER_DISK, 0); ss.write("\x02\x04Test", 6); - boost::optional into; + std::optional into; BOOST_CHECK_THROW(ss >> into, std::ios_base::failure); } diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 7dc93c8c6..9660d23c8 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -24,17 +24,17 @@ SpendDescriptionInfo::SpendDescriptionInfo( librustzcash_sapling_generate_r(alpha.begin()); } -boost::optional OutputDescriptionInfo::Build(void* ctx) { +std::optional OutputDescriptionInfo::Build(void* ctx) { auto cmu = this->note.cmu(); if (!cmu) { - return boost::none; + return std::nullopt; } libzcash::SaplingNotePlaintext notePlaintext(this->note, this->memo); auto res = notePlaintext.encrypt(this->note.pk_d); if (!res) { - return boost::none; + return std::nullopt; } auto enc = res.value(); auto encryptor = enc.second; @@ -54,7 +54,7 @@ boost::optional OutputDescriptionInfo::Build(void* ctx) { this->note.value(), odesc.cv.begin(), odesc.zkproof.begin())) { - return boost::none; + return std::nullopt; } odesc.cmu = *cmu; @@ -75,9 +75,9 @@ TransactionBuilderResult::TransactionBuilderResult(const CTransaction& tx) : may TransactionBuilderResult::TransactionBuilderResult(const std::string& error) : maybeError(error) {} -bool TransactionBuilderResult::IsTx() { return maybeTx != boost::none; } +bool TransactionBuilderResult::IsTx() { return maybeTx != std::nullopt; } -bool TransactionBuilderResult::IsError() { return maybeError != boost::none; } +bool TransactionBuilderResult::IsError() { return maybeError != std::nullopt; } CTransaction TransactionBuilderResult::GetTxOrThrow() { if (maybeTx) { @@ -227,15 +227,15 @@ void TransactionBuilder::SetFee(CAmount fee) void TransactionBuilder::SendChangeTo(libzcash::SaplingPaymentAddress changeAddr, uint256 ovk) { saplingChangeAddr = std::make_pair(ovk, changeAddr); - sproutChangeAddr = boost::none; - tChangeAddr = boost::none; + sproutChangeAddr = std::nullopt; + tChangeAddr = std::nullopt; } void TransactionBuilder::SendChangeTo(libzcash::SproutPaymentAddress changeAddr) { sproutChangeAddr = changeAddr; - saplingChangeAddr = boost::none; - tChangeAddr = boost::none; + saplingChangeAddr = std::nullopt; + tChangeAddr = std::nullopt; } void TransactionBuilder::SendChangeTo(CTxDestination& changeAddr) @@ -245,8 +245,8 @@ void TransactionBuilder::SendChangeTo(CTxDestination& changeAddr) } tChangeAddr = changeAddr; - saplingChangeAddr = boost::none; - sproutChangeAddr = boost::none; + saplingChangeAddr = std::nullopt; + sproutChangeAddr = std::nullopt; } TransactionBuilderResult TransactionBuilder::Build() @@ -566,7 +566,7 @@ void TransactionBuilder::CreateJSDescriptions() assert(changeOutputIndex != -1); assert(changeOutputIndex < prevJoinSplit.commitments.size()); - boost::optional changeWitness; + std::optional changeWitness; int n = 0; for (const uint256& commitment : prevJoinSplit.commitments) { tree.append(commitment); diff --git a/src/transaction_builder.h b/src/transaction_builder.h index 36bc5ba6d..69198f234 100644 --- a/src/transaction_builder.h +++ b/src/transaction_builder.h @@ -19,7 +19,6 @@ #include "zcash/NoteEncryption.hpp" #include -#include #define NO_MEMO {{0xF6}} @@ -47,7 +46,7 @@ struct OutputDescriptionInfo { libzcash::SaplingNote note, std::array memo) : ovk(ovk), note(note), memo(memo) {} - boost::optional Build(void* ctx); + std::optional Build(void* ctx); }; struct TransparentInputInfo { @@ -61,8 +60,8 @@ struct TransparentInputInfo { class TransactionBuilderResult { private: - boost::optional maybeTx; - boost::optional maybeError; + std::optional maybeTx; + std::optional maybeError; public: TransactionBuilderResult() = delete; TransactionBuilderResult(const CTransaction& tx); @@ -90,9 +89,9 @@ private: std::vector jsOutputs; std::vector tIns; - boost::optional> saplingChangeAddr; - boost::optional sproutChangeAddr; - boost::optional tChangeAddr; + std::optional> saplingChangeAddr; + std::optional sproutChangeAddr; + std::optional tChangeAddr; public: TransactionBuilder() {} diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 3f889c2b5..72a7a7c0d 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -841,8 +841,8 @@ bool CTxMemPool::IsRecentlyEvicted(const uint256& txId) { void CTxMemPool::EnsureSizeLimit() { AssertLockHeld(cs); - boost::optional maybeDropTxId; - while ((maybeDropTxId = weightedTxTree->maybeDropRandom()).is_initialized()) { + std::optional maybeDropTxId; + while ((maybeDropTxId = weightedTxTree->maybeDropRandom()).has_value()) { uint256 txId = maybeDropTxId.value(); recentlyEvicted->add(txId); std::list removed; diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index d0cc6a264..016f37d39 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -189,7 +189,7 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip) SyncWithWallets(tx, NULL, pindexLastTip->nHeight); } // Update cached incremental witnesses - GetMainSignals().ChainTip(pindexLastTip, &block, boost::none); + GetMainSignals().ChainTip(pindexLastTip, &block, std::nullopt); // On to the next block! pindexLastTip = pindexLastTip->pprev; diff --git a/src/validationinterface.h b/src/validationinterface.h index ec1568183..ae129c179 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -37,7 +37,7 @@ protected: virtual void UpdatedBlockTip(const CBlockIndex *pindex) {} virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight) {} virtual void EraseFromWallet(const uint256 &hash) {} - virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, boost::optional> added) {} + virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, std::optional> added) {} virtual void UpdatedTransaction(const uint256 &hash) {} virtual void Inventory(const uint256 &hash) {} virtual void ResendWalletTransactions(int64_t nBestBlockTime) {} @@ -59,7 +59,7 @@ struct CMainSignals { /** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */ boost::signals2::signal UpdatedTransaction; /** Notifies listeners of a change to the tip of the active block chain. */ - boost::signals2::signal>)> ChainTip; + boost::signals2::signal>)> ChainTip; /** Notifies listeners about an inventory item being seen on the network. */ boost::signals2::signal Inventory; /** Tells listeners to broadcast their data. */ diff --git a/src/wallet/asyncrpcoperation_common.cpp b/src/wallet/asyncrpcoperation_common.cpp index d3c911f84..97f697a4e 100644 --- a/src/wallet/asyncrpcoperation_common.cpp +++ b/src/wallet/asyncrpcoperation_common.cpp @@ -6,7 +6,7 @@ extern UniValue signrawtransaction(const UniValue& params, bool fHelp); -UniValue SendTransaction(CTransaction& tx, boost::optional reservekey, bool testmode) { +UniValue SendTransaction(CTransaction& tx, std::optional> reservekey, bool testmode) { UniValue o(UniValue::VOBJ); // Send the transaction if (!testmode) { @@ -25,7 +25,7 @@ UniValue SendTransaction(CTransaction& tx, boost::optional reserve return o; } -std::pair SignSendRawTransaction(UniValue obj, boost::optional reservekey, bool testmode) { +std::pair SignSendRawTransaction(UniValue obj, std::optional> reservekey, bool testmode) { // Sign the raw transaction UniValue rawtxnValue = find_value(obj, "rawtxn"); if (rawtxnValue.isNull()) { diff --git a/src/wallet/asyncrpcoperation_common.h b/src/wallet/asyncrpcoperation_common.h index d7448eb3d..e7054aa33 100644 --- a/src/wallet/asyncrpcoperation_common.h +++ b/src/wallet/asyncrpcoperation_common.h @@ -20,7 +20,7 @@ * If testmode is true, do not commit the transaction, * return {"test": 1, "txid": tx.GetHash().ToString(), "hex": EncodeHexTx(tx)} */ -UniValue SendTransaction(CTransaction& tx, boost::optional reservekey, bool testmode); +UniValue SendTransaction(CTransaction& tx, std::optional> reservekey, bool testmode); /** * Sign and send a raw transaction. @@ -28,6 +28,6 @@ UniValue SendTransaction(CTransaction& tx, boost::optional reserve * * Returns a pair of (the parsed transaction, and the result of sending) */ -std::pair SignSendRawTransaction(UniValue obj, boost::optional reservekey, bool testmode); +std::pair SignSendRawTransaction(UniValue obj, std::optional> reservekey, bool testmode); #endif // ZCASH_WALLET_ASYNCRPCOPERATION_COMMON_H diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index 201db5b0b..e72f2f154 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -57,7 +57,7 @@ int mta_find_output(UniValue obj, int n) } AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress( - boost::optional builder, + std::optional builder, CMutableTransaction contextualTx, std::vector utxoInputs, std::vector sproutNoteInputs, @@ -296,7 +296,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() builder_.AddTransparentInput(outPoint, scriptPubKey, amount); } - boost::optional ovk; + std::optional ovk; // Select Sapling notes std::vector saplingOPs; std::vector saplingNotes; @@ -313,7 +313,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() // Fetch Sapling anchor and witnesses uint256 anchor; - std::vector> witnesses; + std::vector> witnesses; { LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->GetSaplingNoteWitnesses(saplingOPs, witnesses, anchor); @@ -355,7 +355,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() // Build the transaction tx_ = builder_.Build().GetTxOrThrow(); - UniValue sendResult = SendTransaction(tx_, boost::none, testmode); + UniValue sendResult = SendTransaction(tx_, std::nullopt, testmode); set_result(sendResult); return true; @@ -375,7 +375,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() if (isPureTaddrOnlyTx) { UniValue obj(UniValue::VOBJ); obj.pushKV("rawtxn", EncodeHexTx(tx_)); - auto txAndResult = SignSendRawTransaction(obj, boost::none, testmode); + auto txAndResult = SignSendRawTransaction(obj, std::nullopt, testmode); tx_ = txAndResult.first; set_result(txAndResult.second); return true; @@ -413,7 +413,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() info.vjsout.push_back(jso); UniValue obj = perform_joinsplit(info); - auto txAndResult = SignSendRawTransaction(obj, boost::none, testmode); + auto txAndResult = SignSendRawTransaction(obj, std::nullopt, testmode); tx_ = txAndResult.first; set_result(txAndResult.second); return true; @@ -438,7 +438,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() JSOutPoint jso = std::get<0>(t); std::vector vOutPoints = {jso}; uint256 inputAnchor; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor}; } @@ -502,7 +502,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() CAmount jsInputValue = 0; uint256 jsAnchor; - std::vector> witnesses; + std::vector> witnesses; JSDescription prevJoinSplit; @@ -533,7 +533,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() } assert(changeOutputIndex != -1); - boost::optional changeWitness; + std::optional changeWitness; int n = 0; for (const uint256& commitment : prevJoinSplit.commitments) { tree.append(commitment); @@ -583,7 +583,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() std::vector vInputNotes; std::vector vInputZKeys; std::vector vOutPoints; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; uint256 inputAnchor; int numInputsNeeded = (jsChange > 0) ? 1 : 0; while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) { @@ -714,7 +714,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() assert(zInputsDeque.size() == 0); assert(vpubNewProcessed); - auto txAndResult = SignSendRawTransaction(obj, boost::none, testmode); + auto txAndResult = SignSendRawTransaction(obj, std::nullopt, testmode); tx_ = txAndResult.first; set_result(txAndResult.second); return true; @@ -723,7 +723,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl() UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -735,7 +735,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector& outPoints) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -746,7 +746,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit( MergeToAddressJSInfo& info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { if (anchor.IsNull()) { diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.h b/src/wallet/asyncrpcoperation_mergetoaddress.h index d00733753..745346b98 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.h +++ b/src/wallet/asyncrpcoperation_mergetoaddress.h @@ -51,7 +51,7 @@ struct MergeToAddressJSInfo { // A struct to help us track the witness and anchor for a given JSOutPoint struct MergeToAddressWitnessAnchorData { - boost::optional witness; + std::optional witness; uint256 anchor; }; @@ -59,7 +59,7 @@ class AsyncRPCOperation_mergetoaddress : public AsyncRPCOperation { public: AsyncRPCOperation_mergetoaddress( - boost::optional builder, + std::optional builder, CMutableTransaction contextualTx, std::vector utxoInputs, std::vector sproutNoteInputs, @@ -123,7 +123,7 @@ private: // JoinSplit where you have the witnesses and anchor UniValue perform_joinsplit( MergeToAddressJSInfo& info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor); void lock_utxos(); @@ -181,7 +181,7 @@ public: UniValue perform_joinsplit( MergeToAddressJSInfo& info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { return delegate->perform_joinsplit(info, witnesses, anchor); diff --git a/src/wallet/asyncrpcoperation_saplingmigration.cpp b/src/wallet/asyncrpcoperation_saplingmigration.cpp index fbad5f956..89fa03cc6 100644 --- a/src/wallet/asyncrpcoperation_saplingmigration.cpp +++ b/src/wallet/asyncrpcoperation_saplingmigration.cpp @@ -140,7 +140,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() { // for each Sprout JoinSplit description // TODO: the above functionality (in comment) is not implemented in zcashd uint256 inputAnchor; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); builder.AddSproutInput(sproutSk, sproutEntry.note, vInputWitnesses[0].value()); } diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index bd55bf456..55a6ec2c1 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -58,7 +58,7 @@ int find_output(UniValue obj, int n) { } AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany( - boost::optional builder, + std::optional builder, CMutableTransaction contextualTx, std::string fromAddress, std::vector tOutputs, @@ -353,7 +353,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { // Fetch Sapling anchor and witnesses uint256 anchor; - std::vector> witnesses; + std::vector> witnesses; { LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->GetSaplingNoteWitnesses(ops, witnesses, anchor); @@ -476,7 +476,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { JSOutPoint jso = t.point; std::vector vOutPoints = { jso }; uint256 inputAnchor; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor); jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor }; } @@ -587,7 +587,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { CAmount jsInputValue = 0; uint256 jsAnchor; - std::vector> witnesses; + std::vector> witnesses; JSDescription prevJoinSplit; @@ -618,7 +618,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { } assert(changeOutputIndex != -1); - boost::optional changeWitness; + std::optional changeWitness; int n = 0; for (const uint256& commitment : prevJoinSplit.commitments) { tree.append(commitment); @@ -667,7 +667,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { // std::vector vInputNotes; std::vector vOutPoints; - std::vector> vInputWitnesses; + std::vector> vInputWitnesses; uint256 inputAnchor; int numInputsNeeded = (jsChange>0) ? 1 : 0; while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) { @@ -825,7 +825,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { assert(zOutputsDeque.size() == 0); assert(vpubNewProcessed); - auto txAndResult = SignSendRawTransaction(obj, boost::none, testmode); + auto txAndResult = SignSendRawTransaction(obj, std::nullopt, testmode); tx_ = txAndResult.first; set_result(txAndResult.second); return true; @@ -974,7 +974,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() { } UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -985,7 +985,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector & outPoints) { - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; { LOCK(cs_main); @@ -996,7 +996,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info UniValue AsyncRPCOperation_sendmany::perform_joinsplit( AsyncJoinSplitInfo & info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { if (anchor.IsNull()) { diff --git a/src/wallet/asyncrpcoperation_sendmany.h b/src/wallet/asyncrpcoperation_sendmany.h index 7fd33ce79..ba578e276 100644 --- a/src/wallet/asyncrpcoperation_sendmany.h +++ b/src/wallet/asyncrpcoperation_sendmany.h @@ -61,14 +61,14 @@ struct AsyncJoinSplitInfo // A struct to help us track the witness and anchor for a given JSOutPoint struct WitnessAnchorData { - boost::optional witness; + std::optional witness; uint256 anchor; }; class AsyncRPCOperation_sendmany : public AsyncRPCOperation { public: AsyncRPCOperation_sendmany( - boost::optional builder, + std::optional builder, CMutableTransaction contextualTx, std::string fromAddress, std::vector tOutputs, @@ -142,7 +142,7 @@ private: // JoinSplit where you have the witnesses and anchor UniValue perform_joinsplit( AsyncJoinSplitInfo & info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor); // payment disclosure! @@ -197,7 +197,7 @@ public: UniValue perform_joinsplit( AsyncJoinSplitInfo & info, - std::vector> witnesses, + std::vector> witnesses, uint256 anchor) { return delegate->perform_joinsplit(info, witnesses, anchor); diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index 8e9a0c48c..c1203b7b6 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -224,7 +224,7 @@ bool ShieldToAddress::operator()(const libzcash::SproutPaymentAddress &zaddr) co info.vjsout.push_back(jso); UniValue obj = m_op->perform_joinsplit(info); - auto txAndResult = SignSendRawTransaction(obj, boost::none, m_op->testmode); + auto txAndResult = SignSendRawTransaction(obj, std::nullopt, m_op->testmode); m_op->tx_ = txAndResult.first; m_op->set_result(txAndResult.second); return true; @@ -252,7 +252,7 @@ bool ShieldToAddress::operator()(const libzcash::SaplingPaymentAddress &zaddr) c // Build the transaction m_op->tx_ = m_op->builder_.Build().GetTxOrThrow(); - UniValue sendResult = SendTransaction(m_op->tx_, boost::none, m_op->testmode); + UniValue sendResult = SendTransaction(m_op->tx_, std::nullopt, m_op->testmode); m_op->set_result(sendResult); return true; diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 4b4b1686c..e0abbe7fd 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -105,8 +105,8 @@ std::pair CreateValidBlock(TestWallet& wallet, std::pair GetWitnessesAndAnchors(TestWallet& wallet, std::vector& sproutNotes, std::vector& saplingNotes, - std::vector>& sproutWitnesses, - std::vector>& saplingWitnesses) { + std::vector>& sproutWitnesses, + std::vector>& saplingWitnesses) { sproutWitnesses.clear(); saplingWitnesses.clear(); uint256 sproutAnchor; @@ -1161,8 +1161,8 @@ TEST(WalletTests, CachedWitnessesEmptyChain) { std::vector sproutNotes {jsoutpt, jsoutpt2}; std::vector saplingNotes = SetSaplingNoteData(wtx); - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; ::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); @@ -1216,8 +1216,8 @@ TEST(WalletTests, CachedWitnessesChainTip) { // Called to fetch anchor std::vector sproutNotes {outpts.first}; std::vector saplingNotes {outpts.second}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); EXPECT_NE(anchors1.first, anchors1.second); @@ -1238,8 +1238,8 @@ TEST(WalletTests, CachedWitnessesChainTip) { wallet.AddToWallet(wtx, true, NULL); std::vector sproutNotes {jsoutpt}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); @@ -1286,8 +1286,8 @@ TEST(WalletTests, CachedWitnessesChainTip) { // Incrementing with the same block again should not change the cache wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree); - std::vector> sproutWitnesses5; - std::vector> saplingWitnesses5; + std::vector> sproutWitnesses5; + std::vector> saplingWitnesses5; auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5); EXPECT_NE(anchors5.first, anchors5.second); @@ -1328,8 +1328,8 @@ TEST(WalletTests, CachedWitnessesDecrementFirst) { // Called to fetch anchor std::vector sproutNotes {outpts.first}; std::vector saplingNotes {outpts.second}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); } @@ -1348,8 +1348,8 @@ TEST(WalletTests, CachedWitnessesDecrementFirst) { wallet.AddToWallet(wtx, true, NULL); std::vector sproutNotes {jsoutpt}; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); @@ -1393,8 +1393,8 @@ TEST(WalletTests, CachedWitnessesCleanIndex) { SproutMerkleTree sproutRiTree = sproutTree; SaplingMerkleTree saplingTree; SaplingMerkleTree saplingRiTree = saplingTree; - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; auto sk = libzcash::SproutSpendingKey::random(); wallet.AddSproutSpendingKey(sk); @@ -1510,8 +1510,8 @@ TEST(WalletTests, ClearNoteWitnessCache) { saplingNotes.emplace_back(wtx.GetHash(), 1); ASSERT_EQ(saplingNotes.size(), 2); - std::vector> sproutWitnesses; - std::vector> saplingWitnesses; + std::vector> sproutWitnesses; + std::vector> saplingWitnesses; // Before clearing, we should have a witness for one note GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses); diff --git a/src/wallet/paymentdisclosuredb.h b/src/wallet/paymentdisclosuredb.h index 703e97a92..8f93f1f73 100644 --- a/src/wallet/paymentdisclosuredb.h +++ b/src/wallet/paymentdisclosuredb.h @@ -13,7 +13,6 @@ #include #include -#include #include diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 8b90280ef..d6c3130b0 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -398,8 +398,8 @@ UniValue importwallet_impl(const UniValue& params, bool fImportZKeys) auto spendingkey = keyIO.DecodeSpendingKey(vstr[0]); int64_t nTime = DecodeDumpTime(vstr[1]); // Only include hdKeypath and seedFpStr if we have both - boost::optional hdKeypath = (vstr.size() > 3) ? boost::optional(vstr[2]) : boost::none; - boost::optional seedFpStr = (vstr.size() > 3) ? boost::optional(vstr[3]) : boost::none; + std::optional hdKeypath = (vstr.size() > 3) ? std::optional(vstr[2]) : std::nullopt; + std::optional seedFpStr = (vstr.size() > 3) ? std::optional(vstr[3]) : std::nullopt; if (IsValidSpendingKey(spendingkey)) { auto addResult = std::visit( AddSpendingKeyToWallet(pwalletMain, Params().GetConsensus(), nTime, hdKeypath, seedFpStr, true), spendingkey); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 27b3329fd..c70241777 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2989,7 +2989,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp) SproutNote decrypted_note = npt.note(payment_addr); assert(pwalletMain != NULL); - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; uint256 commitment = decrypted_note.cm(); pwalletMain->WitnessNoteCommitment( @@ -3099,7 +3099,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp) } uint256 anchor; - std::vector> witnesses; + std::vector> witnesses; pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor); assert(witnesses.size() == notes.size()); @@ -4297,7 +4297,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) } // Builder (used if Sapling addresses are involved) - boost::optional builder; + std::optional builder; if (noSproutAddrs) { builder = TransactionBuilder(Params().GetConsensus(), nextBlockHeight, pwalletMain); } @@ -5079,7 +5079,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) } // Builder (used if Sapling addresses are involved) - boost::optional builder; + std::optional builder; if (isToSaplingZaddr || saplingNoteInputs.size() > 0) { builder = TransactionBuilder(Params().GetConsensus(), nextBlockHeight, pwalletMain); } diff --git a/src/wallet/test/rpc_wallet_tests.cpp b/src/wallet/test/rpc_wallet_tests.cpp index 9634fce0e..07dee957a 100644 --- a/src/wallet/test/rpc_wallet_tests.cpp +++ b/src/wallet/test/rpc_wallet_tests.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include @@ -1124,26 +1123,26 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters) // Test constructor of AsyncRPCOperation_sendmany try { - std::shared_ptr operation(new AsyncRPCOperation_sendmany(boost::none, mtx, "",{}, {}, -1)); + std::shared_ptr operation(new AsyncRPCOperation_sendmany(std::nullopt, mtx, "",{}, {}, -1)); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "Minconf cannot be negative")); } try { - std::shared_ptr operation(new AsyncRPCOperation_sendmany(boost::none, mtx, "",{}, {}, 1)); + std::shared_ptr operation(new AsyncRPCOperation_sendmany(std::nullopt, mtx, "",{}, {}, 1)); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "From address parameter missing")); } try { - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, "tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ", {}, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, "tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ", {}, {}, 1) ); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "No recipients")); } try { std::vector recipients = { SendManyRecipient("dummy", 1*COIN, "") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, "INVALID", recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, "INVALID", recipients, {}, 1) ); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "Invalid from address")); } @@ -1151,7 +1150,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters) // Testnet payment addresses begin with 'zt'. This test detects an incorrect prefix. try { std::vector recipients = { SendManyRecipient("dummy", 1*COIN, "") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, "zcMuhvq8sEkHALuSU2i4NbNQxshSAYrpCExec45ZjtivYPbuiFPwk6WHy4SvsbeZ4siy1WheuRGjtaJmoD1J8bFqNXhsG6U", recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, "zcMuhvq8sEkHALuSU2i4NbNQxshSAYrpCExec45ZjtivYPbuiFPwk6WHy4SvsbeZ4siy1WheuRGjtaJmoD1J8bFqNXhsG6U", recipients, {}, 1) ); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "Invalid from address")); } @@ -1160,7 +1159,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters) // invokes a method on pwalletMain, which is undefined in the google test environment. try { std::vector recipients = { SendManyRecipient("dummy", 1*COIN, "") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, "ztjiDe569DPNbyTE6TSdJTaSDhoXEHLGvYoUnBU1wfVNU52TEyT6berYtySkd21njAeEoh8fFJUT42kua9r8EnhBaEKqCpP", recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, "ztjiDe569DPNbyTE6TSdJTaSDhoXEHLGvYoUnBU1wfVNU52TEyT6berYtySkd21njAeEoh8fFJUT42kua9r8EnhBaEKqCpP", recipients, {}, 1) ); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "no spending key found for zaddr")); } @@ -1172,7 +1171,7 @@ BOOST_AUTO_TEST_CASE(asyncrpcoperation_sign_send_raw_transaction) { UniValue obj(UniValue::VOBJ); obj.pushKV("rawtxn", raw); // Verify test mode is returning output (since no input taddrs, signed and unsigned are the same). - std::pair txAndResult = SignSendRawTransaction(obj, boost::none, true); + std::pair txAndResult = SignSendRawTransaction(obj, std::nullopt, true); UniValue resultObj = txAndResult.second.get_obj(); std::string hex = find_value(resultObj, "hex").get_str(); BOOST_CHECK_EQUAL(hex, raw); @@ -1207,7 +1206,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) // there are no utxos to spend { std::vector recipients = { SendManyRecipient(zaddr1, 100*COIN, "DEADBEEF") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, taddr1, {}, recipients, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, taddr1, {}, recipients, 1) ); operation->main(); BOOST_CHECK(operation->isFailed()); std::string msg = operation->getErrorMessage(); @@ -1218,7 +1217,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) { try { std::vector recipients = {SendManyRecipient(taddr1, 100*COIN, "DEADBEEF")}; - std::shared_ptr operation(new AsyncRPCOperation_sendmany(boost::none, mtx, zaddr1, recipients, {}, 0)); + std::shared_ptr operation(new AsyncRPCOperation_sendmany(std::nullopt, mtx, zaddr1, recipients, {}, 0)); BOOST_CHECK(false); // Fail test if an exception is not thrown } catch (const UniValue& objError) { BOOST_CHECK(find_error(objError, "Minconf cannot be zero when sending from zaddr")); @@ -1229,7 +1228,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) // there are no unspent notes to spend { std::vector recipients = { SendManyRecipient(taddr1, 100*COIN, "DEADBEEF") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, zaddr1, recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, zaddr1, recipients, {}, 1) ); operation->main(); BOOST_CHECK(operation->isFailed()); std::string msg = operation->getErrorMessage(); @@ -1239,7 +1238,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) // get_memo_from_hex_string()) { std::vector recipients = { SendManyRecipient(zaddr1, 100*COIN, "DEADBEEF") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, zaddr1, recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, zaddr1, recipients, {}, 1) ); std::shared_ptr ptr = std::dynamic_pointer_cast (operation); TEST_FRIEND_AsyncRPCOperation_sendmany proxy(ptr); @@ -1290,7 +1289,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) // add_taddr_change_output_to_tx() will append a vout to a raw transaction { std::vector recipients = { SendManyRecipient(zaddr1, 100*COIN, "DEADBEEF") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, zaddr1, recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, zaddr1, recipients, {}, 1) ); std::shared_ptr ptr = std::dynamic_pointer_cast (operation); TEST_FRIEND_AsyncRPCOperation_sendmany proxy(ptr); @@ -1320,7 +1319,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) SendManyRecipient("tmUSbHz3vxnwLvRyNDXbwkZxjVyDodMJEhh", 456000000, ""), SendManyRecipient("tmYZAXYPCP56Xa5JQWWPZuK7o7bfUQW6kkd", 789000000, ""), }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, zaddr1, recipients, {}, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, zaddr1, recipients, {}, 1) ); std::shared_ptr ptr = std::dynamic_pointer_cast (operation); TEST_FRIEND_AsyncRPCOperation_sendmany proxy(ptr); @@ -1338,7 +1337,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) // Dummy input so the operation object can be instantiated. std::vector recipients = { SendManyRecipient(zaddr1, 50000, "ABCD") }; - std::shared_ptr operation( new AsyncRPCOperation_sendmany(boost::none, mtx, zaddr1, {}, recipients, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_sendmany(std::nullopt, mtx, zaddr1, {}, recipients, 1) ); std::shared_ptr ptr = std::dynamic_pointer_cast (operation); TEST_FRIEND_AsyncRPCOperation_sendmany proxy(ptr); @@ -1346,7 +1345,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals) static_cast(operation.get())->testmode = true; AsyncJoinSplitInfo info; - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; try { proxy.perform_joinsplit(info, witnesses, anchor); @@ -1885,14 +1884,14 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters) "mainnet memo"); try { - std::shared_ptr operation(new AsyncRPCOperation_mergetoaddress(boost::none, mtx, {}, {}, {}, testnetzaddr, -1 )); + std::shared_ptr operation(new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, {}, {}, {}, testnetzaddr, -1 )); BOOST_FAIL("Should have caused an error"); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "Fee is out of range")); } try { - std::shared_ptr operation(new AsyncRPCOperation_mergetoaddress(boost::none, mtx, {}, {}, {}, testnetzaddr, 1)); + std::shared_ptr operation(new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, {}, {}, {}, testnetzaddr, 1)); BOOST_FAIL("Should have caused an error"); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "No inputs")); @@ -1902,7 +1901,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters) try { MergeToAddressRecipient badaddr("", "memo"); - std::shared_ptr operation(new AsyncRPCOperation_mergetoaddress(boost::none, mtx, inputs, {}, {}, badaddr, 1)); + std::shared_ptr operation(new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, inputs, {}, {}, badaddr, 1)); BOOST_FAIL("Should have caused an error"); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "Recipient parameter missing")); @@ -1915,7 +1914,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters) // Sprout and Sapling inputs -> throw try { - auto operation = new AsyncRPCOperation_mergetoaddress(boost::none, mtx, inputs, sproutNoteInputs, saplingNoteInputs, testnetzaddr, 1); + auto operation = new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, inputs, sproutNoteInputs, saplingNoteInputs, testnetzaddr, 1); BOOST_FAIL("Should have caused an error"); } catch (const UniValue& objError) { BOOST_CHECK(find_error(objError, "Cannot send from both Sprout and Sapling addresses using z_mergetoaddress")); @@ -1931,7 +1930,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters) // Testnet payment addresses begin with 'zt'. This test detects an incorrect prefix. try { std::vector inputs = { MergeToAddressInputUTXO{ COutPoint{uint256(), 0}, 0, CScript()} }; - std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(boost::none, mtx, inputs, {}, {}, mainnetzaddr, 1) ); + std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, inputs, {}, {}, mainnetzaddr, 1) ); BOOST_FAIL("Should have caused an error"); } catch (const UniValue& objError) { BOOST_CHECK( find_error(objError, "Invalid recipient address")); @@ -1965,7 +1964,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals) // Insufficient funds { std::vector inputs = { MergeToAddressInputUTXO{COutPoint{uint256(),0},0, CScript()} }; - std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(boost::none, mtx, inputs, {}, {}, zaddr1) ); + std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, inputs, {}, {}, zaddr1) ); operation->main(); BOOST_CHECK(operation->isFailed()); std::string msg = operation->getErrorMessage(); @@ -1975,7 +1974,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals) // get_memo_from_hex_string()) { std::vector inputs = { MergeToAddressInputUTXO{COutPoint{uint256(),0},100000, CScript()} }; - std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(boost::none, mtx, inputs, {}, {}, zaddr1) ); + std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, inputs, {}, {}, zaddr1) ); std::shared_ptr ptr = std::dynamic_pointer_cast (operation); TEST_FRIEND_AsyncRPCOperation_mergetoaddress proxy(ptr); @@ -2029,7 +2028,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals) { // Dummy input so the operation object can be instantiated. std::vector inputs = { MergeToAddressInputUTXO{COutPoint{uint256(),0},100000, CScript()} }; - std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(boost::none, mtx, inputs, {}, {}, zaddr1) ); + std::shared_ptr operation( new AsyncRPCOperation_mergetoaddress(std::nullopt, mtx, inputs, {}, {}, zaddr1) ); std::shared_ptr ptr = std::dynamic_pointer_cast (operation); TEST_FRIEND_AsyncRPCOperation_mergetoaddress proxy(ptr); @@ -2037,7 +2036,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals) static_cast(operation.get())->testmode = true; MergeToAddressJSInfo info; - std::vector> witnesses; + std::vector> witnesses; uint256 anchor; try { proxy.perform_joinsplit(info, witnesses, anchor); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 93fe8f320..2e09e7931 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -615,7 +615,7 @@ void CWallet::ChainTipAdded(const CBlockIndex *pindex, void CWallet::ChainTip(const CBlockIndex *pindex, const CBlock *pblock, - boost::optional> added) + std::optional> added) { if (added) { ChainTipAdded(pindex, pblock, added->first, added->second); @@ -666,7 +666,7 @@ void CWallet::RunSaplingMigration(int blockHeight) { for (const CTransaction& transaction : pendingSaplingMigrationTxs) { // Send the transaction CWalletTx wtx(this, transaction); - CommitTransaction(wtx, boost::none); + CommitTransaction(wtx, std::nullopt); } pendingSaplingMigrationTxs.clear(); } @@ -1525,7 +1525,7 @@ void CWallet::UpdateSaplingNullifierNoteMapWithTx(CWalletTx& wtx) { if (item.second.nullifier) { mapSaplingNullifiersToNotes.erase(item.second.nullifier.value()); } - item.second.nullifier = boost::none; + item.second.nullifier = std::nullopt; } else { uint64_t position = nd.witnesses.front().position(); @@ -1536,20 +1536,20 @@ void CWallet::UpdateSaplingNullifierNoteMapWithTx(CWalletTx& wtx) { // The transaction would not have entered the wallet unless // its plaintext had been successfully decrypted previously. - assert(optDeserialized != boost::none); + assert(optDeserialized != std::nullopt); auto optPlaintext = SaplingNotePlaintext::plaintext_checks_without_height(*optDeserialized, nd.ivk, output.ephemeralKey, output.cmu); // An item in mapSaplingNoteData must have already been successfully decrypted, // otherwise the item would not exist in the first place. - assert(optPlaintext != boost::none); + assert(optPlaintext != std::nullopt); auto optNote = optPlaintext.value().note(nd.ivk); - assert(optNote != boost::none); + assert(optNote != std::nullopt); auto optNullifier = optNote.value().nullifier(extfvk.fvk, position); // This should not happen. If it does, maybe the position has been corrupted or miscalculated? - assert(optNullifier != boost::none); + assert(optNullifier != std::nullopt); uint256 nullifier = optNullifier.value(); mapSaplingNullifiersToNotes[nullifier] = op; item.second.nullifier = nullifier; @@ -1842,13 +1842,13 @@ void CWallet::EraseFromWallet(const uint256 &hash) * Returns a nullifier if the SpendingKey is available * Throws std::runtime_error if the decryptor doesn't match this note */ -boost::optional CWallet::GetSproutNoteNullifier(const JSDescription &jsdesc, +std::optional CWallet::GetSproutNoteNullifier(const JSDescription &jsdesc, const libzcash::SproutPaymentAddress &address, const ZCNoteDecryption &dec, const uint256 &hSig, uint8_t n) const { - boost::optional ret; + std::optional ret; auto note_pt = libzcash::SproutNotePlaintext::decrypt( dec, jsdesc.ciphertexts[n], @@ -1988,12 +1988,12 @@ bool CWallet::IsSaplingNullifierFromMe(const uint256& nullifier) const } void CWallet::GetSproutNoteWitnesses(std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor) { LOCK(cs_wallet); witnesses.resize(notes.size()); - boost::optional rt; + std::optional rt; int i = 0; for (JSOutPoint note : notes) { if (mapWallet.count(note.hash) && @@ -2015,12 +2015,12 @@ void CWallet::GetSproutNoteWitnesses(std::vector notes, } void CWallet::GetSaplingNoteWitnesses(std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor) { LOCK(cs_wallet); witnesses.resize(notes.size()); - boost::optional rt; + std::optional rt; int i = 0; for (SaplingOutPoint note : notes) { if (mapWallet.count(note.hash) && @@ -2340,13 +2340,13 @@ std::pair CWalletTx::DecryptSproutNot } } -boost::optional> CWalletTx::DecryptSaplingNote(const Consensus::Params& params, int height, SaplingOutPoint op) const { // Check whether we can decrypt this SaplingOutPoint if (this->mapSaplingNoteData.count(op) == 0) { - return boost::none; + return std::nullopt; } auto output = this->vShieldedOutput[op.n]; @@ -2359,23 +2359,23 @@ boost::optional> CWalletTx::DecryptSaplingNoteWithoutLeadByteCheck(SaplingOutPoint op) const { // Check whether we can decrypt this SaplingOutPoint if (this->mapSaplingNoteData.count(op) == 0) { - return boost::none; + return std::nullopt; } auto output = this->vShieldedOutput[op.n]; @@ -2385,14 +2385,14 @@ boost::optional> CWalletTx::RecoverSaplingNote(const Consensus::Params& params, int height, SaplingOutPoint op, std::set& ovks) const { @@ -2435,10 +2435,10 @@ boost::optional> CWalletTx::RecoverSaplingNoteWithoutLeadByteCheck(SaplingOutPoint op, std::set& ovks) const { @@ -2460,7 +2460,7 @@ boost::optional commitments, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor) { witnesses.resize(commitments.size()); @@ -2701,7 +2701,7 @@ void CWallet::WitnessNoteCommitment(std::vector commitments, { tree.append(note_commitment); - for (boost::optional& wit : witnesses) { + for (std::optional& wit : witnesses) { if (wit) { wit->append(note_commitment); } @@ -2731,7 +2731,7 @@ void CWallet::WitnessNoteCommitment(std::vector commitments, // TODO: #93; Select a root via some heuristic. final_anchor = tree.root(); - for (boost::optional& wit : witnesses) { + for (std::optional& wit : witnesses) { if (wit) { assert(final_anchor == wit->root()); } @@ -3871,7 +3871,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt /** * Call after CreateTransaction unless you want to abort */ -bool CWallet::CommitTransaction(CWalletTx& wtxNew, boost::optional reservekey) +bool CWallet::CommitTransaction(CWalletTx& wtxNew, std::optional> reservekey) { { LOCK2(cs_main, cs_wallet); @@ -5130,7 +5130,7 @@ void CWallet::GetFilteredNotes( // The transaction would not have entered the wallet unless // its plaintext had been successfully decrypted previously. - assert(optDeserialized != boost::none); + assert(optDeserialized != std::nullopt); auto notePt = optDeserialized.value(); auto maybe_pa = nd.ivk.address(notePt.d); @@ -5188,21 +5188,21 @@ bool PaymentAddressBelongsToWallet::operator()(const libzcash::InvalidEncoding& return false; } -boost::optional GetViewingKeyForPaymentAddress::operator()( +std::optional GetViewingKeyForPaymentAddress::operator()( const libzcash::SproutPaymentAddress &zaddr) const { libzcash::SproutViewingKey vk; if (!m_wallet->GetSproutViewingKey(zaddr, vk)) { libzcash::SproutSpendingKey k; if (!m_wallet->GetSproutSpendingKey(zaddr, k)) { - return boost::none; + return std::nullopt; } vk = k.viewing_key(); } return libzcash::ViewingKey(vk); } -boost::optional GetViewingKeyForPaymentAddress::operator()( +std::optional GetViewingKeyForPaymentAddress::operator()( const libzcash::SaplingPaymentAddress &zaddr) const { libzcash::SaplingIncomingViewingKey ivk; @@ -5213,11 +5213,11 @@ boost::optional GetViewingKeyForPaymentAddress::operator() { return libzcash::ViewingKey(extfvk); } else { - return boost::none; + return std::nullopt; } } -boost::optional GetViewingKeyForPaymentAddress::operator()( +std::optional GetViewingKeyForPaymentAddress::operator()( const libzcash::InvalidEncoding& no) const { // Defaults to InvalidEncoding @@ -5244,29 +5244,29 @@ bool HaveSpendingKeyForPaymentAddress::operator()(const libzcash::InvalidEncodin return false; } -boost::optional GetSpendingKeyForPaymentAddress::operator()( +std::optional GetSpendingKeyForPaymentAddress::operator()( const libzcash::SproutPaymentAddress &zaddr) const { libzcash::SproutSpendingKey k; if (m_wallet->GetSproutSpendingKey(zaddr, k)) { return libzcash::SpendingKey(k); } else { - return boost::none; + return std::nullopt; } } -boost::optional GetSpendingKeyForPaymentAddress::operator()( +std::optional GetSpendingKeyForPaymentAddress::operator()( const libzcash::SaplingPaymentAddress &zaddr) const { libzcash::SaplingExtendedSpendingKey extsk; if (m_wallet->GetSaplingExtendedSpendingKey(zaddr, extsk)) { return libzcash::SpendingKey(extsk); } else { - return boost::none; + return std::nullopt; } } -boost::optional GetSpendingKeyForPaymentAddress::operator()( +std::optional GetSpendingKeyForPaymentAddress::operator()( const libzcash::InvalidEncoding& no) const { // Defaults to InvalidEncoding diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index b6c413850..1accf8334 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -228,7 +228,7 @@ public: * transactions they are spent in. This is the same security semantics as * for transparent addresses. */ - boost::optional nullifier; + std::optional nullifier; /** * Cached incremental witnesses for spendable Notes. @@ -291,7 +291,7 @@ public: std::list witnesses; int witnessHeight; libzcash::SaplingIncomingViewingKey ivk; - boost::optional nullifier; + std::optional nullifier; ADD_SERIALIZE_METHODS; @@ -565,17 +565,17 @@ public: std::pair DecryptSproutNote( JSOutPoint jsop) const; - boost::optional> DecryptSaplingNote(const Consensus::Params& params, int height, SaplingOutPoint op) const; - boost::optional> DecryptSaplingNoteWithoutLeadByteCheck(SaplingOutPoint op) const; - boost::optional> RecoverSaplingNote(const Consensus::Params& params, int height, SaplingOutPoint op, std::set& ovks) const; - boost::optional> RecoverSaplingNoteWithoutLeadByteCheck(SaplingOutPoint op, std::set& ovks) const; @@ -1179,7 +1179,7 @@ public: void EraseFromWallet(const uint256 &hash); void WitnessNoteCommitment( std::vector commitments, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); void ReacceptWalletTransactions(); @@ -1204,7 +1204,7 @@ public: */ bool CreateTransaction(const std::vector& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosRet, std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true); - bool CommitTransaction(CWalletTx& wtxNew, boost::optional reservekey); + bool CommitTransaction(CWalletTx& wtxNew, std::optional> reservekey); static CFeeRate minTxFee; /** @@ -1232,7 +1232,7 @@ public: std::set GetAccountAddresses(const std::string& strAccount) const; - boost::optional GetSproutNoteNullifier( + std::optional GetSproutNoteNullifier( const JSDescription& jsdesc, const libzcash::SproutPaymentAddress& address, const ZCNoteDecryption& dec, @@ -1245,11 +1245,11 @@ public: void GetSproutNoteWitnesses( std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor); void GetSaplingNoteWitnesses( std::vector notes, - std::vector>& witnesses, + std::vector>& witnesses, uint256 &final_anchor); isminetype IsMine(const CTxIn& txin) const; @@ -1267,7 +1267,7 @@ public: void ChainTip( const CBlockIndex *pindex, const CBlock *pblock, - boost::optional> added); + std::optional> added); void RunSaplingMigration(int blockHeight); void AddPendingSaplingMigrationTx(const CTransaction& tx); /** Saves witness caches and best block locator to disk. */ @@ -1487,9 +1487,9 @@ private: public: GetViewingKeyForPaymentAddress(CWallet *wallet) : m_wallet(wallet) {} - boost::optional operator()(const libzcash::SproutPaymentAddress &zaddr) const; - boost::optional operator()(const libzcash::SaplingPaymentAddress &zaddr) const; - boost::optional operator()(const libzcash::InvalidEncoding& no) const; + std::optional operator()(const libzcash::SproutPaymentAddress &zaddr) const; + std::optional operator()(const libzcash::SaplingPaymentAddress &zaddr) const; + std::optional operator()(const libzcash::InvalidEncoding& no) const; }; class HaveSpendingKeyForPaymentAddress @@ -1511,9 +1511,9 @@ private: public: GetSpendingKeyForPaymentAddress(CWallet *wallet) : m_wallet(wallet) {} - boost::optional operator()(const libzcash::SproutPaymentAddress &zaddr) const; - boost::optional operator()(const libzcash::SaplingPaymentAddress &zaddr) const; - boost::optional operator()(const libzcash::InvalidEncoding& no) const; + std::optional operator()(const libzcash::SproutPaymentAddress &zaddr) const; + std::optional operator()(const libzcash::SaplingPaymentAddress &zaddr) const; + std::optional operator()(const libzcash::InvalidEncoding& no) const; }; enum KeyAddResult { @@ -1541,18 +1541,18 @@ private: CWallet *m_wallet; const Consensus::Params ¶ms; int64_t nTime; - boost::optional hdKeypath; // currently sapling only - boost::optional seedFpStr; // currently sapling only + std::optional hdKeypath; // currently sapling only + std::optional seedFpStr; // currently sapling only bool log; public: AddSpendingKeyToWallet(CWallet *wallet, const Consensus::Params ¶ms) : - m_wallet(wallet), params(params), nTime(1), hdKeypath(boost::none), seedFpStr(boost::none), log(false) {} + m_wallet(wallet), params(params), nTime(1), hdKeypath(std::nullopt), seedFpStr(std::nullopt), log(false) {} AddSpendingKeyToWallet( CWallet *wallet, const Consensus::Params ¶ms, int64_t _nTime, - boost::optional _hdKeypath, - boost::optional _seedFp, + std::optional _hdKeypath, + std::optional _seedFp, bool _log ) : m_wallet(wallet), params(params), nTime(_nTime), hdKeypath(_hdKeypath), seedFpStr(_seedFp), log(_log) {} diff --git a/src/zcash/IncrementalMerkleTree.cpp b/src/zcash/IncrementalMerkleTree.cpp index ded814088..4f5c23635 100644 --- a/src/zcash/IncrementalMerkleTree.cpp +++ b/src/zcash/IncrementalMerkleTree.cpp @@ -929,17 +929,17 @@ void IncrementalMerkleTree::append(Hash obj) { right = obj; } else { // Combine the leaves and propagate it up the tree - boost::optional combined = Hash::combine(*left, *right, 0); + std::optional combined = Hash::combine(*left, *right, 0); // Set the "left" leaf to the object and make the "right" leaf none left = obj; - right = boost::none; + right = std::nullopt; for (size_t i = 0; i < Depth; i++) { if (i < parents.size()) { if (parents[i]) { combined = Hash::combine(*parents[i], *combined, i+1); - parents[i] = boost::none; + parents[i] = std::nullopt; } else { parents[i] = *combined; break; @@ -965,7 +965,7 @@ bool IncrementalMerkleTree::is_complete(size_t depth) const { return false; } - for (const boost::optional& parent : parents) { + for (const std::optional& parent : parents) { if (!parent) { return false; } @@ -996,7 +996,7 @@ size_t IncrementalMerkleTree::next_depth(size_t skip) const { size_t d = 1; - for (const boost::optional& parent : parents) { + for (const std::optional& parent : parents) { if (!parent) { if (skip) { skip--; @@ -1024,7 +1024,7 @@ Hash IncrementalMerkleTree::root(size_t depth, size_t d = 1; - for (const boost::optional& parent : parents) { + for (const std::optional& parent : parents) { if (parent) { root = Hash::combine(*parent, root, d); } else { @@ -1067,7 +1067,7 @@ MerklePath IncrementalMerkleTree::path(std::deque filler_hash size_t d = 1; - for (const boost::optional& parent : parents) { + for (const std::optional& parent : parents) { if (parent) { index.push_back(true); path.push_back(*parent); @@ -1117,7 +1117,7 @@ void IncrementalWitness::append(Hash obj) { if (cursor->is_complete(cursor_depth)) { filled.push_back(cursor->root(cursor_depth)); - cursor = boost::none; + cursor = std::nullopt; } } else { cursor_depth = tree.next_depth(filled.size()); diff --git a/src/zcash/IncrementalMerkleTree.hpp b/src/zcash/IncrementalMerkleTree.hpp index 80f7e846d..807e6ee2c 100644 --- a/src/zcash/IncrementalMerkleTree.hpp +++ b/src/zcash/IncrementalMerkleTree.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "uint256.h" #include "serialize.h" @@ -126,11 +125,11 @@ public: private: static EmptyMerkleRoots emptyroots; - boost::optional left; - boost::optional right; + std::optional left; + std::optional right; // Collapsed "left" subtrees ordered toward the root of the tree. - std::vector> parents; + std::vector> parents; MerklePath path(std::deque filler_hashes = std::deque()) const; Hash root(size_t depth, std::deque filler_hashes = std::deque()) const; bool is_complete(size_t depth = Depth) const; @@ -193,7 +192,7 @@ public: private: IncrementalMerkleTree tree; std::vector filled; - boost::optional> cursor; + std::optional> cursor; size_t cursor_depth = 0; std::deque partial_path() const; IncrementalWitness(IncrementalMerkleTree tree) : tree(tree) {} diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 00f86f00b..db35c6e5a 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include "tinyformat.h" #include "sync.h" diff --git a/src/zcash/Note.cpp b/src/zcash/Note.cpp index abbfae0bc..e29dd91e3 100644 --- a/src/zcash/Note.cpp +++ b/src/zcash/Note.cpp @@ -59,7 +59,7 @@ SaplingNote::SaplingNote( } // Call librustzcash to compute the commitment -boost::optional SaplingNote::cmu() const { +std::optional SaplingNote::cmu() const { uint256 result; uint256 rcm_tmp = rcm(); if (!librustzcash_sapling_compute_cmu( @@ -70,14 +70,14 @@ boost::optional SaplingNote::cmu() const { result.begin() )) { - return boost::none; + return std::nullopt; } return result; } // Call librustzcash to compute the nullifier -boost::optional SaplingNote::nullifier(const SaplingFullViewingKey& vk, const uint64_t position) const +std::optional SaplingNote::nullifier(const SaplingFullViewingKey& vk, const uint64_t position) const { auto ak = vk.ak; auto nk = vk.nk; @@ -95,7 +95,7 @@ boost::optional SaplingNote::nullifier(const SaplingFullViewingKey& vk, result.begin() )) { - return boost::none; + return std::nullopt; } return result; @@ -167,7 +167,7 @@ SaplingNotePlaintext::SaplingNotePlaintext( } -boost::optional SaplingNotePlaintext::note(const SaplingIncomingViewingKey& ivk) const +std::optional SaplingNotePlaintext::note(const SaplingIncomingViewingKey& ivk) const { auto addr = ivk.address(d); if (addr) { @@ -179,11 +179,11 @@ boost::optional SaplingNotePlaintext::note(const SaplingIncomingVie auto tmp = SaplingNote(d, addr.value().pk_d, value_, rseed, zip_212_enabled); return tmp; } else { - return boost::none; + return std::nullopt; } } -boost::optional SaplingOutgoingPlaintext::decrypt( +std::optional SaplingOutgoingPlaintext::decrypt( const SaplingOutCiphertext &ciphertext, const uint256& ovk, const uint256& cv, @@ -193,7 +193,7 @@ boost::optional SaplingOutgoingPlaintext::decrypt( { auto pt = AttemptSaplingOutDecryption(ciphertext, ovk, cv, cm, epk); if (!pt) { - return boost::none; + return std::nullopt; } // Deserialize from the plaintext @@ -207,11 +207,11 @@ boost::optional SaplingOutgoingPlaintext::decrypt( } catch (const boost::thread_interrupted&) { throw; } catch (...) { - return boost::none; + return std::nullopt; } } -boost::optional SaplingNotePlaintext::decrypt( +std::optional SaplingNotePlaintext::decrypt( const Consensus::Params& params, int height, const SaplingEncCiphertext &ciphertext, @@ -223,7 +223,7 @@ boost::optional SaplingNotePlaintext::decrypt( auto ret = attempt_sapling_enc_decryption_deserialization(ciphertext, ivk, epk); if (!ret) { - return boost::none; + return std::nullopt; } else { const SaplingNotePlaintext plaintext = *ret; @@ -231,14 +231,14 @@ boost::optional SaplingNotePlaintext::decrypt( if (!plaintext_version_is_valid(params, height, plaintext.get_leadbyte())) { LogPrint("receiveunsafe", "Received note plaintext with invalid lead byte %d at height %d", plaintext.get_leadbyte(), height); - return boost::none; + return std::nullopt; } return plaintext_checks_without_height(plaintext, ivk, epk, cmu); } } -boost::optional SaplingNotePlaintext::attempt_sapling_enc_decryption_deserialization( +std::optional SaplingNotePlaintext::attempt_sapling_enc_decryption_deserialization( const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk @@ -247,7 +247,7 @@ boost::optional SaplingNotePlaintext::attempt_sapling_enc_ auto encPlaintext = AttemptSaplingEncDecryption(ciphertext, ivk, epk); if (!encPlaintext) { - return boost::none; + return std::nullopt; } // Deserialize from the plaintext @@ -261,11 +261,11 @@ boost::optional SaplingNotePlaintext::attempt_sapling_enc_ } catch (const boost::thread_interrupted&) { throw; } catch (...) { - return boost::none; + return std::nullopt; } } -boost::optional SaplingNotePlaintext::plaintext_checks_without_height( +std::optional SaplingNotePlaintext::plaintext_checks_without_height( const SaplingNotePlaintext &plaintext, const uint256 &ivk, const uint256 &epk, @@ -274,7 +274,7 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit { uint256 pk_d; if (!librustzcash_ivk_to_pkd(ivk.begin(), plaintext.d.data(), pk_d.begin())) { - return boost::none; + return std::nullopt; } uint256 cmu_expected; @@ -287,11 +287,11 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit cmu_expected.begin() )) { - return boost::none; + return std::nullopt; } if (cmu_expected != cmu) { - return boost::none; + return std::nullopt; } if (plaintext.get_leadbyte() != 0x01) { @@ -301,17 +301,17 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit uint256 expected_epk; uint256 esk = plaintext.generate_or_derive_esk(); if (!librustzcash_sapling_ka_derivepublic(plaintext.d.data(), esk.begin(), expected_epk.begin())) { - return boost::none; + return std::nullopt; } if (expected_epk != epk) { - return boost::none; + return std::nullopt; } } return plaintext; } -boost::optional SaplingNotePlaintext::decrypt( +std::optional SaplingNotePlaintext::decrypt( const Consensus::Params& params, int height, const SaplingEncCiphertext &ciphertext, @@ -324,7 +324,7 @@ boost::optional SaplingNotePlaintext::decrypt( auto ret = attempt_sapling_enc_decryption_deserialization(ciphertext, epk, esk, pk_d); if (!ret) { - return boost::none; + return std::nullopt; } else { SaplingNotePlaintext plaintext = *ret; @@ -332,14 +332,14 @@ boost::optional SaplingNotePlaintext::decrypt( if (!plaintext_version_is_valid(params, height, plaintext.get_leadbyte())) { LogPrint("receiveunsafe", "Received note plaintext with invalid lead byte %d at height %d", plaintext.get_leadbyte(), height); - return boost::none; + return std::nullopt; } return plaintext_checks_without_height(plaintext, epk, esk, pk_d, cmu); } } -boost::optional SaplingNotePlaintext::attempt_sapling_enc_decryption_deserialization( +std::optional SaplingNotePlaintext::attempt_sapling_enc_decryption_deserialization( const SaplingEncCiphertext &ciphertext, const uint256 &epk, const uint256 &esk, @@ -349,7 +349,7 @@ boost::optional SaplingNotePlaintext::attempt_sapling_enc_ auto encPlaintext = AttemptSaplingEncDecryption(ciphertext, epk, esk, pk_d); if (!encPlaintext) { - return boost::none; + return std::nullopt; }; // Deserialize from the plaintext @@ -363,11 +363,11 @@ boost::optional SaplingNotePlaintext::attempt_sapling_enc_ } catch (const boost::thread_interrupted&) { throw; } catch (...) { - return boost::none; + return std::nullopt; } } -boost::optional SaplingNotePlaintext::plaintext_checks_without_height( +std::optional SaplingNotePlaintext::plaintext_checks_without_height( const SaplingNotePlaintext &plaintext, const uint256 &epk, const uint256 &esk, @@ -380,7 +380,7 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit // ZIP 212: Additionally check that the esk provided to this function // is consistent with the esk we can derive if (esk != plaintext.generate_or_derive_esk()) { - return boost::none; + return std::nullopt; } } @@ -388,10 +388,10 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit // https://zips.z.cash/zip-0212#changes-to-the-process-of-receiving-sapling-notes uint256 expected_epk; if (!librustzcash_sapling_ka_derivepublic(plaintext.d.data(), esk.begin(), expected_epk.begin())) { - return boost::none; + return std::nullopt; } if (expected_epk != epk) { - return boost::none; + return std::nullopt; } uint256 cmu_expected; @@ -404,22 +404,22 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit cmu_expected.begin() )) { - return boost::none; + return std::nullopt; } if (cmu_expected != cmu) { - return boost::none; + return std::nullopt; } return plaintext; } -boost::optional SaplingNotePlaintext::encrypt(const uint256& pk_d) const +std::optional SaplingNotePlaintext::encrypt(const uint256& pk_d) const { // Get the encryptor auto sne = SaplingNoteEncryption::FromDiversifier(d, generate_or_derive_esk()); if (!sne) { - return boost::none; + return std::nullopt; } auto enc = sne.value(); @@ -433,7 +433,7 @@ boost::optional SaplingNotePlaintext::encr // Encrypt the plaintext auto encciphertext = enc.encrypt_to_recipient(pk_d, pt); if (!encciphertext) { - return boost::none; + return std::nullopt; } return SaplingNotePlaintextEncryptionResult(encciphertext.value(), enc); } diff --git a/src/zcash/Note.hpp b/src/zcash/Note.hpp index d2ab36145..ed231f411 100644 --- a/src/zcash/Note.hpp +++ b/src/zcash/Note.hpp @@ -10,7 +10,6 @@ #include #include -#include namespace libzcash { @@ -83,8 +82,8 @@ public: virtual ~SaplingNote() {}; - boost::optional cmu() const; - boost::optional nullifier(const SaplingFullViewingKey &vk, const uint64_t position) const; + std::optional cmu() const; + std::optional nullifier(const SaplingFullViewingKey &vk, const uint64_t position) const; uint256 rcm() const; Zip212Enabled get_zip_212_enabled() const { @@ -161,7 +160,7 @@ public: SaplingNotePlaintext(const SaplingNote& note, std::array memo); - static boost::optional decrypt( + static std::optional decrypt( const Consensus::Params& params, int height, const SaplingEncCiphertext &ciphertext, @@ -170,20 +169,20 @@ public: const uint256 &cmu ); - static boost::optional plaintext_checks_without_height( + static std::optional plaintext_checks_without_height( const SaplingNotePlaintext &plaintext, const uint256 &ivk, const uint256 &epk, const uint256 &cmu ); - static boost::optional attempt_sapling_enc_decryption_deserialization( + static std::optional attempt_sapling_enc_decryption_deserialization( const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk ); - static boost::optional decrypt( + static std::optional decrypt( const Consensus::Params& params, int height, const SaplingEncCiphertext &ciphertext, @@ -193,7 +192,7 @@ public: const uint256 &cmu ); - static boost::optional plaintext_checks_without_height( + static std::optional plaintext_checks_without_height( const SaplingNotePlaintext &plaintext, const uint256 &epk, const uint256 &esk, @@ -201,14 +200,14 @@ public: const uint256 &cmu ); - static boost::optional attempt_sapling_enc_decryption_deserialization( + static std::optional attempt_sapling_enc_decryption_deserialization( const SaplingEncCiphertext &ciphertext, const uint256 &epk, const uint256 &esk, const uint256 &pk_d ); - boost::optional note(const SaplingIncomingViewingKey& ivk) const; + std::optional note(const SaplingIncomingViewingKey& ivk) const; virtual ~SaplingNotePlaintext() {} @@ -228,7 +227,7 @@ public: READWRITE(memo_); // 512 bytes } - boost::optional encrypt(const uint256& pk_d) const; + std::optional encrypt(const uint256& pk_d) const; uint256 rcm() const; uint256 generate_or_derive_esk() const; @@ -255,7 +254,7 @@ public: READWRITE(esk); // 8 bytes } - static boost::optional decrypt( + static std::optional decrypt( const SaplingOutCiphertext &ciphertext, const uint256& ovk, const uint256& cv, diff --git a/src/zcash/NoteEncryption.cpp b/src/zcash/NoteEncryption.cpp index dd0c06215..99272f9bf 100644 --- a/src/zcash/NoteEncryption.cpp +++ b/src/zcash/NoteEncryption.cpp @@ -90,7 +90,7 @@ void KDF(unsigned char K[NOTEENCRYPTION_CIPHER_KEYSIZE], namespace libzcash { -boost::optional SaplingNoteEncryption::FromDiversifier( +std::optional SaplingNoteEncryption::FromDiversifier( diversifier_t d, uint256 esk ) @@ -99,13 +99,13 @@ boost::optional SaplingNoteEncryption::FromDiversifier( // Compute epk given the diversifier if (!librustzcash_sapling_ka_derivepublic(d.begin(), esk.begin(), epk.begin())) { - return boost::none; + return std::nullopt; } return SaplingNoteEncryption(epk, esk); } -boost::optional SaplingNoteEncryption::encrypt_to_recipient( +std::optional SaplingNoteEncryption::encrypt_to_recipient( const uint256 &pk_d, const SaplingEncPlaintext &message ) @@ -117,7 +117,7 @@ boost::optional SaplingNoteEncryption::encrypt_to_recipien uint256 dhsecret; if (!librustzcash_sapling_ka_agree(pk_d.begin(), esk.begin(), dhsecret.begin())) { - return boost::none; + return std::nullopt; } // Construct the symmetric key @@ -141,7 +141,7 @@ boost::optional SaplingNoteEncryption::encrypt_to_recipien return ciphertext; } -boost::optional AttemptSaplingEncDecryption( +std::optional AttemptSaplingEncDecryption( const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk @@ -150,7 +150,7 @@ boost::optional AttemptSaplingEncDecryption( uint256 dhsecret; if (!librustzcash_sapling_ka_agree(epk.begin(), ivk.begin(), dhsecret.begin())) { - return boost::none; + return std::nullopt; } // Construct the symmetric key @@ -170,13 +170,13 @@ boost::optional AttemptSaplingEncDecryption( 0, cipher_nonce, K) != 0) { - return boost::none; + return std::nullopt; } return plaintext; } -boost::optional AttemptSaplingEncDecryption ( +std::optional AttemptSaplingEncDecryption ( const SaplingEncCiphertext &ciphertext, const uint256 &epk, const uint256 &esk, @@ -186,7 +186,7 @@ boost::optional AttemptSaplingEncDecryption ( uint256 dhsecret; if (!librustzcash_sapling_ka_agree(pk_d.begin(), esk.begin(), dhsecret.begin())) { - return boost::none; + return std::nullopt; } // Construct the symmetric key @@ -206,7 +206,7 @@ boost::optional AttemptSaplingEncDecryption ( 0, cipher_nonce, K) != 0) { - return boost::none; + return std::nullopt; } return plaintext; @@ -245,7 +245,7 @@ SaplingOutCiphertext SaplingNoteEncryption::encrypt_to_ourselves( return ciphertext; } -boost::optional AttemptSaplingOutDecryption( +std::optional AttemptSaplingOutDecryption( const SaplingOutCiphertext &ciphertext, const uint256 &ovk, const uint256 &cv, @@ -270,7 +270,7 @@ boost::optional AttemptSaplingOutDecryption( 0, cipher_nonce, K) != 0) { - return boost::none; + return std::nullopt; } return plaintext; diff --git a/src/zcash/NoteEncryption.hpp b/src/zcash/NoteEncryption.hpp index b3c029cad..a4484004b 100644 --- a/src/zcash/NoteEncryption.hpp +++ b/src/zcash/NoteEncryption.hpp @@ -43,9 +43,9 @@ protected: public: - static boost::optional FromDiversifier(diversifier_t d, uint256 esk); + static std::optional FromDiversifier(diversifier_t d, uint256 esk); - boost::optional encrypt_to_recipient( + std::optional encrypt_to_recipient( const uint256 &pk_d, const SaplingEncPlaintext &message ); @@ -68,7 +68,7 @@ public: // Attempts to decrypt a Sapling note. This will not check that the contents // of the ciphertext are correct. -boost::optional AttemptSaplingEncDecryption( +std::optional AttemptSaplingEncDecryption( const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk @@ -76,7 +76,7 @@ boost::optional AttemptSaplingEncDecryption( // Attempts to decrypt a Sapling note using outgoing plaintext. // This will not check that the contents of the ciphertext are correct. -boost::optional AttemptSaplingEncDecryption ( +std::optional AttemptSaplingEncDecryption ( const SaplingEncCiphertext &ciphertext, const uint256 &epk, const uint256 &esk, @@ -85,7 +85,7 @@ boost::optional AttemptSaplingEncDecryption ( // Attempts to decrypt a Sapling note. This will not check that the contents // of the ciphertext are correct. -boost::optional AttemptSaplingOutDecryption( +std::optional AttemptSaplingOutDecryption( const SaplingOutCiphertext &ciphertext, const uint256 &ovk, const uint256 &cv, diff --git a/src/zcash/address/sapling.cpp b/src/zcash/address/sapling.cpp index 30aa77348..2a49f0461 100644 --- a/src/zcash/address/sapling.cpp +++ b/src/zcash/address/sapling.cpp @@ -23,13 +23,13 @@ uint256 SaplingPaymentAddress::GetHash() const { return Hash(ss.begin(), ss.end()); } -boost::optional SaplingIncomingViewingKey::address(diversifier_t d) const { +std::optional SaplingIncomingViewingKey::address(diversifier_t d) const { uint256 pk_d; if (librustzcash_check_diversifier(d.data())) { librustzcash_ivk_to_pkd(this->begin(), d.data(), pk_d.begin()); return SaplingPaymentAddress(d, pk_d); } else { - return boost::none; + return std::nullopt; } } @@ -79,7 +79,7 @@ SaplingFullViewingKey SaplingSpendingKey::full_viewing_key() const { SaplingPaymentAddress SaplingSpendingKey::default_address() const { // Iterates within default_diversifier to ensure a valid address is returned auto addrOpt = full_viewing_key().in_viewing_key().address(default_diversifier(*this)); - assert(addrOpt != boost::none); + assert(addrOpt != std::nullopt); return addrOpt.value(); } diff --git a/src/zcash/address/sapling.hpp b/src/zcash/address/sapling.hpp index 11d0cc196..b4cccd0f1 100644 --- a/src/zcash/address/sapling.hpp +++ b/src/zcash/address/sapling.hpp @@ -55,7 +55,7 @@ public: SaplingIncomingViewingKey(uint256 ivk) : uint256(ivk) { } // Can pass in diversifier for Sapling addr - boost::optional address(diversifier_t d) const; + std::optional address(diversifier_t d) const; }; class SaplingFullViewingKey { diff --git a/src/zcash/address/zip32.cpp b/src/zcash/address/zip32.cpp index 6104da568..d36618960 100644 --- a/src/zcash/address/zip32.cpp +++ b/src/zcash/address/zip32.cpp @@ -54,7 +54,7 @@ uint256 ovkForShieldingFromTaddr(HDSeed& seed) { namespace libzcash { -boost::optional SaplingExtendedFullViewingKey::Derive(uint32_t i) const +std::optional SaplingExtendedFullViewingKey::Derive(uint32_t i) const { CDataStream ss_p(SER_NETWORK, PROTOCOL_VERSION); ss_p << *this; @@ -71,11 +71,11 @@ boost::optional SaplingExtendedFullViewingKey::De ss_i >> xfvk_i; return xfvk_i; } else { - return boost::none; + return std::nullopt; } } -boost::optional> +std::optional> SaplingExtendedFullViewingKey::Address(diversifier_index_t j) const { CDataStream ss_xfvk(SER_NETWORK, PROTOCOL_VERSION); @@ -93,7 +93,7 @@ boost::optional> ss_addr >> addr; return std::make_pair(j_ret, addr); } else { - return boost::none; + return std::nullopt; } } diff --git a/src/zcash/address/zip32.h b/src/zcash/address/zip32.h index 5aef0babb..50e5516ae 100644 --- a/src/zcash/address/zip32.h +++ b/src/zcash/address/zip32.h @@ -11,7 +11,6 @@ #include "zcash/address/sapling.hpp" #include -#include const uint32_t ZIP32_HARDENED_KEY_LIMIT = 0x80000000; const size_t ZIP32_XFVK_SIZE = 169; @@ -70,12 +69,12 @@ struct SaplingExtendedFullViewingKey { READWRITE(dk); } - boost::optional Derive(uint32_t i) const; + std::optional Derive(uint32_t i) const; // Returns the first index starting from j that generates a valid // payment address, along with the corresponding address. Returns // an error if the diversifier space is exhausted. - boost::optional> + std::optional> Address(diversifier_index_t j) const; libzcash::SaplingPaymentAddress DefaultAddress() const;