Commit 7bcc3912 authored by zeroleak's avatar zeroleak
Browse files

add --emptyTo

parent 6fd545db
......@@ -26,6 +26,7 @@ public class ApplicationArgs {
private static final String ARG_TX0_DELAY = "tx0-delay";
private static final String ARG_TX0_MAX_OUTPUTS = "tx0-max-outputs";
private static final String ARG_AGGREGATE_POSTMIX = "aggregate-postmix";
private static final String ARG_EMPTY_TO = "emptyTo";
private static final String ARG_AUTO_AGGREGATE_POSTMIX = "auto-aggregate-postmix";
private static final String ARG_AUTO_TX0 = "auto-tx0";
private static final String ARG_AUTO_MIX = "auto-mix";
......@@ -119,6 +120,14 @@ public class ApplicationArgs {
return !StringUtils.isEmpty(getAggregatePostmix());
}
public String getEmptyTo() {
return optionalOption(ARG_EMPTY_TO);
}
public boolean isEmptyTo() {
return !StringUtils.isEmpty(getEmptyTo());
}
public boolean isInit() {
return args.containsOption(ARG_INIT);
}
......
package com.samourai.whirlpool.cli.run;
import com.samourai.wallet.client.Bip84ApiWallet;
import com.samourai.wallet.util.FormatsUtilGeneric;
import com.samourai.whirlpool.cli.ApplicationArgs;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.cli.services.CliWalletService;
import com.samourai.whirlpool.cli.services.WalletAggregateService;
import com.samourai.whirlpool.cli.utils.CliUtils;
import com.samourai.whirlpool.cli.wallet.CliWallet;
import java.lang.invoke.MethodHandles;
import org.slf4j.Logger;
......@@ -42,6 +44,34 @@ public class RunCliCommand {
log.info(" • Moving funds to: " + toAddress);
walletAggregateService.toAddress(depositWallet, toAddress, cliWallet);
}
} else if (appArgs.isEmptyTo()) {
CliWallet cliWallet = cliWalletService.getSessionWallet();
String toAddress = appArgs.getEmptyTo();
if (!FormatsUtilGeneric.getInstance().isValidBech32(toAddress)) {
throw new Exception("Invalid bech32 destination address: " + toAddress);
}
// confirm
System.out.println("⣿ WARNING ⣿ This will EMPTY your wallet and move funds to: " + toAddress);
CliUtils.readUserInputRequired("Press <y> to continue", false, new String[] {"y", "Y"});
// deposit
Bip84ApiWallet depositWallet = cliWallet.getWalletDeposit();
log.info(" • Moving funds: DEPOSIT -> " + toAddress);
walletAggregateService.toAddress(depositWallet, toAddress, cliWallet);
// premix
Bip84ApiWallet premixWallet = cliWallet.getWalletDeposit();
log.info(" • Moving funds: PREMIX -> " + toAddress);
walletAggregateService.toAddress(premixWallet, toAddress, cliWallet);
// postmix
Bip84ApiWallet postmixWallet = cliWallet.getWalletDeposit();
log.info(" • Moving funds: POSTMIX -> " + toAddress);
walletAggregateService.toAddress(postmixWallet, toAddress, cliWallet);
log.info("⣿ SUCCESS ⣿ All funds were moved to " + toAddress);
} else if (appArgs.isListPools()) {
CliWallet cliWallet = cliWalletService.getSessionWallet();
new RunListPools(cliWallet).run();
......@@ -55,6 +85,9 @@ public class RunCliCommand {
}
public static boolean hasCommandToRun(ApplicationArgs appArgs, CliConfig cliConfig) {
return appArgs.isDumpPayload() || appArgs.isAggregatePostmix() || appArgs.isListPools();
return appArgs.isDumpPayload()
|| appArgs.isAggregatePostmix()
|| appArgs.isEmptyTo()
|| appArgs.isListPools();
}
}
......@@ -10,7 +10,6 @@ import com.samourai.wallet.segwit.bech32.Bech32UtilGeneric;
import com.samourai.wallet.util.FormatsUtilGeneric;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.cli.wallet.CliWallet;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.utils.ClientUtils;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
......@@ -56,10 +55,11 @@ public class WalletAggregateService {
public boolean toAddress(
Bip84ApiWallet sourceWallet, String destinationAddress, CliWallet cliWallet)
throws Exception {
if (!formatUtils.isTestNet(cliConfig.getServer().getParams())) {
// enabled for mainnet for branch empty-to
/*if (!formatUtils.isTestNet(cliConfig.getServer().getParams())) {
throw new NotifiableException(
"aggregate toAddress is disabled on mainnet for security reasons.");
}
}*/
int feeSatPerByte = cliWallet.getFee(SamouraiFeeTarget.BLOCKS_2);
SamouraiApi samouraiApi = cliWallet.getConfig().getSamouraiApi();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment