Browse Source

Support multiple zsweepexclude zaddrs

pull/195/head
Jonathan "Duke" Leto 2 years ago
parent
commit
f796d5d14e
  1. 4
      src/init.cpp
  2. 37
      src/wallet/asyncrpcoperation_sweep.cpp
  3. 2
      src/wallet/wallet.h

4
src/init.cpp

@ -2121,17 +2121,17 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
for (int i = 0; i < vSweepExclude.size(); i++) {
LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]);
pwalletMain->sweepExcludeAddress = vSweepExclude[i];
auto zSweepExcluded = DecodePaymentAddress(vSweepExclude[i]);
if (!IsValidPaymentAddress(zSweepExcluded)) {
return InitError("Invalid zsweep address");
}
auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zSweepExcluded);
pwalletMain->sweepExcludeAddress = vSweepExclude[i];
if (!hasSpendingKey) {
return InitError("Wallet must have the spending key of zsweepexclude address");
}
// Add this validated zaddr to the list of excluded sweep zaddrs
pwalletMain->sweepExcludeAddresses.push_back( vSweepExclude[i] );
}
if (pwalletMain->fSaplingConsolidationEnabled) {

37
src/wallet/asyncrpcoperation_sweep.cpp

@ -74,6 +74,26 @@ void AsyncRPCOperation_sweep::main() {
LogPrintf("%s", s);
}
// Is this zaddr excluded from zsweep ?
bool IsExcludedAddress(libzcash::SaplingPaymentAddress zaddr) {
for( auto & sweepExcludeAddress : pwalletMain->sweepExcludeAddresses ) {
auto zAddressExclude = DecodePaymentAddress(sweepExcludeAddress);
if (boost::get<libzcash::SaplingPaymentAddress>(&zAddressExclude) != nullptr) {
sweepExcludeAddress = boost::get<libzcash::SaplingPaymentAddress>(zAddressExclude);
} else {
// This is an invalid sapling zaddr
LogPrintf("%s: Invalid zsweepexclude zaddr %s, ignoring\n", opid, sweepExcludeAddress);
}
if (sweepExcludeAddress == entry.address) {
return true;
}
}
return false;
}
bool AsyncRPCOperation_sweep::main_impl() {
bool status=true;
auto opid=getId();
@ -88,7 +108,6 @@ bool AsyncRPCOperation_sweep::main_impl() {
std::vector<SaplingNoteEntry> saplingEntries;
libzcash::SaplingPaymentAddress sweepAddress;
libzcash::SaplingPaymentAddress sweepExcludeAddress;
std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> mapAddresses;
{
@ -96,16 +115,15 @@ bool AsyncRPCOperation_sweep::main_impl() {
pwalletMain->GetFilteredNotes(saplingEntries, "", 11);
if (!fromRPC_) {
auto zAddressExclude = DecodePaymentAddress(pwalletMain->sweepExcludeAddress);
if (boost::get<libzcash::SaplingPaymentAddress>(&zAddressExclude) != nullptr) {
sweepExcludeAddress = boost::get<libzcash::SaplingPaymentAddress>(zAddressExclude);
}
if (fSweepMapUsed) {
const vector<string>& v = mapMultiArgs["-zsweepaddress"];
for(int i = 0; i < v.size(); i++) {
auto zAddress = DecodePaymentAddress(v[i]);
if (boost::get<libzcash::SaplingPaymentAddress>(&zAddress) != nullptr) {
sweepAddress = boost::get<libzcash::SaplingPaymentAddress>(zAddress);
} else {
LogPrintf("%s: Invalid zsweepaddress configured, exiting\n", opid);
return false;
}
}
} else {
@ -121,10 +139,13 @@ bool AsyncRPCOperation_sweep::main_impl() {
}
}
// Map all notes by address
// Map all notes (zutxos) by address
for (auto & entry : saplingEntries) {
// do not need to sweep Excluded Address
if (sweepExcludeAddress == entry.address) { continue; }
// do not need to sweep Excluded Addresses
if(IsExcludedAddress(entry.address) {
continue;
}
// do not need to sweep the sweepAddress as that is the destination
if (sweepAddress == entry.address) {
continue;

2
src/wallet/wallet.h

@ -815,7 +815,7 @@ public:
int sweepFee = 10000;
int sweepMaxInputs = 200;
std::string sweepAddress = "";
std::string sweepExcludeAddress = "";
std::vector<std::string> sweepExcludeAddresses = "";
std::string consolidationAddress = "";
void ClearNoteWitnessCache();

Loading…
Cancel
Save