Use a visitor for handling -mineraddress config option
This makes it easier to add UA support.
This commit is contained in:
parent
22ffee8da6
commit
990bc46b2b
|
@ -1093,10 +1093,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||
if (mapArgs.count("-mineraddress")) {
|
||||
CTxDestination addr = keyIO.DecodeDestination(mapArgs["-mineraddress"]);
|
||||
if (!IsValidDestination(addr)) {
|
||||
// Try a Sapling address
|
||||
// Try a payment address
|
||||
auto zaddr = keyIO.DecodePaymentAddress(mapArgs["-mineraddress"]);
|
||||
if (!IsValidPaymentAddress(zaddr) ||
|
||||
std::get_if<libzcash::SaplingPaymentAddress>(&zaddr) == nullptr)
|
||||
if (!std::visit(IsValidMinerAddress(), std::visit(ExtractMinerAddress(), zaddr)))
|
||||
{
|
||||
return InitError(strprintf(
|
||||
_("Invalid address for -mineraddress=<addr>: '%s' (must be a Sapling or transparent address)"),
|
||||
|
|
|
@ -696,12 +696,10 @@ void GetMinerAddress(MinerAddress &minerAddress)
|
|||
mAddr->reserveScript = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
minerAddress = mAddr;
|
||||
} else {
|
||||
// Try a Sapling address
|
||||
auto zaddr = keyIO.DecodePaymentAddress(mAddrArg);
|
||||
if (IsValidPaymentAddress(zaddr)) {
|
||||
if (std::get_if<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
|
||||
minerAddress = std::get<libzcash::SaplingPaymentAddress>(zaddr);
|
||||
}
|
||||
// Try a payment address
|
||||
auto zaddr = std::visit(ExtractMinerAddress(), keyIO.DecodePaymentAddress(mAddrArg));
|
||||
if (std::visit(IsValidMinerAddress(), zaddr)) {
|
||||
minerAddress = zaddr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
src/miner.h
21
src/miner.h
|
@ -29,7 +29,26 @@ public:
|
|||
friend bool operator<(const InvalidMinerAddress &a, const InvalidMinerAddress &b) { return true; }
|
||||
};
|
||||
|
||||
typedef std::variant<InvalidMinerAddress, libzcash::SaplingPaymentAddress, boost::shared_ptr<CReserveScript>> MinerAddress;
|
||||
typedef std::variant<
|
||||
InvalidMinerAddress,
|
||||
libzcash::SaplingPaymentAddress,
|
||||
boost::shared_ptr<CReserveScript>> MinerAddress;
|
||||
|
||||
class ExtractMinerAddress
|
||||
{
|
||||
public:
|
||||
ExtractMinerAddress() {}
|
||||
|
||||
MinerAddress operator()(const libzcash::InvalidEncoding &invalid) const {
|
||||
return InvalidMinerAddress();
|
||||
}
|
||||
MinerAddress operator()(const libzcash::SproutPaymentAddress &addr) const {
|
||||
return InvalidMinerAddress();
|
||||
}
|
||||
MinerAddress operator()(const libzcash::SaplingPaymentAddress &addr) const {
|
||||
return addr;
|
||||
}
|
||||
};
|
||||
|
||||
class KeepMinerAddress
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue