Migrate from boost::optional::get to boost::optional::value

std::optional only has std::optional::value.
This commit is contained in:
Jack Grigg 2020-10-21 00:39:23 +01:00
parent ae4551004a
commit d9928926f3
31 changed files with 119 additions and 119 deletions

View File

@ -61,9 +61,9 @@ std::set<FundingStreamElement> GetActiveFundingStreamElements(
// in the definition of vFundingStreams.
auto fs = params.vFundingStreams[idx];
// Funding period is [startHeight, endHeight)
if (fs && nHeight >= fs.get().GetStartHeight() && nHeight < fs.get().GetEndHeight()) {
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
requiredElements.insert(std::make_pair(
fs.get().RecipientAddress(params, nHeight),
fs.value().RecipientAddress(params, nHeight),
FundingStreamInfo[idx].Value(blockSubsidy)));
}
}
@ -82,7 +82,7 @@ std::vector<FSInfo> GetActiveFundingStreams(
if (params.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
auto fs = params.vFundingStreams[idx];
if (fs && nHeight >= fs.get().GetStartHeight() && nHeight < fs.get().GetEndHeight()) {
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
activeStreams.push_back(FundingStreamInfo[idx]);
}
}

View File

@ -161,7 +161,7 @@ boost::optional<int> NextActivationHeight(
{
auto idx = NextEpoch(nHeight, params);
if (idx) {
return params.vUpgrades[idx.get()].nActivationHeight;
return params.vUpgrades[idx.value()].nActivationHeight;
}
return boost::none;
}

View File

@ -1134,7 +1134,7 @@ TEST(ChecktransactionTests, HeartwoodAcceptsShieldedCoinbase) {
auto output = OutputDescriptionInfo(ovk, note, {{0xF6}});
auto ctx = librustzcash_sapling_proving_ctx_init();
auto odesc = output.Build(ctx).get();
auto odesc = output.Build(ctx).value();
librustzcash_sapling_proving_ctx_free(ctx);
CMutableTransaction mtx = GetValidTransaction();
@ -1240,7 +1240,7 @@ TEST(ChecktransactionTests, HeartwoodEnforcesSaplingRulesOnShieldedCoinbase) {
// Add a Sapling output.
auto ctx = librustzcash_sapling_proving_ctx_init();
auto odesc = output.Build(ctx).get();
auto odesc = output.Build(ctx).value();
librustzcash_sapling_proving_ctx_free(ctx);
mtx.vShieldedOutput.push_back(odesc);

View File

@ -105,8 +105,8 @@ void checkNumberOfUniqueAddresses(int nUnique) {
int GetMaxFundingStreamHeight(const Consensus::Params& params) {
int result = 0;
for (auto fs : params.vFundingStreams) {
if (fs && result < fs.get().GetEndHeight() - 1) {
result = fs.get().GetEndHeight() - 1;
if (fs && result < fs.value().GetEndHeight() - 1) {
result = fs.value().GetEndHeight() - 1;
}
}

View File

@ -100,7 +100,7 @@ TEST(MempoolLimitTests, WeightedTxTreeCheckSizeAfterDropping)
EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight);
boost::optional<uint256> drop = tree.maybeDropRandom();
ASSERT_TRUE(drop.is_initialized());
uint256 txid = drop.get();
uint256 txid = drop.value();
testedDropping.insert(txid);
// Do not continue to test if a particular trial fails
ASSERT_EQ(8000, tree.getTotalWeight().cost);

View File

@ -50,7 +50,7 @@ TEST(NoteEncryption, NotePlaintext)
if (!cmu_opt) {
FAIL();
}
uint256 cmu = cmu_opt.get();
uint256 cmu = cmu_opt.value();
SaplingNotePlaintext pt(note, memo);
auto res = pt.encrypt(addr.pk_d);
@ -58,7 +58,7 @@ TEST(NoteEncryption, NotePlaintext)
FAIL();
}
auto enc = res.get();
auto enc = res.value();
auto ct = enc.first;
auto encryptor = enc.second;
@ -88,7 +88,7 @@ TEST(NoteEncryption, NotePlaintext)
FAIL();
}
auto bar = foo.get();
auto bar = foo.value();
ASSERT_TRUE(bar.value() == pt.value());
ASSERT_TRUE(bar.memo() == pt.memo());
@ -101,7 +101,7 @@ TEST(NoteEncryption, NotePlaintext)
FAIL();
}
auto new_note = foobar.get();
auto new_note = foobar.value();
ASSERT_TRUE(note.value() == new_note.value());
ASSERT_TRUE(note.d == new_note.d);
@ -136,7 +136,7 @@ TEST(NoteEncryption, NotePlaintext)
FAIL();
}
auto decrypted_out_ct_unwrapped = decrypted_out_ct.get();
auto decrypted_out_ct_unwrapped = decrypted_out_ct.value();
ASSERT_TRUE(decrypted_out_ct_unwrapped.pk_d == out_pt.pk_d);
ASSERT_TRUE(decrypted_out_ct_unwrapped.esk == out_pt.esk);
@ -169,7 +169,7 @@ TEST(NoteEncryption, NotePlaintext)
FAIL();
}
bar = foo.get();
bar = foo.value();
ASSERT_TRUE(bar.value() == pt.value());
ASSERT_TRUE(bar.memo() == pt.memo());
@ -210,7 +210,7 @@ TEST(NoteEncryption, RejectsInvalidNoteZip212Enabled)
if (!cmu_opt) {
FAIL();
}
uint256 cmu = cmu_opt.get();
uint256 cmu = cmu_opt.value();
SaplingNotePlaintext pt(note, memo);
auto res = pt.encrypt(addr.pk_d);
@ -218,7 +218,7 @@ TEST(NoteEncryption, RejectsInvalidNoteZip212Enabled)
FAIL();
}
auto enc = res.get();
auto enc = res.value();
auto ct = enc.first;
auto encryptor = enc.second;
@ -241,7 +241,7 @@ TEST(NoteEncryption, RejectsInvalidNoteZip212Enabled)
if (!cmu_opt) {
FAIL();
}
uint256 cmu = cmu_opt.get();
uint256 cmu = cmu_opt.value();
SaplingNotePlaintext pt(note, memo);
auto res = pt.encrypt(addr.pk_d);
@ -249,7 +249,7 @@ TEST(NoteEncryption, RejectsInvalidNoteZip212Enabled)
FAIL();
}
auto enc = res.get();
auto enc = res.value();
auto ct = enc.first;
auto encryptor = enc.second;
@ -301,7 +301,7 @@ TEST(NoteEncryption, AcceptsValidNoteZip212Enabled)
if (!cmu_opt) {
FAIL();
}
uint256 cmu = cmu_opt.get();
uint256 cmu = cmu_opt.value();
SaplingNotePlaintext pt(note, memo);
auto res = pt.encrypt(addr.pk_d);
@ -309,7 +309,7 @@ TEST(NoteEncryption, AcceptsValidNoteZip212Enabled)
FAIL();
}
auto enc = res.get();
auto enc = res.value();
auto ct = enc.first;
auto encryptor = enc.second;
@ -343,7 +343,7 @@ TEST(NoteEncryption, AcceptsValidNoteZip212Enabled)
if (!cmu_opt) {
FAIL();
}
uint256 cmu = cmu_opt.get();
uint256 cmu = cmu_opt.value();
SaplingNotePlaintext pt(note, memo);
auto res = pt.encrypt(addr.pk_d);
@ -351,7 +351,7 @@ TEST(NoteEncryption, AcceptsValidNoteZip212Enabled)
FAIL();
}
auto enc = res.get();
auto enc = res.value();
auto ct = enc.first;
auto encryptor = enc.second;
@ -380,7 +380,7 @@ TEST(NoteEncryption, AcceptsValidNoteZip212Enabled)
if (!cmu_opt) {
FAIL();
}
uint256 cmu = cmu_opt.get();
uint256 cmu = cmu_opt.value();
SaplingNotePlaintext pt(note, memo);
auto res = pt.encrypt(addr.pk_d);
@ -388,7 +388,7 @@ TEST(NoteEncryption, AcceptsValidNoteZip212Enabled)
FAIL();
}
auto enc = res.get();
auto enc = res.value();
auto ct = enc.first;
auto encryptor = enc.second;

View File

@ -93,7 +93,7 @@ TEST(PoW, MinDifficultyRules) {
std::vector<CBlockIndex> blocks(lastBlk+1);
for (int i = 0; i <= lastBlk; i++) {
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
blocks[i].nHeight = params.nPowAllowMinDifficultyBlocksAfterHeight.get() + i;
blocks[i].nHeight = params.nPowAllowMinDifficultyBlocksAfterHeight.value() + i;
blocks[i].nTime = i ? blocks[i - 1].nTime + params.PoWTargetSpacing(i) : 1269211443;
blocks[i].nBits = 0x1e7fffff; /* target 0x007fffff000... */
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);

View File

@ -45,7 +45,7 @@ TEST(SaplingNote, TestVectors)
// Test commitment
SaplingNote note = SaplingNote(diversifier, pk_d, v, r, Zip212Enabled::BeforeZip212);
ASSERT_EQ(note.cmu().get(), cm);
ASSERT_EQ(note.cmu().value(), cm);
// Test nullifier
SaplingSpendingKey spendingKey(sk);

View File

@ -43,11 +43,11 @@ public:
}
bool GetCoins(const uint256 &txid, CCoins &coins) const {
if (coin && txid == coin.get().first.second) {
if (coin && txid == coin.value().first.second) {
CCoins newCoins;
newCoins.vout.resize(2);
newCoins.vout[0] = coin.get().second.first;
newCoins.nHeight = coin.get().second.second;
newCoins.vout[0] = coin.value().second.first;
newCoins.nHeight = coin.value().second.second;
coins.swap(newCoins);
return true;
} else {
@ -56,7 +56,7 @@ public:
}
bool HaveCoins(const uint256 &txid) const {
if (coin && txid == coin.get().first.second) {
if (coin && txid == coin.value().first.second) {
return true;
} else {
return false;
@ -65,7 +65,7 @@ public:
uint256 GetBestBlock() const {
if (coin) {
return coin.get().first.first;
return coin.value().first.first;
} else {
uint256 a;
return a;

View File

@ -109,7 +109,7 @@ TEST(ZIP32, TestVectors) {
auto maybe_m_1_2hv_3 = m_1_2hv.Derive(3);
EXPECT_TRUE(maybe_m_1_2hv_3);
auto m_1_2hv_3 = maybe_m_1_2hv_3.get();
auto m_1_2hv_3 = maybe_m_1_2hv_3.value();
EXPECT_EQ(m_1_2hv_3.depth, 3);
EXPECT_EQ(m_1_2hv_3.parentFVKTag, 0x7583c148);
EXPECT_EQ(m_1_2hv_3.childIndex, 3);

View File

@ -900,7 +900,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Set this early so that experimental features are correctly enabled/disabled
auto err = InitExperimentalMode();
if (err) {
return InitError(err.get());
return InitError(err.value());
}
// Make sure enough file descriptors are available

View File

@ -1966,7 +1966,7 @@ bool IsInitialBlockDownload(const CChainParams& chainParams)
// If an upgrade is active, we must be past its activation height.
assert(chainActive[upgrade.nActivationHeight]);
if (chainActive[upgrade.nActivationHeight]->GetBlockHash() != upgrade.hashActivationBlock.get()) {
if (chainActive[upgrade.nActivationHeight]->GetBlockHash() != upgrade.hashActivationBlock.value()) {
AbortNode(
strprintf(
"%s: We are on a chain with sufficient work, but the activation block hash for the %s network upgrade is not as expected.\n"
@ -1978,7 +1978,7 @@ bool IsInitialBlockDownload(const CChainParams& chainParams)
chainParams.GetConsensus().nMinimumChainWork.GetHex(),
chainActive.Height(),
upgrade.nActivationHeight,
upgrade.hashActivationBlock.get().GetHex(),
upgrade.hashActivationBlock.value().GetHex(),
chainActive[upgrade.nActivationHeight]->GetBlockHash().GetHex()),
_("We are on a chain with sufficient work, but the network upgrade checkpoints do not match. Your node may be under attack! Shutting down for safety."));
return true;
@ -2575,7 +2575,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s
// This is guaranteed to be filled by LoadBlockIndex.
assert(pindex->nCachedBranchId);
auto consensusBranchId = pindex->nCachedBranchId.get();
auto consensusBranchId = pindex->nCachedBranchId.value();
if (chainparams.GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_HEARTWOOD)) {
view.PopHistoryNode(consensusBranchId);
@ -6982,7 +6982,7 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para
bool blossomActive = consensusParams.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM);
unsigned int defaultExpiryDelta = blossomActive ? DEFAULT_POST_BLOSSOM_TX_EXPIRY_DELTA : DEFAULT_PRE_BLOSSOM_TX_EXPIRY_DELTA;
mtx.nExpiryHeight = nHeight + (expiryDeltaArg ? expiryDeltaArg.get() : defaultExpiryDelta);
mtx.nExpiryHeight = nHeight + (expiryDeltaArg ? expiryDeltaArg.value() : defaultExpiryDelta);
// mtx.nExpiryHeight == 0 is valid for coinbase transactions
if (mtx.nExpiryHeight <= 0 || mtx.nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD) {
@ -6994,7 +6994,7 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para
// TX_EXPIRING_SOON_THRESHOLD (3) blocks (for DoS mitigation) based on the current height.
auto nextActivationHeight = NextActivationHeight(nHeight, consensusParams);
if (nextActivationHeight) {
mtx.nExpiryHeight = std::min(mtx.nExpiryHeight, static_cast<uint32_t>(nextActivationHeight.get()) - 1);
mtx.nExpiryHeight = std::min(mtx.nExpiryHeight, static_cast<uint32_t>(nextActivationHeight.value()) - 1);
}
}
return mtx;

View File

@ -279,7 +279,7 @@ boost::optional<int64_t> SecondsLeftToNextEpoch(const Consensus::Params& params,
{
auto nextHeight = NextActivationHeight(currentHeight, params);
if (nextHeight) {
return (nextHeight.get() - currentHeight) * params.PoWTargetSpacing(nextHeight.get() - 1);
return (nextHeight.value() - currentHeight) * params.PoWTargetSpacing(nextHeight.value() - 1);
} else {
return boost::none;
}

View File

@ -143,7 +143,7 @@ public:
auto odesc = output.Build(ctx);
if (odesc) {
mtx.vShieldedOutput.push_back(odesc.get());
mtx.vShieldedOutput.push_back(odesc.value());
mtx.valueBalance -= fundingStreamValue;
return true;
} else {
@ -260,7 +260,7 @@ public:
librustzcash_sapling_proving_ctx_free(ctx);
throw new std::runtime_error("Failed to create shielded output for miner");
}
mtx.vShieldedOutput.push_back(odesc.get());
mtx.vShieldedOutput.push_back(odesc.value());
ComputeBindingSig(ctx);

View File

@ -823,7 +823,7 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
const Consensus::Params& params = Params().GetConsensus();
auto nextEpoch = NextEpoch(height, params);
if (nextEpoch) {
auto idx = nextEpoch.get();
auto idx = nextEpoch.value();
int nActivationHeight = params.vUpgrades[idx].nActivationHeight;
if (nActivationHeight > 0 &&

View File

@ -31,7 +31,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 &&
pindexLast->nHeight >= params.nPowAllowMinDifficultyBlocksAfterHeight.get())
pindexLast->nHeight >= params.nPowAllowMinDifficultyBlocksAfterHeight.value())
{
// Special difficulty rule for testnet:
// If the new block's timestamp is more than 6 * block interval minutes

View File

@ -981,7 +981,7 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
fsobj.pushKV("valueZat", nStreamAmount);
auto fs = consensus.vFundingStreams[idx];
auto address = fs.get().RecipientAddress(consensus, nHeight);
auto address = fs.value().RecipientAddress(consensus, nHeight);
CScript* outpoint = std::get_if<CScript>(&address);
std::string addressStr;

View File

@ -36,7 +36,7 @@ boost::optional<OutputDescription> OutputDescriptionInfo::Build(void* ctx) {
if (!res) {
return boost::none;
}
auto enc = res.get();
auto enc = res.value();
auto encryptor = enc.second;
libzcash::SaplingPaymentAddress address(this->note.d, this->note.pk_d);
@ -81,7 +81,7 @@ bool TransactionBuilderResult::IsError() { return maybeError != boost::none; }
CTransaction TransactionBuilderResult::GetTxOrThrow() {
if (maybeTx) {
return maybeTx.get();
return maybeTx.value();
} else {
throw JSONRPCError(RPC_WALLET_ERROR, "Failed to build transaction: " + GetError());
}
@ -89,7 +89,7 @@ CTransaction TransactionBuilderResult::GetTxOrThrow() {
std::string TransactionBuilderResult::GetError() {
if (maybeError) {
return maybeError.get();
return maybeError.value();
} else {
// This can only happen if isTx() is true in which case we should not call getError()
throw std::runtime_error("getError() was called in TransactionBuilderResult, but the result was not initialized as an error.");
@ -285,7 +285,7 @@ TransactionBuilderResult TransactionBuilder::Build()
if (saplingChangeAddr) {
AddSaplingOutput(saplingChangeAddr->first, saplingChangeAddr->second, change);
} else if (sproutChangeAddr) {
AddSproutOutput(sproutChangeAddr.get(), change);
AddSproutOutput(sproutChangeAddr.value(), change);
} else if (tChangeAddr) {
// tChangeAddr has already been validated.
AddTransparentOutput(tChangeAddr.value(), change);
@ -360,7 +360,7 @@ TransactionBuilderResult TransactionBuilder::Build()
return TransactionBuilderResult("Failed to create output description");
}
mtx.vShieldedOutput.push_back(odesc.get());
mtx.vShieldedOutput.push_back(odesc.value());
}
//
@ -574,7 +574,7 @@ void TransactionBuilder::CreateJSDescriptions()
if (!changeWitness && changeOutputIndex == n++) {
changeWitness = tree.witness();
} else if (changeWitness) {
changeWitness.get().append(commitment);
changeWitness.value().append(commitment);
}
}
assert(changeWitness.has_value());
@ -593,7 +593,7 @@ void TransactionBuilder::CreateJSDescriptions()
(unsigned char)changeOutputIndex);
auto note = plaintext.note(changeAddress);
vjsin[0] = libzcash::JSInput(changeWitness.get(), note, changeKey);
vjsin[0] = libzcash::JSInput(changeWitness.value(), note, changeKey);
jsInputValue += plaintext.value();

View File

@ -841,7 +841,7 @@ void CTxMemPool::EnsureSizeLimit() {
AssertLockHeld(cs);
boost::optional<uint256> maybeDropTxId;
while ((maybeDropTxId = weightedTxTree->maybeDropRandom()).is_initialized()) {
uint256 txId = maybeDropTxId.get();
uint256 txId = maybeDropTxId.value();
recentlyEvicted->add(txId);
std::list<CTransaction> removed;
remove(mapTx.find(txId)->GetTx(), removed, true);

View File

@ -290,7 +290,7 @@ CKey AddTestCKeyToKeyStore(CBasicKeyStore& keyStore) {
TestSaplingNote GetTestSaplingNote(const libzcash::SaplingPaymentAddress& pa, CAmount value) {
// Generate dummy Sapling note
libzcash::SaplingNote note(pa, value, libzcash::Zip212Enabled::BeforeZip212);
uint256 cm = note.cmu().get();
uint256 cm = note.cmu().value();
SaplingMerkleTree tree;
tree.append(cm);
return { note, tree };

View File

@ -91,7 +91,7 @@ AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress(
isUsingBuilder_ = false;
if (builder) {
isUsingBuilder_ = true;
builder_ = builder.get();
builder_ = builder.value();
}
KeyIO keyIO(Params());
@ -324,7 +324,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
if (!witnesses[i]) {
throw JSONRPCError(RPC_WALLET_ERROR, "Missing witness for Sapling note");
}
builder_.AddSaplingSpend(expsks[i], saplingNotes[i], anchor, witnesses[i].get());
builder_.AddSaplingSpend(expsks[i], saplingNotes[i], anchor, witnesses[i].value());
}
if (isToTaddr_) {
@ -349,7 +349,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
if (!ovk) {
throw JSONRPCError(RPC_WALLET_ERROR, "Sending to a Sapling address requires an ovk.");
}
builder_.AddSaplingOutput(ovk.get(), *saplingPaymentAddress, sendAmount, hexMemo);
builder_.AddSaplingOutput(ovk.value(), *saplingPaymentAddress, sendAmount, hexMemo);
}
// Build the transaction
@ -541,7 +541,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
if (!changeWitness && changeOutputIndex == n++) {
changeWitness = tree.witness();
} else if (changeWitness) {
changeWitness.get().append(commitment);
changeWitness.value().append(commitment);
}
}
if (changeWitness) {
@ -640,7 +640,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
if (!optionalWitness) {
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
}
SproutWitness w = *optionalWitness; // could use .get();
SproutWitness w = *optionalWitness; // could use .value();
if (jsChange > 0) {
for (const uint256& commitment : previousCommitments) {
w.append(commitment);

View File

@ -72,7 +72,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
LogPrint("zrpcunsafe", "%s: Beginning AsyncRPCOperation_saplingmigration.\n", getId());
const Consensus::Params& consensusParams = Params().GetConsensus();
auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams);
if (nextActivationHeight && targetHeight_ + MIGRATION_EXPIRY_DELTA >= nextActivationHeight.get()) {
if (nextActivationHeight && targetHeight_ + MIGRATION_EXPIRY_DELTA >= nextActivationHeight.value()) {
LogPrint("zrpcunsafe", "%s: Migration txs would be created before a NU activation but may expire after. Skipping this round.\n", getId());
setMigrationResult(0, 0, std::vector<std::string>());
return true;
@ -141,7 +141,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
uint256 inputAnchor;
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
builder.AddSproutInput(sproutSk, sproutEntry.note, vInputWitnesses[0].get());
builder.AddSproutInput(sproutSk, sproutEntry.note, vInputWitnesses[0].value());
}
// The amount chosen *includes* the 0.0001 ZEC fee for this transaction, i.e.
// the value of the Sapling output will be 0.0001 ZEC less.

View File

@ -85,7 +85,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
isUsingBuilder_ = false;
if (builder) {
isUsingBuilder_ = true;
builder_ = builder.get();
builder_ = builder.value();
}
KeyIO keyIO(Params());
@ -105,7 +105,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
isfromzaddr_ = true;
frompaymentaddress_ = address;
spendingkey_ = std::visit(GetSpendingKeyForPaymentAddress(pwalletMain), address).get();
spendingkey_ = std::visit(GetSpendingKeyForPaymentAddress(pwalletMain), address).value();
} else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address");
}
@ -364,7 +364,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (!witnesses[i]) {
throw JSONRPCError(RPC_WALLET_ERROR, "Missing witness for Sapling note");
}
builder_.AddSaplingSpend(expsk, notes[i], anchor, witnesses[i].get());
builder_.AddSaplingSpend(expsk, notes[i], anchor, witnesses[i].value());
}
// Add Sapling outputs
@ -626,7 +626,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (!changeWitness && changeOutputIndex == n++) {
changeWitness = tree.witness();
} else if (changeWitness) {
changeWitness.get().append(commitment);
changeWitness.value().append(commitment);
}
}
if (changeWitness) {
@ -724,7 +724,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (!optionalWitness) {
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
}
SproutWitness w = *optionalWitness; // could use .get();
SproutWitness w = *optionalWitness; // could use .value();
if (jsChange > 0) {
for (const uint256& commitment : previousCommitments) {
w.append(commitment);

View File

@ -360,7 +360,7 @@ TEST(WalletTests, SetSaplingNoteAddrsInCWalletTx) {
auto pk = sk.DefaultAddress();
libzcash::SaplingNote note(pk, 50000, zip_212_enabled[ver]);
auto cm = note.cmu().get();
auto cm = note.cmu().value();
SaplingMerkleTree tree;
tree.append(cm);
auto anchor = tree.root();
@ -368,7 +368,7 @@ TEST(WalletTests, SetSaplingNoteAddrsInCWalletTx) {
auto nf = note.nullifier(fvk, witness.position());
ASSERT_TRUE(nf);
uint256 nullifier = nf.get();
uint256 nullifier = nf.value();
auto builder = TransactionBuilder(consensusParams, 1);
builder.AddSaplingSpend(expsk, note, anchor, witness);
@ -634,7 +634,7 @@ TEST(WalletTests, GetConflictedSaplingNotes) {
// Generate note A
libzcash::SaplingNote note(pk, 50000, zip_212_enabled[ver]);
auto cm = note.cmu().get();
auto cm = note.cmu().value();
SaplingMerkleTree saplingTree;
saplingTree.append(cm);
auto anchor = saplingTree.root();
@ -684,15 +684,15 @@ TEST(WalletTests, GetConflictedSaplingNotes) {
wtx.vShieldedOutput[0].ephemeralKey,
wtx.vShieldedOutput[0].cmu);
ASSERT_EQ(static_cast<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
auto maybe_note = maybe_pt.value().note(ivk);
ASSERT_EQ(static_cast<bool>(maybe_note), true);
auto note2 = maybe_note.get();
auto note2 = maybe_note.value();
SaplingOutPoint sop0(wtx.GetHash(), 0);
auto spend_note_witness = wtx.mapSaplingNoteData[sop0].witnesses.front();
auto maybe_nf = note2.nullifier(extfvk.fvk, spend_note_witness.position());
ASSERT_EQ(static_cast<bool>(maybe_nf), true);
auto nullifier2 = maybe_nf.get();
auto nullifier2 = maybe_nf.value();
anchor = saplingTree.root();
@ -804,7 +804,7 @@ TEST(WalletTests, SaplingNullifierIsSpent) {
// Manually compute the nullifier based on the known position
auto nf = testNote.note.nullifier(extfvk.fvk, testNote.tree.witness().position());
ASSERT_TRUE(nf);
uint256 nullifier = nf.get();
uint256 nullifier = nf.value();
// Verify note has not been spent
EXPECT_FALSE(wallet.IsSaplingSpent(nullifier));
@ -889,7 +889,7 @@ TEST(WalletTests, NavigateFromSaplingNullifierToNote) {
// Manually compute the nullifier based on the expected position
auto nf = testNote.note.nullifier(extfvk.fvk, testNote.tree.witness().position());
ASSERT_TRUE(nf);
uint256 nullifier = nf.get();
uint256 nullifier = nf.value();
// Verify dummy note is unspent
EXPECT_FALSE(wallet.IsSaplingSpent(nullifier));
@ -941,7 +941,7 @@ TEST(WalletTests, NavigateFromSaplingNullifierToNote) {
EXPECT_EQ(hash, op.hash);
EXPECT_EQ(1, nd.witnesses.size());
ASSERT_TRUE(nd.nullifier);
auto nf = nd.nullifier.get();
auto nf = nd.nullifier.value();
EXPECT_EQ(1, wallet.mapSaplingNullifiersToNotes.count(nf));
EXPECT_EQ(op.hash, wallet.mapSaplingNullifiersToNotes[nf].hash);
EXPECT_EQ(op.n, wallet.mapSaplingNullifiersToNotes[nf].n);
@ -1007,7 +1007,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
// Generate Sapling note A
libzcash::SaplingNote note(pk, 50000, zip_212_enabled[ver]);
auto cm = note.cmu().get();
auto cm = note.cmu().value();
SaplingMerkleTree saplingTree;
saplingTree.append(cm);
auto anchor = saplingTree.root();
@ -1059,7 +1059,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
// Manually compute the nullifier and check map entry does not exist
auto nf = note.nullifier(extfvk.fvk, witness.position());
ASSERT_TRUE(nf);
ASSERT_FALSE(wallet.mapSaplingNullifiersToNotes.count(nf.get()));
ASSERT_FALSE(wallet.mapSaplingNullifiersToNotes.count(nf.value()));
// Decrypt note B
auto maybe_pt = libzcash::SaplingNotePlaintext::decrypt(
@ -1070,16 +1070,16 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) {
wtx.vShieldedOutput[0].ephemeralKey,
wtx.vShieldedOutput[0].cmu);
ASSERT_EQ(static_cast<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
auto maybe_note = maybe_pt.value().note(ivk);
ASSERT_EQ(static_cast<bool>(maybe_note), true);
auto note2 = maybe_note.get();
auto note2 = maybe_note.value();
// Get witness to retrieve position of note B we want to spend
SaplingOutPoint sop0(wtx.GetHash(), 0);
auto spend_note_witness = wtx.mapSaplingNoteData[sop0].witnesses.front();
auto maybe_nf = note2.nullifier(extfvk.fvk, spend_note_witness.position());
ASSERT_EQ(static_cast<bool>(maybe_nf), true);
auto nullifier2 = maybe_nf.get();
auto nullifier2 = maybe_nf.value();
// NOTE: Not updating the anchor results in a core dump. Shouldn't builder just return error?
// *** Error in `./zcash-gtest': double free or corruption (out): 0x00007ffd8755d990 ***
@ -1997,9 +1997,9 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) {
// Prepare to spend the note that was just created
auto maybe_pt = libzcash::SaplingNotePlaintext::decrypt(consensusParams, fakeIndex.nHeight, tx1.vShieldedOutput[0].encCiphertext, ivk, tx1.vShieldedOutput[0].ephemeralKey, tx1.vShieldedOutput[0].cmu);
ASSERT_EQ(static_cast<bool>(maybe_pt), true);
auto maybe_note = maybe_pt.get().note(ivk);
auto maybe_note = maybe_pt.value().note(ivk);
ASSERT_EQ(static_cast<bool>(maybe_note), true);
auto note = maybe_note.get();
auto note = maybe_note.value();
auto anchor = saplingTree.root();
auto witness = saplingTree.witness();

View File

@ -70,7 +70,7 @@ TEST(WalletZkeysTest, StoreAndLoadSaplingZkeys) {
// If we can't get an early diversified address, we are very unlucky
blob88 diversifier;
diversifier.begin()[0] = 10;
auto dpa = sk.ToXFVK().Address(diversifier).get().second;
auto dpa = sk.ToXFVK().Address(diversifier).value().second;
// verify wallet only has the default address
EXPECT_TRUE(wallet.HaveSaplingIncomingViewingKey(sk.DefaultAddress()));
@ -98,7 +98,7 @@ TEST(WalletZkeysTest, StoreAndLoadSaplingZkeys) {
ASSERT_EQ(wallet.mapSaplingZKeyMetadata[ivk2].nCreateTime, now);
// Load a diversified address for the third key into the wallet
auto dpa2 = sk2.ToXFVK().Address(diversifier).get().second;
auto dpa2 = sk2.ToXFVK().Address(diversifier).value().second;
EXPECT_TRUE(wallet.HaveSaplingIncomingViewingKey(sk2.DefaultAddress()));
EXPECT_FALSE(wallet.HaveSaplingIncomingViewingKey(dpa2));
EXPECT_TRUE(wallet.LoadSaplingPaymentAddress(dpa2, ivk2));
@ -449,7 +449,7 @@ TEST(wallet_zkeys_tests, WriteCryptedSaplingZkeyDirectToDb) {
EXPECT_TRUE(wallet.GetSaplingExtendedSpendingKey(address, extsk));
blob88 diversifier;
diversifier.begin()[0] = 10;
auto dpa = extsk.ToXFVK().Address(diversifier).get().second;
auto dpa = extsk.ToXFVK().Address(diversifier).value().second;
// Add diversified address to the wallet
auto ivk = extsk.expsk.full_viewing_key().in_viewing_key();

View File

@ -913,7 +913,7 @@ UniValue z_exportkey(const UniValue& params, bool fHelp)
if (!sk) {
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr");
}
return keyIO.EncodeSpendingKey(sk.get());
return keyIO.EncodeSpendingKey(sk.value());
}
UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
@ -949,7 +949,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
auto vk = std::visit(GetViewingKeyForPaymentAddress(pwalletMain), address);
if (vk) {
return keyIO.EncodeViewingKey(vk.get());
return keyIO.EncodeViewingKey(vk.value());
} else {
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private key or viewing key for this zaddr");
}

View File

@ -3829,7 +3829,7 @@ UniValue z_viewtransaction(const UniValue& params, bool fHelp)
// means the plaintext leadbyte was valid at the block height
// where the note was received.
// https://zips.z.cash/zip-0212#changes-to-the-process-of-receiving-sapling-notes
auto decrypted = wtxPrev.DecryptSaplingNoteWithoutLeadByteCheck(op).get();
auto decrypted = wtxPrev.DecryptSaplingNoteWithoutLeadByteCheck(op).value();
auto notePt = decrypted.first;
auto pa = decrypted.second;

View File

@ -705,7 +705,7 @@ std::set<std::pair<libzcash::PaymentAddress, uint256>> CWallet::GetNullifiersFor
auto & nullifier = noteData.nullifier;
auto & address = noteData.address;
if (nullifier && addresses.count(address)) {
nullifierSet.insert(std::make_pair(address, nullifier.get()));
nullifierSet.insert(std::make_pair(address, nullifier.value()));
}
}
// Sapling
@ -715,7 +715,7 @@ std::set<std::pair<libzcash::PaymentAddress, uint256>> CWallet::GetNullifiersFor
auto & ivk = noteData.ivk;
if (nullifier && ivkMap.count(ivk)) {
for (const auto & addr : ivkMap[ivk]) {
nullifierSet.insert(std::make_pair(addr, nullifier.get()));
nullifierSet.insert(std::make_pair(addr, nullifier.value()));
}
}
}
@ -1523,7 +1523,7 @@ void CWallet::UpdateSaplingNullifierNoteMapWithTx(CWalletTx& wtx) {
if (nd.witnesses.empty()) {
// If there are no witnesses, erase the nullifier and associated mapping.
if (item.second.nullifier) {
mapSaplingNullifiersToNotes.erase(item.second.nullifier.get());
mapSaplingNullifiersToNotes.erase(item.second.nullifier.value());
}
item.second.nullifier = boost::none;
}
@ -1544,13 +1544,13 @@ void CWallet::UpdateSaplingNullifierNoteMapWithTx(CWalletTx& wtx) {
// otherwise the item would not exist in the first place.
assert(optPlaintext != boost::none);
auto optNote = optPlaintext.get().note(nd.ivk);
auto optNote = optPlaintext.value().note(nd.ivk);
assert(optNote != boost::none);
auto optNullifier = optNote.get().nullifier(extfvk.fvk, position);
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);
uint256 nullifier = optNullifier.get();
uint256 nullifier = optNullifier.value();
mapSaplingNullifiersToNotes[nullifier] = op;
item.second.nullifier = nullifier;
}
@ -1946,9 +1946,9 @@ std::pair<mapSaplingNoteData_t, SaplingIncomingViewingKeyMap> CWallet::FindMySap
if (!result) {
continue;
}
auto address = ivk.address(result.get().d);
if (address && mapSaplingIncomingViewingKeys.count(address.get()) == 0) {
viewingKeysToAdd[address.get()] = ivk;
auto address = ivk.address(result.value().d);
if (address && mapSaplingIncomingViewingKeys.count(address.value()) == 0) {
viewingKeysToAdd[address.value()] = ivk;
}
// We don't cache the nullifier here as computing it requires knowledge of the note position
// in the commitment tree, which can only be determined when the transaction has been mined.
@ -2360,11 +2360,11 @@ boost::optional<std::pair<
output.ephemeralKey,
output.cmu);
assert(maybe_pt != boost::none);
auto notePt = maybe_pt.get();
auto notePt = maybe_pt.value();
auto maybe_pa = nd.ivk.address(notePt.d);
assert(maybe_pa != boost::none);
auto pa = maybe_pa.get();
auto pa = maybe_pa.value();
return std::make_pair(notePt, pa);
}
@ -2393,11 +2393,11 @@ boost::optional<std::pair<
output.ephemeralKey,
output.cmu);
assert(maybe_pt != boost::none);
auto notePt = maybe_pt.get();
auto notePt = maybe_pt.value();
auto maybe_pa = nd.ivk.address(notePt.d);
assert(static_cast<bool>(maybe_pa));
auto pa = maybe_pa.get();
auto pa = maybe_pa.value();
return std::make_pair(notePt, pa);
}
@ -2429,7 +2429,7 @@ boost::optional<std::pair<
outPt->pk_d,
output.cmu);
assert(static_cast<bool>(maybe_pt));
auto notePt = maybe_pt.get();
auto notePt = maybe_pt.value();
return std::make_pair(notePt, SaplingPaymentAddress(notePt.d, outPt->pk_d));
}
@ -2469,7 +2469,7 @@ boost::optional<std::pair<
outPt->pk_d,
output.cmu);
assert(static_cast<bool>(maybe_pt));
auto notePt = maybe_pt.get();
auto notePt = maybe_pt.value();
return std::make_pair(notePt, SaplingPaymentAddress(notePt.d, outPt->pk_d));
}
@ -3884,7 +3884,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, boost::optional<CReserveKey&>
if (reservekey) {
// Take key pair from key pool so it won't be used again
reservekey.get().KeepKey();
reservekey.value().KeepKey();
}
// Add tx to wallet, because if it has change it's also ours,
@ -5132,10 +5132,10 @@ void CWallet::GetFilteredNotes(
// its plaintext had been successfully decrypted previously.
assert(optDeserialized != boost::none);
auto notePt = optDeserialized.get();
auto notePt = optDeserialized.value();
auto maybe_pa = nd.ivk.address(notePt.d);
assert(static_cast<bool>(maybe_pa));
auto pa = maybe_pa.get();
auto pa = maybe_pa.value();
// skip notes which belong to a different payment address in the wallet
if (!(filterAddresses.empty() || filterAddresses.count(pa))) {
@ -5156,7 +5156,7 @@ void CWallet::GetFilteredNotes(
continue;
}
auto note = notePt.note(nd.ivk).get();
auto note = notePt.note(nd.ivk).value();
saplingEntries.push_back(SaplingNoteEntry {
op, pa, note, notePt.memo(), wtx.GetDepthInMainChain() });
}
@ -5343,11 +5343,11 @@ KeyAddResult AddSpendingKeyToWallet::operator()(const libzcash::SaplingExtendedS
m_wallet->mapSaplingZKeyMetadata[ivk].nCreateTime = std::max((int64_t) 154051200, nTime);
}
if (hdKeypath) {
m_wallet->mapSaplingZKeyMetadata[ivk].hdKeypath = hdKeypath.get();
m_wallet->mapSaplingZKeyMetadata[ivk].hdKeypath = hdKeypath.value();
}
if (seedFpStr) {
uint256 seedFp;
seedFp.SetHex(seedFpStr.get());
seedFp.SetHex(seedFpStr.value());
m_wallet->mapSaplingZKeyMetadata[ivk].seedFp = seedFp;
}
return KeyAdded;

View File

@ -176,7 +176,7 @@ boost::optional<SaplingNote> SaplingNotePlaintext::note(const SaplingIncomingVie
assert(leadbyte == 0x02);
zip_212_enabled = Zip212Enabled::AfterZip212;
};
auto tmp = SaplingNote(d, addr.get().pk_d, value_, rseed, zip_212_enabled);
auto tmp = SaplingNote(d, addr.value().pk_d, value_, rseed, zip_212_enabled);
return tmp;
} else {
return boost::none;
@ -199,7 +199,7 @@ boost::optional<SaplingOutgoingPlaintext> SaplingOutgoingPlaintext::decrypt(
// Deserialize from the plaintext
try {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();
ss << pt.value();
SaplingOutgoingPlaintext ret;
ss >> ret;
assert(ss.size() == 0);
@ -254,7 +254,7 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::attempt_sapling_enc_
SaplingNotePlaintext ret;
try {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << encPlaintext.get();
ss << encPlaintext.value();
ss >> ret;
assert(ss.size() == 0);
return ret;
@ -356,7 +356,7 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::attempt_sapling_enc_
SaplingNotePlaintext ret;
try {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << encPlaintext.get();
ss << encPlaintext.value();
ss >> ret;
assert(ss.size() == 0);
return ret;
@ -421,7 +421,7 @@ boost::optional<SaplingNotePlaintextEncryptionResult> SaplingNotePlaintext::encr
if (!sne) {
return boost::none;
}
auto enc = sne.get();
auto enc = sne.value();
// Create the plaintext
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
@ -435,7 +435,7 @@ boost::optional<SaplingNotePlaintextEncryptionResult> SaplingNotePlaintext::encr
if (!encciphertext) {
return boost::none;
}
return SaplingNotePlaintextEncryptionResult(encciphertext.get(), enc);
return SaplingNotePlaintextEncryptionResult(encciphertext.value(), enc);
}

View File

@ -105,7 +105,7 @@ libzcash::SaplingPaymentAddress SaplingExtendedFullViewingKey::DefaultAddress()
if (!addr) {
throw std::runtime_error("SaplingExtendedFullViewingKey::DefaultAddress(): No valid diversifiers out of 2^88!");
}
return addr.get().second;
return addr.value().second;
}
SaplingExtendedSpendingKey SaplingExtendedSpendingKey::Master(const HDSeed& seed)

View File

@ -374,7 +374,7 @@ CWalletTx CreateSaplingTxWithNoteData(const Consensus::Params& consensusParams,
auto wtx = GetValidSaplingReceive(consensusParams, keyStore, sk, 10);
auto testNote = GetTestSaplingNote(sk.DefaultAddress(), 10);
auto fvk = sk.expsk.full_viewing_key();
auto nullifier = testNote.note.nullifier(fvk, testNote.tree.witness().position()).get();
auto nullifier = testNote.note.nullifier(fvk, testNote.tree.witness().position()).value();
mapSaplingNoteData_t noteDataMap;
SaplingOutPoint outPoint {wtx.GetHash(), 0};
@ -595,7 +595,7 @@ double benchmark_create_sapling_spend()
SaplingNote note(address, GetRand(MAX_MONEY), libzcash::Zip212Enabled::BeforeZip212);
SaplingMerkleTree tree;
auto maybe_cmu = note.cmu();
tree.append(maybe_cmu.get());
tree.append(maybe_cmu.value());
auto anchor = tree.root();
auto witness = tree.witness();
auto maybe_nf = note.nullifier(expsk.full_viewing_key(), witness.position());
@ -653,7 +653,7 @@ double benchmark_create_sapling_output()
throw JSONRPCError(RPC_INTERNAL_ERROR, "SaplingNotePlaintext::encrypt() failed");
}
auto enc = res.get();
auto enc = res.value();
auto encryptor = enc.second;
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);