diff --git a/src/init.cpp b/src/init.cpp index 98f773b0f..3b0bc6bcd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -471,6 +471,7 @@ std::string HelpMessage(HelpMessageMode mode) // By default we only allow sweeping to the current wallet which must have the spending key of the sweep zaddr // This hopefully will make it harder for people to accidentally sweep funds to a wrong zaddr and lose funds strUsage += HelpMessageOpt("-zsweepexternal", _("Enable sweeping to an external wallet (default false)")); + strUsage += HelpMessageOpt("-zsweepexclude", _("Addresses to exclude from sweeping (default none)")); strUsage += HelpMessageOpt("-deletetx", _("Enable Old Transaction Deletion")); strUsage += HelpMessageOpt("-deleteinterval", strprintf(_("Delete transaction every blocks during inital block download (default: %i)"), DEFAULT_TX_DELETE_INTERVAL)); @@ -2094,6 +2095,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) //Validate Sapling Addresses vector& vSweep = mapMultiArgs["-zsweepaddress"]; + vector& vSweepExclude = mapMultiArgs["-zsweepexclude"]; if (vSweep.size() != 1) { return InitError("A single zsweep address must be specified."); } @@ -2117,6 +2119,20 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } } + for (int i = 0; i < vSweepExclude.size(); i++) { + // LogPrintf("Sweep Excluded Address: %s\n", 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"); + } + } + if (pwalletMain->fSaplingConsolidationEnabled) { //Validate 1 Consolidation address only that matches the sweep address vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f5e07e9da..2dfb9e6b1 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -815,6 +815,7 @@ public: int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; + std::string sweepExcludeAddress = ""; std::string consolidationAddress = ""; void ClearNoteWitnessCache();