Replace boost::variant with std::variant

This commit is contained in:
Jack Grigg 2020-07-17 17:19:56 +12:00
parent 6272d92b53
commit 25a225f946
36 changed files with 194 additions and 175 deletions

View File

@ -13,6 +13,7 @@
#include "utilstrencodings.h"
#include <assert.h>
#include <variant>
#include <boost/assign/list_of.hpp>
@ -689,7 +690,7 @@ CScript CChainParams::GetFoundersRewardScriptAtHeight(int nHeight) const {
CTxDestination address = keyIO.DecodeDestination(GetFoundersRewardAddressAtHeight(nHeight).c_str());
assert(IsValidDestination(address));
assert(IsScriptDestination(address));
CScriptID scriptID = boost::get<CScriptID>(address); // address is a boost variant
CScriptID scriptID = std::get<CScriptID>(address); // address is a variant
CScript script = CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
return script;
}

View File

@ -8,8 +8,6 @@
#include <amount.h>
#include <consensus/params.h>
#include <boost/variant.hpp>
namespace Consensus
{

View File

@ -99,7 +99,7 @@ namespace Consensus {
return (nHeight - fundingStreamStartHeight + startPeriodOffset) / nFundingPeriodLength;
}
boost::variant<FundingStream, FundingStreamError> FundingStream::ValidateFundingStream(
std::variant<FundingStream, FundingStreamError> FundingStream::ValidateFundingStream(
const Consensus::Params& params,
const int startHeight,
const int endHeight,
@ -120,7 +120,7 @@ namespace Consensus {
return FundingStream(startHeight, endHeight, addresses);
};
class GetFundingStreamOrThrow: public boost::static_visitor<FundingStream> {
class GetFundingStreamOrThrow {
public:
FundingStream operator()(const FundingStream& fs) const {
return fs;
@ -160,12 +160,12 @@ namespace Consensus {
// If the string is not a valid transparent or Sapling address, we will
// throw here.
addresses.push_back(boost::get<libzcash::SaplingPaymentAddress>(zaddr));
addresses.push_back(std::get<libzcash::SaplingPaymentAddress>(zaddr));
}
}
auto validationResult = FundingStream::ValidateFundingStream(params, startHeight, endHeight, addresses);
return boost::apply_visitor(GetFundingStreamOrThrow(), validationResult);
return std::visit(GetFundingStreamOrThrow(), validationResult);
};
void Params::AddZIP207FundingStream(

View File

@ -11,6 +11,8 @@
#include "key_constants.h"
#include <zcash/address/sapling.hpp>
#include <variant>
#include <boost/optional.hpp>
namespace Consensus {
@ -81,7 +83,7 @@ struct NetworkUpgrade {
boost::optional<uint256> hashActivationBlock;
};
typedef boost::variant<libzcash::SaplingPaymentAddress, CScript> FundingStreamAddress;
typedef std::variant<libzcash::SaplingPaymentAddress, CScript> FundingStreamAddress;
/**
* Index into Params.vFundingStreams.
@ -115,7 +117,7 @@ public:
FundingStream(const FundingStream& fs):
startHeight(fs.startHeight), endHeight(fs.endHeight), addresses(fs.addresses) { }
static boost::variant<FundingStream, FundingStreamError> ValidateFundingStream(
static std::variant<FundingStream, FundingStreamError> ValidateFundingStream(
const Consensus::Params& params,
const int startHeight,
const int endHeight,

View File

@ -3,7 +3,6 @@
#include "utilstrencodings.h"
#include <boost/foreach.hpp>
#include <boost/variant/get.hpp>
#include "zcash/prf.h"
#include "util.h"

View File

@ -4,6 +4,8 @@
#include "utiltest.h"
#include <variant>
#include <gtest/gtest.h>
TEST(Keys, EncodeAndDecodeSapling)
@ -24,8 +26,8 @@ TEST(Keys, EncodeAndDecodeSapling)
auto spendingkey2 = keyIO.DecodeSpendingKey(sk_string);
EXPECT_TRUE(IsValidSpendingKey(spendingkey2));
ASSERT_TRUE(boost::get<libzcash::SaplingExtendedSpendingKey>(&spendingkey2) != nullptr);
auto sk2 = boost::get<libzcash::SaplingExtendedSpendingKey>(spendingkey2);
ASSERT_TRUE(std::get_if<libzcash::SaplingExtendedSpendingKey>(&spendingkey2) != nullptr);
auto sk2 = std::get<libzcash::SaplingExtendedSpendingKey>(spendingkey2);
EXPECT_EQ(sk, sk2);
}
{
@ -38,8 +40,8 @@ TEST(Keys, EncodeAndDecodeSapling)
auto viewingkey2 = keyIO.DecodeViewingKey(vk_string);
EXPECT_TRUE(IsValidViewingKey(viewingkey2));
ASSERT_TRUE(boost::get<libzcash::SaplingExtendedFullViewingKey>(&viewingkey2) != nullptr);
auto extfvk2 = boost::get<libzcash::SaplingExtendedFullViewingKey>(viewingkey2);
ASSERT_TRUE(std::get_if<libzcash::SaplingExtendedFullViewingKey>(&viewingkey2) != nullptr);
auto extfvk2 = std::get<libzcash::SaplingExtendedFullViewingKey>(viewingkey2);
EXPECT_EQ(extfvk, extfvk2);
}
{
@ -53,8 +55,8 @@ TEST(Keys, EncodeAndDecodeSapling)
auto paymentaddr2 = keyIO.DecodePaymentAddress(addr_string);
EXPECT_TRUE(IsValidPaymentAddress(paymentaddr2));
ASSERT_TRUE(boost::get<libzcash::SaplingPaymentAddress>(&paymentaddr2) != nullptr);
auto addr2 = boost::get<libzcash::SaplingPaymentAddress>(paymentaddr2);
ASSERT_TRUE(std::get_if<libzcash::SaplingPaymentAddress>(&paymentaddr2) != nullptr);
auto addr2 = std::get<libzcash::SaplingPaymentAddress>(paymentaddr2);
EXPECT_EQ(addr, addr2);
}
}

View File

@ -6,6 +6,8 @@
#include "miner.h"
#include "util.h"
#include <variant>
TEST(Miner, GetMinerAddress) {
SelectParams(CBaseChainParams::MAIN);
@ -51,8 +53,8 @@ TEST(Miner, GetMinerAddress) {
MinerAddress minerAddress;
GetMinerAddress(minerAddress);
EXPECT_TRUE(IsValidMinerAddress(minerAddress));
EXPECT_TRUE(boost::get<boost::shared_ptr<CReserveScript>>(&minerAddress) != nullptr);
auto coinbaseScript = boost::get<boost::shared_ptr<CReserveScript>>(minerAddress);
EXPECT_TRUE(std::get_if<boost::shared_ptr<CReserveScript>>(&minerAddress) != nullptr);
auto coinbaseScript = std::get<boost::shared_ptr<CReserveScript>>(minerAddress);
EXPECT_EQ(expectedCoinbaseScript, coinbaseScript->reserveScript);
}
@ -62,8 +64,8 @@ TEST(Miner, GetMinerAddress) {
MinerAddress minerAddress;
GetMinerAddress(minerAddress);
EXPECT_TRUE(IsValidMinerAddress(minerAddress));
EXPECT_TRUE(boost::get<boost::shared_ptr<CReserveScript>>(&minerAddress) != nullptr);
auto coinbaseScript = boost::get<boost::shared_ptr<CReserveScript>>(minerAddress);
EXPECT_TRUE(std::get_if<boost::shared_ptr<CReserveScript>>(&minerAddress) != nullptr);
auto coinbaseScript = std::get<boost::shared_ptr<CReserveScript>>(minerAddress);
EXPECT_EQ(expectedCoinbaseScript, coinbaseScript->reserveScript);
}
@ -73,8 +75,8 @@ TEST(Miner, GetMinerAddress) {
MinerAddress minerAddress;
GetMinerAddress(minerAddress);
EXPECT_TRUE(IsValidMinerAddress(minerAddress));
EXPECT_TRUE(boost::get<boost::shared_ptr<CReserveScript>>(&minerAddress) != nullptr);
auto coinbaseScript = boost::get<boost::shared_ptr<CReserveScript>>(minerAddress);
EXPECT_TRUE(std::get_if<boost::shared_ptr<CReserveScript>>(&minerAddress) != nullptr);
auto coinbaseScript = std::get<boost::shared_ptr<CReserveScript>>(minerAddress);
EXPECT_EQ(expectedCoinbaseScript, coinbaseScript->reserveScript);
}
@ -100,7 +102,7 @@ TEST(Miner, GetMinerAddress) {
MinerAddress minerAddress;
GetMinerAddress(minerAddress);
EXPECT_TRUE(IsValidMinerAddress(minerAddress));
EXPECT_TRUE(boost::get<libzcash::SaplingPaymentAddress>(&minerAddress) != nullptr);
EXPECT_TRUE(std::get_if<libzcash::SaplingPaymentAddress>(&minerAddress) != nullptr);
}
// Valid Sapling address with leading whitespace

View File

@ -1080,7 +1080,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Try a Sapling address
auto zaddr = keyIO.DecodePaymentAddress(mapArgs["-mineraddress"]);
if (!IsValidPaymentAddress(zaddr) ||
boost::get<libzcash::SaplingPaymentAddress>(&zaddr) == nullptr)
std::get_if<libzcash::SaplingPaymentAddress>(&zaddr) == nullptr)
{
return InitError(strprintf(
_("Invalid address for -mineraddress=<addr>: '%s' (must be a Sapling or transparent address)"),
@ -1623,11 +1623,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (pwalletMain) {
CTxDestination addr = keyIO.DecodeDestination(mapArgs["-mineraddress"]);
if (IsValidDestination(addr)) {
CKeyID keyID = boost::get<CKeyID>(addr);
CKeyID keyID = std::get<CKeyID>(addr);
minerAddressInLocalWallet = pwalletMain->HaveKey(keyID);
} else {
auto zaddr = keyIO.DecodePaymentAddress(mapArgs["-mineraddress"]);
minerAddressInLocalWallet = boost::apply_visitor(
minerAddressInLocalWallet = std::visit(
HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
}
}

View File

@ -10,16 +10,14 @@
#include <script/script.h>
#include <utilstrencodings.h>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <assert.h>
#include <string.h>
#include <algorithm>
#include <variant>
namespace
{
class DestinationEncoder : public boost::static_visitor<std::string>
class DestinationEncoder
{
private:
const KeyConstants& keyConstants;
@ -44,7 +42,7 @@ public:
std::string operator()(const CNoDestination& no) const { return {}; }
};
class PaymentAddressEncoder : public boost::static_visitor<std::string>
class PaymentAddressEncoder
{
private:
const KeyConstants& keyConstants;
@ -77,7 +75,7 @@ public:
std::string operator()(const libzcash::InvalidEncoding& no) const { return {}; }
};
class ViewingKeyEncoder : public boost::static_visitor<std::string>
class ViewingKeyEncoder
{
private:
const KeyConstants& keyConstants;
@ -115,7 +113,7 @@ public:
std::string operator()(const libzcash::InvalidEncoding& no) const { return {}; }
};
class SpendingKeyEncoder : public boost::static_visitor<std::string>
class SpendingKeyEncoder
{
private:
const KeyConstants& keyConstants;
@ -264,7 +262,7 @@ std::string KeyIO::EncodeExtKey(const CExtKey& key)
std::string KeyIO::EncodeDestination(const CTxDestination& dest)
{
return boost::apply_visitor(DestinationEncoder(keyConstants), dest);
return std::visit(DestinationEncoder(keyConstants), dest);
}
bool KeyIO::IsValidDestinationString(const std::string& str)
@ -274,7 +272,7 @@ bool KeyIO::IsValidDestinationString(const std::string& str)
std::string KeyIO::EncodePaymentAddress(const libzcash::PaymentAddress& zaddr)
{
return boost::apply_visitor(PaymentAddressEncoder(keyConstants), zaddr);
return std::visit(PaymentAddressEncoder(keyConstants), zaddr);
}
template<typename T1, typename T2, typename T3>
@ -336,7 +334,7 @@ bool KeyIO::IsValidPaymentAddressString(const std::string& str) {
std::string KeyIO::EncodeViewingKey(const libzcash::ViewingKey& vk)
{
return boost::apply_visitor(ViewingKeyEncoder(keyConstants), vk);
return std::visit(ViewingKeyEncoder(keyConstants), vk);
}
libzcash::ViewingKey KeyIO::DecodeViewingKey(const std::string& str)
@ -353,7 +351,7 @@ libzcash::ViewingKey KeyIO::DecodeViewingKey(const std::string& str)
std::string KeyIO::EncodeSpendingKey(const libzcash::SpendingKey& zkey)
{
return boost::apply_visitor(SpendingKeyEncoder(keyConstants), zkey);
return std::visit(SpendingKeyEncoder(keyConstants), zkey);
}
libzcash::SpendingKey KeyIO::DecodeSpendingKey(const std::string& str)

View File

@ -15,7 +15,6 @@
#include "zcash/NoteEncryption.hpp"
#include <boost/signals2/signal.hpp>
#include <boost/variant.hpp>
/** A virtual base class for key stores */
class CKeyStore

View File

@ -40,6 +40,7 @@
#include <algorithm>
#include <atomic>
#include <sstream>
#include <variant>
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
@ -955,7 +956,7 @@ bool ContextualCheckTransaction(
if (canopyActive) {
libzcash::SaplingPaymentAddress zaddr(encPlaintext->d, outPlaintext->pk_d);
for (auto it = fundingStreamElements.begin(); it != fundingStreamElements.end(); ++it) {
const libzcash::SaplingPaymentAddress* streamAddr = boost::get<libzcash::SaplingPaymentAddress>(&(it->first));
const libzcash::SaplingPaymentAddress* streamAddr = std::get_if<libzcash::SaplingPaymentAddress>(&(it->first));
if (streamAddr && zaddr == *streamAddr && encPlaintext->value() == it->second) {
fundingStreamElements.erase(it);
break;
@ -990,7 +991,7 @@ bool ContextualCheckTransaction(
// Detect transparent funding streams.
for (const CTxOut& output : tx.vout) {
for (auto it = fundingStreamElements.begin(); it != fundingStreamElements.end(); ++it) {
const CScript* taddr = boost::get<CScript>(&(it->first));
const CScript* taddr = std::get_if<CScript>(&(it->first));
if (taddr && output.scriptPubKey == *taddr && output.nValue == it->second) {
fundingStreamElements.erase(it);
break;

View File

@ -117,10 +117,10 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
}
bool IsValidMinerAddress(const MinerAddress& minerAddr) {
return minerAddr.which() != 0;
return !std::holds_alternative<InvalidMinerAddress>(minerAddr);
}
class AddFundingStreamValueToTx : public boost::static_visitor<bool>
class AddFundingStreamValueToTx
{
private:
CMutableTransaction &mtx;
@ -156,7 +156,7 @@ public:
};
class AddOutputsToCoinbaseTxAndSign : public boost::static_visitor<>
class AddOutputsToCoinbaseTxAndSign
{
private:
CMutableTransaction &mtx;
@ -192,7 +192,7 @@ public:
for (Consensus::FundingStreamElement fselem : fundingStreamElements) {
miner_reward -= fselem.second;
bool added = boost::apply_visitor(AddFundingStreamValueToTx(mtx, ctx, fselem.second, GetZip212Flag()), fselem.first);
bool added = std::visit(AddFundingStreamValueToTx(mtx, ctx, fselem.second, GetZip212Flag()), fselem.first);
if (!added) {
librustzcash_sapling_proving_ctx_free(ctx);
throw new std::runtime_error("Failed to add funding stream output.");
@ -579,7 +579,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre
txNew.nExpiryHeight = 0;
// Add outputs and sign
boost::apply_visitor(
std::visit(
AddOutputsToCoinbaseTxAndSign(txNew, chainparams, nHeight, nFees),
minerAddress);
@ -652,7 +652,7 @@ void GetMinerAddress(MinerAddress &minerAddress)
CTxDestination addr = keyIO.DecodeDestination(mAddrArg);
if (IsValidDestination(addr)) {
boost::shared_ptr<MinerAddressScript> mAddr(new MinerAddressScript());
CKeyID keyID = boost::get<CKeyID>(addr);
CKeyID keyID = std::get<CKeyID>(addr);
mAddr->reserveScript = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
minerAddress = mAddr;
@ -660,8 +660,8 @@ void GetMinerAddress(MinerAddress &minerAddress)
// Try a Sapling address
auto zaddr = keyIO.DecodePaymentAddress(mAddrArg);
if (IsValidPaymentAddress(zaddr)) {
if (boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
minerAddress = boost::get<libzcash::SaplingPaymentAddress>(zaddr);
if (std::get_if<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
minerAddress = std::get<libzcash::SaplingPaymentAddress>(zaddr);
}
}
}
@ -837,7 +837,7 @@ void static BitcoinMiner(const CChainParams& chainparams)
cancelSolver = false;
}
SetThreadPriority(THREAD_PRIORITY_LOWEST);
boost::apply_visitor(KeepMinerAddress(), minerAddress);
std::visit(KeepMinerAddress(), minerAddress);
// In regression test mode, stop mining after a block is found.
if (chainparams.MineBlocksOnDemand()) {

View File

@ -10,6 +10,7 @@
#include <boost/optional.hpp>
#include <stdint.h>
#include <variant>
class CBlockIndex;
class CChainParams;
@ -27,9 +28,9 @@ public:
friend bool operator<(const InvalidMinerAddress &a, const InvalidMinerAddress &b) { return true; }
};
typedef boost::variant<InvalidMinerAddress, libzcash::SaplingPaymentAddress, boost::shared_ptr<CReserveScript>> MinerAddress;
typedef std::variant<InvalidMinerAddress, libzcash::SaplingPaymentAddress, boost::shared_ptr<CReserveScript>> MinerAddress;
class KeepMinerAddress : public boost::static_visitor<>
class KeepMinerAddress
{
public:
KeepMinerAddress() {}

View File

@ -14,8 +14,7 @@
#include "consensus/consensus.h"
#include <array>
#include <boost/variant.hpp>
#include <variant>
#include "zcash/NoteEncryption.hpp"
#include "zcash/Zcash.h"
@ -136,7 +135,7 @@ public:
};
template <typename Stream>
class SproutProofSerializer : public boost::static_visitor<>
class SproutProofSerializer
{
Stream& s;
bool useGroth;
@ -165,7 +164,7 @@ template<typename Stream, typename T>
inline void SerReadWriteSproutProof(Stream& s, const T& proof, bool useGroth, CSerActionSerialize ser_action)
{
auto ps = SproutProofSerializer<Stream>(s, useGroth);
boost::apply_visitor(ps, proof);
std::visit(ps, proof);
}
template<typename Stream, typename T>

View File

@ -6,10 +6,11 @@
#include <zcash/JoinSplit.hpp>
#include <boost/variant.hpp>
#include <variant>
#include <librustzcash.h>
class SproutProofVerifier : public boost::static_visitor<bool>
class SproutProofVerifier
{
ProofVerifier& verifier;
const uint256& joinSplitPubKey;
@ -66,5 +67,5 @@ bool ProofVerifier::VerifySprout(
}
auto pv = SproutProofVerifier(*this, joinSplitPubKey, jsdesc);
return boost::apply_visitor(pv, jsdesc.proof);
return std::visit(pv, jsdesc.proof);
}

View File

@ -27,6 +27,7 @@
#endif
#include <stdint.h>
#include <variant>
#include <boost/assign/list_of.hpp>
#include <boost/shared_ptr.hpp>
@ -255,7 +256,7 @@ endloop:
blockHashes.push_back(pblock->GetHash().GetHex());
//mark miner address as important because it was used at least for one coinbase output
boost::apply_visitor(KeepMinerAddress(), minerAddress);
std::visit(KeepMinerAddress(), minerAddress);
}
return blockHashes;
}
@ -624,7 +625,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
// Mark script as important because it was used at least for one coinbase output
boost::apply_visitor(KeepMinerAddress(), minerAddress);
std::visit(KeepMinerAddress(), minerAddress);
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;

View File

@ -19,6 +19,7 @@
#endif
#include <stdint.h>
#include <variant>
#include <boost/assign/list_of.hpp>
@ -110,7 +111,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
}
#ifdef ENABLE_WALLET
class DescribeAddressVisitor : public boost::static_visitor<UniValue>
class DescribeAddressVisitor
{
public:
UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); }
@ -199,7 +200,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
ret.pushKV("ismine", (mine & ISMINE_SPENDABLE) ? true : false);
ret.pushKV("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true: false);
UniValue detail = boost::apply_visitor(DescribeAddressVisitor(), dest);
UniValue detail = std::visit(DescribeAddressVisitor(), dest);
ret.pushKVs(detail);
if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
ret.pushKV("account", pwalletMain->mapAddressBook[dest].name);
@ -209,7 +210,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
}
class DescribePaymentAddressVisitor : public boost::static_visitor<UniValue>
class DescribePaymentAddressVisitor
{
public:
UniValue operator()(const libzcash::InvalidEncoding &zaddr) const { return UniValue(UniValue::VOBJ); }
@ -283,7 +284,7 @@ UniValue z_validateaddress(const UniValue& params, bool fHelp)
if (isValid)
{
ret.pushKV("address", strAddress);
UniValue detail = boost::apply_visitor(DescribePaymentAddressVisitor(), address);
UniValue detail = std::visit(DescribePaymentAddressVisitor(), address);
ret.pushKVs(detail);
}
return ret;
@ -319,7 +320,7 @@ CScript _createmultisig_redeemScript(const UniValue& params)
// Case 1: Bitcoin address and we have full public key:
CTxDestination dest = keyIO.DecodeDestination(ks);
if (pwalletMain && IsValidDestination(dest)) {
const CKeyID *keyID = boost::get<CKeyID>(&dest);
const CKeyID *keyID = std::get_if<CKeyID>(&dest);
if (!keyID) {
throw std::runtime_error(strprintf("%s does not refer to a key", ks));
}
@ -434,7 +435,7 @@ UniValue verifymessage(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
}
const CKeyID *keyID = boost::get<CKeyID>(&destination);
const CKeyID *keyID = std::get_if<CKeyID>(&destination);
if (!keyID) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
}
@ -534,13 +535,13 @@ static bool getIndexKey(
return false;
}
if (IsKeyDestination(dest)) {
auto x = boost::get<CKeyID>(&dest);
auto x = std::get_if<CKeyID>(&dest);
memcpy(&hashBytes, x->begin(), 20);
type = CScript::P2PKH;
return true;
}
if (IsScriptDestination(dest)) {
auto x = boost::get<CScriptID>(&dest);
auto x = std::get_if<CScriptID>(&dest);
memcpy(&hashBytes, x->begin(), 20);
type = CScript::P2SH;
return true;

View File

@ -26,6 +26,7 @@
#endif
#include <stdint.h>
#include <variant>
#include <boost/assign/list_of.hpp>
@ -103,7 +104,7 @@ UniValue TxJoinSplitToJSON(const CTransaction& tx) {
CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION);
auto ps = SproutProofSerializer<CDataStream>(ssProof, useGroth);
boost::apply_visitor(ps, jsdescription.proof);
std::visit(ps, jsdescription.proof);
joinsplit.pushKV("proof", HexStr(ssProof.begin(), ssProof.end()));
{

View File

@ -226,7 +226,7 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto
namespace
{
class CScriptVisitor : public boost::static_visitor<bool>
class CScriptVisitor
{
private:
CScript *script;
@ -256,7 +256,7 @@ CScript GetScriptForDestination(const CTxDestination& dest)
{
CScript script;
boost::apply_visitor(CScriptVisitor(&script), dest);
std::visit(CScriptVisitor(&script), dest);
return script;
}
@ -277,15 +277,15 @@ CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys)
}
bool IsValidDestination(const CTxDestination& dest) {
return dest.which() != 0;
return !std::holds_alternative<CNoDestination>(dest);
}
bool IsKeyDestination(const CTxDestination& dest) {
return dest.which() == 1;
return std::holds_alternative<CKeyID>(dest);
}
bool IsScriptDestination(const CTxDestination& dest) {
return dest.which() == 2;
return std::holds_alternative<CScriptID>(dest);
}
// insightexplorer

View File

@ -9,7 +9,7 @@
#include "script/interpreter.h"
#include "uint256.h"
#include <boost/variant.hpp>
#include <variant>
#include <stdint.h>
@ -66,6 +66,7 @@ enum txnouttype
class CNoDestination {
public:
friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
friend bool operator!=(const CNoDestination &a, const CNoDestination &b) { return false; }
friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
};
@ -76,7 +77,7 @@ public:
* * CScriptID: TX_SCRIPTHASH destination
* A CTxDestination is the internal data type encoded in a bitcoin address
*/
typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
typedef std::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
/** Check whether a CTxDestination is a CNoDestination. */
bool IsValidDestination(const CTxDestination& dest);

View File

@ -16,6 +16,7 @@
#include "zcash/Address.hpp"
#include <string>
#include <variant>
#include <vector>
#include <boost/test/unit_test.hpp>
@ -202,8 +203,8 @@ BOOST_AUTO_TEST_CASE(zc_address_test)
auto spendingkey2 = keyIO.DecodeSpendingKey(sk_string);
BOOST_CHECK(IsValidSpendingKey(spendingkey2));
BOOST_ASSERT(boost::get<SproutSpendingKey>(&spendingkey2) != nullptr);
auto sk2 = boost::get<SproutSpendingKey>(spendingkey2);
BOOST_ASSERT(std::get_if<SproutSpendingKey>(&spendingkey2) != nullptr);
auto sk2 = std::get<SproutSpendingKey>(spendingkey2);
BOOST_CHECK(sk.inner() == sk2.inner());
}
{
@ -217,8 +218,8 @@ BOOST_AUTO_TEST_CASE(zc_address_test)
auto paymentaddr2 = keyIO.DecodePaymentAddress(addr_string);
BOOST_ASSERT(IsValidPaymentAddress(paymentaddr2));
BOOST_ASSERT(boost::get<SproutPaymentAddress>(&paymentaddr2) != nullptr);
auto addr2 = boost::get<SproutPaymentAddress>(paymentaddr2);
BOOST_ASSERT(std::get_if<SproutPaymentAddress>(&paymentaddr2) != nullptr);
auto addr2 = std::get<SproutPaymentAddress>(paymentaddr2);
BOOST_CHECK(addr.a_pk == addr2.a_pk);
BOOST_CHECK(addr.pk_enc == addr2.pk_enc);
}
@ -241,8 +242,8 @@ BOOST_AUTO_TEST_CASE(zs_address_test)
auto spendingkey2 = keyIO.DecodeSpendingKey(sk_string);
BOOST_CHECK(IsValidSpendingKey(spendingkey2));
BOOST_ASSERT(boost::get<SaplingExtendedSpendingKey>(&spendingkey2) != nullptr);
auto sk2 = boost::get<SaplingExtendedSpendingKey>(spendingkey2);
BOOST_ASSERT(std::get_if<SaplingExtendedSpendingKey>(&spendingkey2) != nullptr);
auto sk2 = std::get<SaplingExtendedSpendingKey>(spendingkey2);
BOOST_CHECK(sk == sk2);
}
{
@ -254,8 +255,8 @@ BOOST_AUTO_TEST_CASE(zs_address_test)
auto paymentaddr2 = keyIO.DecodePaymentAddress(addr_string);
BOOST_CHECK(IsValidPaymentAddress(paymentaddr2));
BOOST_ASSERT(boost::get<SaplingPaymentAddress>(&paymentaddr2) != nullptr);
auto addr2 = boost::get<SaplingPaymentAddress>(paymentaddr2);
BOOST_ASSERT(std::get_if<SaplingPaymentAddress>(&paymentaddr2) != nullptr);
auto addr2 = std::get<SaplingPaymentAddress>(paymentaddr2);
BOOST_CHECK(addr == addr2);
}
}

View File

@ -10,6 +10,8 @@
#include "script/standard.h"
#include "test/test_bitcoin.h"
#include <variant>
#include <boost/test/unit_test.hpp>
@ -175,23 +177,23 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
s.clear();
s << ToByteVector(pubkey) << OP_CHECKSIG;
BOOST_CHECK(ExtractDestination(s, address));
BOOST_CHECK(boost::get<CKeyID>(&address) &&
*boost::get<CKeyID>(&address) == pubkey.GetID());
BOOST_CHECK(std::get_if<CKeyID>(&address) &&
std::get<CKeyID>(address) == pubkey.GetID());
// TX_PUBKEYHASH
s.clear();
s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
BOOST_CHECK(ExtractDestination(s, address));
BOOST_CHECK(boost::get<CKeyID>(&address) &&
*boost::get<CKeyID>(&address) == pubkey.GetID());
BOOST_CHECK(std::get_if<CKeyID>(&address) &&
std::get<CKeyID>(address) == pubkey.GetID());
// TX_SCRIPTHASH
CScript redeemScript(s); // initialize with leftover P2PKH script
s.clear();
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
BOOST_CHECK(ExtractDestination(s, address));
BOOST_CHECK(boost::get<CScriptID>(&address) &&
*boost::get<CScriptID>(&address) == CScriptID(redeemScript));
BOOST_CHECK(std::get_if<CScriptID>(&address) &&
std::get<CScriptID>(address) == CScriptID(redeemScript));
// TX_MULTISIG
s.clear();
@ -235,8 +237,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
BOOST_CHECK_EQUAL(whichType, TX_PUBKEY);
BOOST_CHECK_EQUAL(addresses.size(), 1);
BOOST_CHECK_EQUAL(nRequired, 1);
BOOST_CHECK(boost::get<CKeyID>(&addresses[0]) &&
*boost::get<CKeyID>(&addresses[0]) == pubkeys[0].GetID());
BOOST_CHECK(std::get_if<CKeyID>(&addresses[0]) &&
std::get<CKeyID>(addresses[0]) == pubkeys[0].GetID());
// TX_PUBKEYHASH
s.clear();
@ -245,8 +247,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
BOOST_CHECK_EQUAL(whichType, TX_PUBKEYHASH);
BOOST_CHECK_EQUAL(addresses.size(), 1);
BOOST_CHECK_EQUAL(nRequired, 1);
BOOST_CHECK(boost::get<CKeyID>(&addresses[0]) &&
*boost::get<CKeyID>(&addresses[0]) == pubkeys[0].GetID());
BOOST_CHECK(std::get_if<CKeyID>(&addresses[0]) &&
std::get<CKeyID>(addresses[0]) == pubkeys[0].GetID());
// TX_SCRIPTHASH
CScript redeemScript(s); // initialize with leftover P2PKH script
@ -256,8 +258,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
BOOST_CHECK_EQUAL(whichType, TX_SCRIPTHASH);
BOOST_CHECK_EQUAL(addresses.size(), 1);
BOOST_CHECK_EQUAL(nRequired, 1);
BOOST_CHECK(boost::get<CScriptID>(&addresses[0]) &&
*boost::get<CScriptID>(&addresses[0]) == CScriptID(redeemScript));
BOOST_CHECK(std::get_if<CScriptID>(&addresses[0]) &&
std::get<CScriptID>(addresses[0]) == CScriptID(redeemScript));
// TX_MULTISIG
s.clear();
@ -269,10 +271,10 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
BOOST_CHECK_EQUAL(whichType, TX_MULTISIG);
BOOST_CHECK_EQUAL(addresses.size(), 2);
BOOST_CHECK_EQUAL(nRequired, 2);
BOOST_CHECK(boost::get<CKeyID>(&addresses[0]) &&
*boost::get<CKeyID>(&addresses[0]) == pubkeys[0].GetID());
BOOST_CHECK(boost::get<CKeyID>(&addresses[1]) &&
*boost::get<CKeyID>(&addresses[1]) == pubkeys[1].GetID());
BOOST_CHECK(std::get_if<CKeyID>(&addresses[0]) &&
std::get<CKeyID>(addresses[0]) == pubkeys[0].GetID());
BOOST_CHECK(std::get_if<CKeyID>(&addresses[1]) &&
std::get<CKeyID>(addresses[1]) == pubkeys[1].GetID());
// TX_NULL_DATA
s.clear();

View File

@ -12,7 +12,6 @@
#include "utilmoneystr.h"
#include "zcash/Note.hpp"
#include <boost/variant.hpp>
#include <librustzcash.h>
SpendDescriptionInfo::SpendDescriptionInfo(

View File

@ -34,6 +34,7 @@
#include <iostream>
#include <string>
#include <thread>
#include <variant>
using namespace libzcash;
@ -327,7 +328,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
std::string zaddr = std::get<0>(recipient_);
std::string memo = std::get<1>(recipient_);
std::array<unsigned char, ZC_MEMO_SIZE> hexMemo = get_memo_from_hex_string(memo);
auto saplingPaymentAddress = boost::get<libzcash::SaplingPaymentAddress>(&toPaymentAddress_);
auto saplingPaymentAddress = std::get_if<libzcash::SaplingPaymentAddress>(&toPaymentAddress_);
if (saplingPaymentAddress == nullptr) {
// This should never happen as we have already determined that the payment is to sapling
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Could not get Sapling payment address.");
@ -400,7 +401,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
info.vpub_old = sendAmount;
info.vpub_new = 0;
JSOutput jso = JSOutput(boost::get<libzcash::SproutPaymentAddress>(toPaymentAddress_), sendAmount);
JSOutput jso = JSOutput(std::get<libzcash::SproutPaymentAddress>(toPaymentAddress_), sendAmount);
if (hexMemo.size() > 0) {
jso.memo = get_memo_from_hex_string(hexMemo);
}
@ -687,7 +688,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
// If this is the final output, set the target and memo
if (isToZaddr_ && vpubNewProcessed) {
outputType = "target";
jso.addr = boost::get<libzcash::SproutPaymentAddress>(toPaymentAddress_);
jso.addr = std::get<libzcash::SproutPaymentAddress>(toPaymentAddress_);
if (!hexMemo.empty()) {
jso.memo = get_memo_from_hex_string(hexMemo);
}

View File

@ -1,5 +1,4 @@
#include "assert.h"
#include "boost/variant/static_visitor.hpp"
#include "asyncrpcoperation_saplingmigration.h"
#include "init.h"
#include "key_io.h"
@ -12,6 +11,8 @@
#include "utilmoneystr.h"
#include "wallet.h"
#include <variant>
const CAmount FEE = 10000;
const int MIGRATION_EXPIRY_DELTA = 450;
@ -196,7 +197,7 @@ libzcash::SaplingPaymentAddress AsyncRPCOperation_saplingmigration::getMigration
if (mapArgs.count("-migrationdestaddress")) {
std::string migrationDestAddress = mapArgs["-migrationdestaddress"];
auto address = keyIO.DecodePaymentAddress(migrationDestAddress);
auto saplingAddress = boost::get<libzcash::SaplingPaymentAddress>(&address);
auto saplingAddress = std::get_if<libzcash::SaplingPaymentAddress>(&address);
assert(saplingAddress != nullptr); // This is checked in init.cpp
return *saplingAddress;
}

View File

@ -36,6 +36,7 @@
#include <chrono>
#include <thread>
#include <string>
#include <variant>
using namespace libzcash;
@ -97,13 +98,13 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
auto address = keyIO.DecodePaymentAddress(fromAddress);
if (IsValidPaymentAddress(address)) {
// We don't need to lock on the wallet as spending key related methods are thread-safe
if (!boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), address)) {
if (!std::visit(HaveSpendingKeyForPaymentAddress(pwalletMain), address)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, no spending key found for zaddr");
}
isfromzaddr_ = true;
frompaymentaddress_ = address;
spendingkey_ = boost::apply_visitor(GetSpendingKeyForPaymentAddress(pwalletMain), address).get();
spendingkey_ = std::visit(GetSpendingKeyForPaymentAddress(pwalletMain), address).get();
} else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address");
}
@ -362,7 +363,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
SaplingExpandedSpendingKey expsk;
uint256 ovk;
if (isfromzaddr_) {
auto sk = boost::get<libzcash::SaplingExtendedSpendingKey>(spendingkey_);
auto sk = std::get<libzcash::SaplingExtendedSpendingKey>(spendingkey_);
expsk = sk.expsk;
ovk = expsk.full_viewing_key().ovk;
} else {
@ -430,8 +431,8 @@ bool AsyncRPCOperation_sendmany::main_impl() {
auto hexMemo = r.memo;
auto addr = keyIO.DecodePaymentAddress(address);
assert(boost::get<libzcash::SaplingPaymentAddress>(&addr) != nullptr);
auto to = boost::get<libzcash::SaplingPaymentAddress>(addr);
assert(std::get_if<libzcash::SaplingPaymentAddress>(&addr) != nullptr);
auto to = std::get<libzcash::SaplingPaymentAddress>(addr);
auto memo = get_memo_from_hex_string(hexMemo);
@ -589,7 +590,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
zOutputsDeque.pop_front();
PaymentAddress pa = keyIO.DecodePaymentAddress(address);
JSOutput jso = JSOutput(boost::get<libzcash::SproutPaymentAddress>(pa), value);
JSOutput jso = JSOutput(std::get<libzcash::SproutPaymentAddress>(pa), value);
if (hexMemo.size() > 0) {
jso.memo = get_memo_from_hex_string(hexMemo);
}
@ -692,7 +693,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
intermediates.insert(std::make_pair(tree.root(), tree)); // chained js are interstitial (found in between block boundaries)
// Decrypt the change note's ciphertext to retrieve some data we need
ZCNoteDecryption decryptor(boost::get<libzcash::SproutSpendingKey>(spendingkey_).receiving_key());
ZCNoteDecryption decryptor(std::get<libzcash::SproutSpendingKey>(spendingkey_).receiving_key());
auto hSig = ZCJoinSplit::h_sig(
prevJoinSplit.randomSeed,
prevJoinSplit.nullifiers,
@ -705,7 +706,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
hSig,
(unsigned char) changeOutputIndex);
SproutNote note = plaintext.note(boost::get<libzcash::SproutPaymentAddress>(frompaymentaddress_));
SproutNote note = plaintext.note(std::get<libzcash::SproutPaymentAddress>(frompaymentaddress_));
info.notes.push_back(note);
jsInputValue += plaintext.value();
@ -855,7 +856,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
} else {
PaymentAddress pa = keyIO.DecodePaymentAddress(address);
// If we are here, we know we have no Sapling outputs.
JSOutput jso = JSOutput(boost::get<libzcash::SproutPaymentAddress>(pa), value);
JSOutput jso = JSOutput(std::get<libzcash::SproutPaymentAddress>(pa), value);
if (hexMemo.size() > 0) {
jso.memo = get_memo_from_hex_string(hexMemo);
}
@ -864,7 +865,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
// create output for any change
if (jsChange>0) {
info.vjsout.push_back(JSOutput(boost::get<libzcash::SproutPaymentAddress>(frompaymentaddress_), jsChange));
info.vjsout.push_back(JSOutput(std::get<libzcash::SproutPaymentAddress>(frompaymentaddress_), jsChange));
LogPrint("zrpcunsafe", "%s: generating note for change (amount=%s)\n",
getId(),
@ -1036,7 +1037,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
if (!witnesses[i]) {
throw runtime_error("joinsplit input could not be found in tree");
}
info.vjsin.push_back(JSInput(*witnesses[i], info.notes[i], boost::get<libzcash::SproutSpendingKey>(spendingkey_)));
info.vjsin.push_back(JSInput(*witnesses[i], info.notes[i], std::get<libzcash::SproutSpendingKey>(spendingkey_)));
}
// Make sure there are two inputs and two outputs

View File

@ -36,6 +36,7 @@
#include <chrono>
#include <thread>
#include <string>
#include <variant>
using namespace libzcash;
@ -196,7 +197,7 @@ bool AsyncRPCOperation_shieldcoinbase::main_impl() {
LogPrint("zrpc", "%s: spending %s to shield %s with fee %s\n",
getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee));
return boost::apply_visitor(ShieldToAddress(this, sendAmount), tozaddr_);
return std::visit(ShieldToAddress(this, sendAmount), tozaddr_);
}
bool ShieldToAddress::operator()(const libzcash::SproutPaymentAddress &zaddr) const {

View File

@ -95,7 +95,7 @@ private:
std::vector<PaymentDisclosureKeyInfo> paymentDisclosureData_;
};
class ShieldToAddress : public boost::static_visitor<bool>
class ShieldToAddress
{
private:
AsyncRPCOperation_shieldcoinbase *m_op;

View File

@ -16,6 +16,7 @@
#include <fstream>
#include <stdint.h>
#include <variant>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@ -399,7 +400,7 @@ UniValue importwallet_impl(const UniValue& params, bool fImportZKeys)
boost::optional<std::string> hdKeypath = (vstr.size() > 3) ? boost::optional<std::string>(vstr[2]) : boost::none;
boost::optional<std::string> seedFpStr = (vstr.size() > 3) ? boost::optional<std::string>(vstr[3]) : boost::none;
if (IsValidSpendingKey(spendingkey)) {
auto addResult = boost::apply_visitor(
auto addResult = std::visit(
AddSpendingKeyToWallet(pwalletMain, Params().GetConsensus(), nTime, hdKeypath, seedFpStr, true), spendingkey);
if (addResult == KeyAlreadyExists){
LogPrint("zrpc", "Skipping import of zaddr (key already present)\n");
@ -501,7 +502,7 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address");
}
const CKeyID *keyID = boost::get<CKeyID>(&dest);
const CKeyID *keyID = std::get_if<CKeyID>(&dest);
if (!keyID) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
}
@ -753,13 +754,13 @@ UniValue z_importkey(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid spending key");
}
auto addrInfo = boost::apply_visitor(libzcash::AddressInfoFromSpendingKey{}, spendingkey);
auto addrInfo = std::visit(libzcash::AddressInfoFromSpendingKey{}, spendingkey);
UniValue result(UniValue::VOBJ);
result.pushKV("type", addrInfo.first);
result.pushKV("address", keyIO.EncodePaymentAddress(addrInfo.second));
// Sapling support
auto addResult = boost::apply_visitor(AddSpendingKeyToWallet(pwalletMain, Params().GetConsensus()), spendingkey);
auto addResult = std::visit(AddSpendingKeyToWallet(pwalletMain, Params().GetConsensus()), spendingkey);
if (addResult == KeyAlreadyExists && fIgnoreExistingKey) {
return result;
}
@ -848,12 +849,12 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid viewing key");
}
auto addrInfo = boost::apply_visitor(libzcash::AddressInfoFromViewingKey{}, viewingkey);
auto addrInfo = std::visit(libzcash::AddressInfoFromViewingKey{}, viewingkey);
UniValue result(UniValue::VOBJ);
result.pushKV("type", addrInfo.first);
result.pushKV("address", keyIO.EncodePaymentAddress(addrInfo.second));
auto addResult = boost::apply_visitor(AddViewingKeyToWallet(pwalletMain), viewingkey);
auto addResult = std::visit(AddViewingKeyToWallet(pwalletMain), viewingkey);
if (addResult == SpendingKeyExists) {
throw JSONRPCError(
RPC_WALLET_ERROR,
@ -907,7 +908,7 @@ UniValue z_exportkey(const UniValue& params, bool fHelp)
}
// Sapling support
auto sk = boost::apply_visitor(GetSpendingKeyForPaymentAddress(pwalletMain), address);
auto sk = std::visit(GetSpendingKeyForPaymentAddress(pwalletMain), address);
if (!sk) {
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr");
}
@ -945,7 +946,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr");
}
auto vk = boost::apply_visitor(GetViewingKeyForPaymentAddress(pwalletMain), address);
auto vk = std::visit(GetViewingKeyForPaymentAddress(pwalletMain), address);
if (vk) {
return keyIO.EncodeViewingKey(vk.get());
} else {

View File

@ -44,6 +44,7 @@
#include <univalue.h>
#include <numeric>
#include <variant>
using namespace std;
@ -582,7 +583,7 @@ UniValue signmessage(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
}
const CKeyID *keyID = boost::get<CKeyID>(&dest);
const CKeyID *keyID = std::get_if<CKeyID>(&dest);
if (!keyID) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
}
@ -2501,7 +2502,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
entry.pushKV("account", pwalletMain->mapAddressBook[address].name);
if (scriptPubKey.IsPayToScriptHash()) {
const CScriptID& hash = boost::get<CScriptID>(address);
const CScriptID& hash = std::get<CScriptID>(address);
CScript redeemScript;
if (pwalletMain->GetCScript(hash, redeemScript))
entry.pushKV("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()));
@ -2613,7 +2614,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
if (!IsValidPaymentAddress(zaddr)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, address is not a valid zaddr: ") + address);
}
auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
auto hasSpendingKey = std::visit(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
if (!fIncludeWatchonly && !hasSpendingKey) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, spending key for address does not belong to wallet: ") + address);
}
@ -2937,10 +2938,10 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
if (!IsValidSpendingKey(spendingkey)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid spending key");
}
if (boost::get<libzcash::SproutSpendingKey>(&spendingkey) == nullptr) {
if (std::get_if<libzcash::SproutSpendingKey>(&spendingkey) == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Only works with Sprout spending keys");
}
SproutSpendingKey k = boost::get<libzcash::SproutSpendingKey>(spendingkey);
SproutSpendingKey k = std::get<libzcash::SproutSpendingKey>(spendingkey);
uint256 epk;
unsigned char nonce;
@ -3062,10 +3063,10 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
if (!IsValidSpendingKey(spendingkey)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid spending key");
}
if (boost::get<libzcash::SproutSpendingKey>(&spendingkey) == nullptr) {
if (std::get_if<libzcash::SproutSpendingKey>(&spendingkey) == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Only works with Sprout spending keys");
}
SproutSpendingKey k = boost::get<libzcash::SproutSpendingKey>(spendingkey);
SproutSpendingKey k = std::get<libzcash::SproutSpendingKey>(spendingkey);
keys.push_back(k);
@ -3110,12 +3111,12 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
if (!IsValidPaymentAddress(addrTo)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid recipient address.");
}
if (boost::get<libzcash::SproutPaymentAddress>(&addrTo) == nullptr) {
if (std::get_if<libzcash::SproutPaymentAddress>(&addrTo) == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Only works with Sprout payment addresses");
}
CAmount nAmount = AmountFromValue(outputs[name_]);
vjsout.push_back(JSOutput(boost::get<libzcash::SproutPaymentAddress>(addrTo), nAmount));
vjsout.push_back(JSOutput(std::get<libzcash::SproutPaymentAddress>(addrTo), nAmount));
}
while (vjsout.size() < ZC_NUM_JS_OUTPUTS) {
@ -3457,7 +3458,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
}
// Visitor to support Sprout and Sapling addrs
if (!boost::apply_visitor(PaymentAddressBelongsToWallet(pwalletMain), zaddr)) {
if (!std::visit(PaymentAddressBelongsToWallet(pwalletMain), zaddr)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found.");
}
@ -3467,12 +3468,12 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, fromaddress, nMinDepth, false, false);
std::set<std::pair<PaymentAddress, uint256>> nullifierSet;
auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
auto hasSpendingKey = std::visit(HaveSpendingKeyForPaymentAddress(pwalletMain), zaddr);
if (hasSpendingKey) {
nullifierSet = pwalletMain->GetNullifiersForAddresses({zaddr});
}
if (boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr) {
if (std::get_if<libzcash::SproutPaymentAddress>(&zaddr) != nullptr) {
for (SproutNoteEntry & entry : sproutEntries) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("txid", entry.jsop.hash.ToString());
@ -3494,7 +3495,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
}
result.push_back(obj);
}
} else if (boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
} else if (std::get_if<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
for (SaplingNoteEntry & entry : saplingEntries) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("txid", entry.op.hash.ToString());
@ -3565,7 +3566,7 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
if (!IsValidPaymentAddress(res)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or zaddr.");
}
if (!boost::apply_visitor(PaymentAddressBelongsToWallet(pwalletMain), res)) {
if (!std::visit(PaymentAddressBelongsToWallet(pwalletMain), res)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, spending key or viewing key not found.");
}
}
@ -4034,12 +4035,12 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
}
// Check that we have the spending key
if (!boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), res)) {
if (!std::visit(HaveSpendingKeyForPaymentAddress(pwalletMain), res)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key not found.");
}
// Remember whether this is a Sprout or Sapling address
fromSapling = boost::get<libzcash::SaplingPaymentAddress>(&res) != nullptr;
fromSapling = std::get_if<libzcash::SaplingPaymentAddress>(&res) != nullptr;
}
// This logic will need to be updated if we add a new shielded pool
bool fromSprout = !(fromTaddr || fromSapling);
@ -4082,7 +4083,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
if (IsValidPaymentAddress(res)) {
isZaddr = true;
bool toSapling = boost::get<libzcash::SaplingPaymentAddress>(&res) != nullptr;
bool toSapling = std::get_if<libzcash::SaplingPaymentAddress>(&res) != nullptr;
bool toSprout = !toSapling;
noSproutAddrs = noSproutAddrs && toSapling;
@ -4181,7 +4182,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
for (int i = 0; i < zaddrRecipients.size(); i++) {
auto address = zaddrRecipients[i].address;
auto res = keyIO.DecodePaymentAddress(address);
bool toSapling = boost::get<libzcash::SaplingPaymentAddress>(&res) != nullptr;
bool toSapling = std::get_if<libzcash::SaplingPaymentAddress>(&res) != nullptr;
if (toSapling) {
mtx.vShieldedOutput.push_back(OutputDescription());
} else {
@ -4479,7 +4480,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
if (canopyActive) {
auto decodeAddr = keyIO.DecodePaymentAddress(destaddress);
bool isToSproutZaddr = (boost::get<libzcash::SproutPaymentAddress>(&decodeAddr) != nullptr);
bool isToSproutZaddr = (std::get_if<libzcash::SproutPaymentAddress>(&decodeAddr) != nullptr);
if (isToSproutZaddr) {
throw JSONRPCError(RPC_VERIFY_REJECTED, "Sprout shielding is not supported after Canopy activation");
@ -4559,7 +4560,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
CAmount nValue = out.tx->vout[out.i].nValue;
if (!maxedOutFlag) {
size_t increase = (boost::get<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
size_t increase = (std::get_if<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
if (estimatedTxSize + increase >= max_tx_size ||
(mempoolLimit > 0 && utxoCounter > mempoolLimit))
{
@ -4732,7 +4733,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
auto zaddr = keyIO.DecodePaymentAddress(address);
if (IsValidPaymentAddress(zaddr)) {
zaddrs.insert(zaddr);
if (boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
if (std::get_if<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
isFromNonSprout = true;
}
} else {
@ -4766,7 +4767,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
if (!IsValidDestination(taddr)) {
auto decodeAddr = keyIO.DecodePaymentAddress(destaddress);
if (IsValidPaymentAddress(decodeAddr)) {
if (boost::get<libzcash::SaplingPaymentAddress>(&decodeAddr) != nullptr) {
if (std::get_if<libzcash::SaplingPaymentAddress>(&decodeAddr) != nullptr) {
isToSaplingZaddr = true;
// If Sapling is not active, do not allow sending to a sapling addresses.
if (!saplingActive) {
@ -4877,7 +4878,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
CAmount nValue = out.tx->vout[out.i].nValue;
if (!maxedOutUTXOsFlag) {
size_t increase = (boost::get<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
size_t increase = (std::get_if<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
if (estimatedTxSize + increase >= max_tx_size ||
(mempoolLimit > 0 && utxoCounter > mempoolLimit))
{

View File

@ -26,6 +26,7 @@
#include <array>
#include <chrono>
#include <thread>
#include <variant>
#include <fstream>
#include <unordered_set>
@ -614,8 +615,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet)
// check that we have the spending key for the address
auto address = keyIO.DecodePaymentAddress(testAddr);
BOOST_CHECK(IsValidPaymentAddress(address));
BOOST_ASSERT(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr);
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
BOOST_ASSERT(std::get_if<libzcash::SproutPaymentAddress>(&address) != nullptr);
auto addr = std::get<libzcash::SproutPaymentAddress>(address);
BOOST_CHECK(pwalletMain->HaveSproutSpendingKey(addr));
// Verify the spending key is the same as the test data
@ -728,7 +729,7 @@ template <typename ADDR_TYPE>
void CheckHaveAddr(const libzcash::PaymentAddress& addr) {
BOOST_CHECK(IsValidPaymentAddress(addr));
auto addr_of_type = boost::get<ADDR_TYPE>(&addr);
auto addr_of_type = std::get_if<ADDR_TYPE>(&addr);
BOOST_ASSERT(addr_of_type != nullptr);
HaveSpendingKeyForPaymentAddress test(pwalletMain);

View File

@ -29,6 +29,7 @@
#include "wallet/asyncrpcoperation_saplingmigration.h"
#include <assert.h>
#include <variant>
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
@ -680,7 +681,7 @@ std::set<std::pair<libzcash::PaymentAddress, uint256>> CWallet::GetNullifiersFor
// (There may be more than one diversified address for a given ivk.)
std::map<libzcash::SaplingIncomingViewingKey, std::vector<libzcash::SaplingPaymentAddress>> ivkMap;
for (const auto & addr : addresses) {
auto saplingAddr = boost::get<libzcash::SaplingPaymentAddress>(&addr);
auto saplingAddr = std::get_if<libzcash::SaplingPaymentAddress>(&addr);
if (saplingAddr != nullptr) {
libzcash::SaplingIncomingViewingKey ivk;
this->GetSaplingIncomingViewingKey(*saplingAddr, ivk);
@ -3674,7 +3675,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
CScript scriptChange;
// coin control: send change to custom address
if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange))
if (coinControl && !std::get_if<CNoDestination>(&coinControl->destChange))
scriptChange = GetScriptForDestination(coinControl->destChange);
// no coin control: send change to newly generated address
@ -4492,7 +4493,7 @@ std::vector<SaplingOutPoint> CWallet::ListLockedSaplingNotes()
/** @} */ // end of Actions
class CAffectedKeysVisitor : public boost::static_visitor<void> {
class CAffectedKeysVisitor {
private:
const CKeyStore &keystore;
std::vector<CKeyID> &vKeys;
@ -4506,7 +4507,7 @@ public:
int nRequired;
if (ExtractDestinations(script, type, vDest, nRequired)) {
BOOST_FOREACH(const CTxDestination &dest, vDest)
boost::apply_visitor(*this, dest);
std::visit(*this, dest);
}
}
@ -4579,7 +4580,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
{
if (boost::get<CNoDestination>(&dest))
if (std::get_if<CNoDestination>(&dest))
return false;
mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
@ -4870,7 +4871,7 @@ bool CWallet::ParameterInteraction()
if (mapArgs.count("-migrationdestaddress")) {
std::string migrationDestAddress = mapArgs["-migrationdestaddress"];
libzcash::PaymentAddress address = keyIO.DecodePaymentAddress(migrationDestAddress);
if (boost::get<libzcash::SaplingPaymentAddress>(&address) == nullptr) {
if (std::get_if<libzcash::SaplingPaymentAddress>(&address) == nullptr) {
return UIError(_("-migrationdestaddress must be a valid Sapling address."));
}
}

View File

@ -1459,7 +1459,7 @@ public:
// Shielded key and address generalizations
//
class PaymentAddressBelongsToWallet : public boost::static_visitor<bool>
class PaymentAddressBelongsToWallet
{
private:
CWallet *m_wallet;
@ -1471,7 +1471,7 @@ public:
bool operator()(const libzcash::InvalidEncoding& no) const;
};
class GetViewingKeyForPaymentAddress : public boost::static_visitor<boost::optional<libzcash::ViewingKey>>
class GetViewingKeyForPaymentAddress
{
private:
CWallet *m_wallet;
@ -1483,7 +1483,7 @@ public:
boost::optional<libzcash::ViewingKey> operator()(const libzcash::InvalidEncoding& no) const;
};
class HaveSpendingKeyForPaymentAddress : public boost::static_visitor<bool>
class HaveSpendingKeyForPaymentAddress
{
private:
CWallet *m_wallet;
@ -1495,7 +1495,7 @@ public:
bool operator()(const libzcash::InvalidEncoding& no) const;
};
class GetSpendingKeyForPaymentAddress : public boost::static_visitor<boost::optional<libzcash::SpendingKey>>
class GetSpendingKeyForPaymentAddress
{
private:
CWallet *m_wallet;
@ -1514,7 +1514,7 @@ enum KeyAddResult {
KeyNotAdded,
};
class AddViewingKeyToWallet : public boost::static_visitor<KeyAddResult>
class AddViewingKeyToWallet
{
private:
CWallet *m_wallet;
@ -1526,7 +1526,7 @@ public:
KeyAddResult operator()(const libzcash::InvalidEncoding& no) const;
};
class AddSpendingKeyToWallet : public boost::static_visitor<KeyAddResult>
class AddSpendingKeyToWallet
{
private:
CWallet *m_wallet;

View File

@ -25,13 +25,13 @@ std::pair<std::string, PaymentAddress> AddressInfoFromViewingKey::operator()(con
}
bool IsValidPaymentAddress(const libzcash::PaymentAddress& zaddr) {
return zaddr.which() != 0;
return !std::holds_alternative<libzcash::InvalidEncoding>(zaddr);
}
bool IsValidViewingKey(const libzcash::ViewingKey& vk) {
return vk.which() != 0;
return !std::holds_alternative<libzcash::InvalidEncoding>(vk);
}
bool IsValidSpendingKey(const libzcash::SpendingKey& zkey) {
return zkey.which() != 0;
return !std::holds_alternative<libzcash::InvalidEncoding>(zkey);
}

View File

@ -5,7 +5,7 @@
#include "zcash/address/sprout.hpp"
#include "zcash/address/zip32.h"
#include <boost/variant.hpp>
#include <variant>
namespace libzcash {
class InvalidEncoding {
@ -14,18 +14,18 @@ public:
friend bool operator<(const InvalidEncoding &a, const InvalidEncoding &b) { return true; }
};
typedef boost::variant<InvalidEncoding, SproutPaymentAddress, SaplingPaymentAddress> PaymentAddress;
typedef boost::variant<InvalidEncoding, SproutViewingKey, SaplingExtendedFullViewingKey> ViewingKey;
typedef boost::variant<InvalidEncoding, SproutSpendingKey, SaplingExtendedSpendingKey> SpendingKey;
typedef std::variant<InvalidEncoding, SproutPaymentAddress, SaplingPaymentAddress> PaymentAddress;
typedef std::variant<InvalidEncoding, SproutViewingKey, SaplingExtendedFullViewingKey> ViewingKey;
typedef std::variant<InvalidEncoding, SproutSpendingKey, SaplingExtendedSpendingKey> SpendingKey;
class AddressInfoFromSpendingKey : public boost::static_visitor<std::pair<std::string, PaymentAddress>> {
class AddressInfoFromSpendingKey {
public:
std::pair<std::string, PaymentAddress> operator()(const SproutSpendingKey&) const;
std::pair<std::string, PaymentAddress> operator()(const struct SaplingExtendedSpendingKey&) const;
std::pair<std::string, PaymentAddress> operator()(const InvalidEncoding&) const;
};
class AddressInfoFromViewingKey : public boost::static_visitor<std::pair<std::string, PaymentAddress>> {
class AddressInfoFromViewingKey {
public:
std::pair<std::string, PaymentAddress> operator()(const SproutViewingKey&) const;
std::pair<std::string, PaymentAddress> operator()(const struct SaplingExtendedFullViewingKey&) const;

View File

@ -4,6 +4,8 @@
#include "serialize.h"
#include "uint256.h"
#include <variant>
namespace libzcash {
const unsigned char G1_PREFIX_MASK = 0x02;
@ -209,7 +211,7 @@ typedef std::array<unsigned char, GROTH_PROOF_SIZE> GrothProof;
// TODO: Because PHGRProof is listed first, using the default
// constructor for JSDescription() will create a JSDescription
// with a PHGRProof. The default however should be GrothProof.
typedef boost::variant<PHGRProof, GrothProof> SproutProof;
typedef std::variant<PHGRProof, GrothProof> SproutProof;
}