add whirlpool postmix to the list of possible accounts that can be added to any legacy or segwit wallet

This commit is contained in:
Craig Raw 2023-09-29 14:37:58 +02:00
parent 31539a27ac
commit 0724c38582
5 changed files with 21 additions and 7 deletions

2
drongo

@ -1 +1 @@
Subproject commit 2b7b650faeeeda7fc25ab0962a6132e6531ced4c Subproject commit 73eed3e292d6e3f91402fe024aede18b5a50a509

View file

@ -17,6 +17,8 @@ import org.controlsfx.glyphfont.Glyph;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.sparrowwallet.drongo.wallet.StandardAccount.*;
public class AddAccountDialog extends Dialog<List<StandardAccount>> { public class AddAccountDialog extends Dialog<List<StandardAccount>> {
private final ComboBox<StandardAccount> standardAccountCombo; private final ComboBox<StandardAccount> standardAccountCombo;
private boolean discoverAccounts = false; private boolean discoverAccounts = false;
@ -53,13 +55,15 @@ public class AddAccountDialog extends Dialog<List<StandardAccount>> {
List<StandardAccount> availableAccounts = new ArrayList<>(); List<StandardAccount> availableAccounts = new ArrayList<>();
for(StandardAccount standardAccount : StandardAccount.values()) { for(StandardAccount standardAccount : StandardAccount.values()) {
if(!existingIndexes.contains(standardAccount.getAccountNumber()) && !StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { if(!existingIndexes.contains(standardAccount.getAccountNumber()) && !WHIRLPOOL_ACCOUNTS.contains(standardAccount)) {
availableAccounts.add(standardAccount); availableAccounts.add(standardAccount);
} }
} }
if(WhirlpoolServices.canWalletMix(masterWallet) && !masterWallet.isWhirlpoolMasterWallet()) { if(WhirlpoolServices.canWalletMix(masterWallet) && !masterWallet.isWhirlpoolMasterWallet()) {
availableAccounts.add(StandardAccount.WHIRLPOOL_PREMIX); availableAccounts.add(WHIRLPOOL_PREMIX);
} else if(WhirlpoolServices.canWatchPostmix(masterWallet) && !existingIndexes.contains(WHIRLPOOL_POSTMIX.getAccountNumber())) {
availableAccounts.add(WHIRLPOOL_POSTMIX);
} }
final ButtonType discoverButtonType = new javafx.scene.control.ButtonType("Discover", ButtonBar.ButtonData.LEFT); final ButtonType discoverButtonType = new javafx.scene.control.ButtonType("Discover", ButtonBar.ButtonData.LEFT);
@ -82,10 +86,14 @@ public class AddAccountDialog extends Dialog<List<StandardAccount>> {
return "None Available"; return "None Available";
} }
if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(account)) { if(account == WHIRLPOOL_PREMIX) {
return "Whirlpool Accounts"; return "Whirlpool Accounts";
} }
if(account == WHIRLPOOL_POSTMIX) {
return "Whirlpool Postmix (No mixing)";
}
return account.getName(); return account.getName();
} }

View file

@ -427,7 +427,7 @@ public class SendController extends WalletFormController implements Initializabl
addFeeRangeTrackHighlight(0); addFeeRangeTrackHighlight(0);
efficiencyToggle.setOnAction(event -> { efficiencyToggle.setOnAction(event -> {
if(getWalletForm().getWallet().isWhirlpoolMixWallet() && !overrideOptimizationStrategy) { if(StandardAccount.WHIRLPOOL_MIX_ACCOUNTS.contains(getWalletForm().getWallet().getStandardAccountType()) && !overrideOptimizationStrategy) {
AppServices.showWarningDialog("Privacy may be lost!", "It is recommended to optimize for privacy when sending coinjoined outputs."); AppServices.showWarningDialog("Privacy may be lost!", "It is recommended to optimize for privacy when sending coinjoined outputs.");
overrideOptimizationStrategy = true; overrideOptimizationStrategy = true;
} }
@ -1071,7 +1071,7 @@ public class SendController extends WalletFormController implements Initializabl
private OptimizationStrategy getPreferredOptimizationStrategy() { private OptimizationStrategy getPreferredOptimizationStrategy() {
OptimizationStrategy optimizationStrategy = Config.get().getSendOptimizationStrategy(); OptimizationStrategy optimizationStrategy = Config.get().getSendOptimizationStrategy();
if(getWalletForm().getWallet().isWhirlpoolMixWallet() && !overrideOptimizationStrategy) { if(StandardAccount.WHIRLPOOL_MIX_ACCOUNTS.contains(getWalletForm().getWallet().getStandardAccountType()) && !overrideOptimizationStrategy) {
optimizationStrategy = OptimizationStrategy.PRIVACY; optimizationStrategy = OptimizationStrategy.PRIVACY;
} }

View file

@ -655,7 +655,7 @@ public class SettingsController extends WalletFormController implements Initiali
private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) { private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) {
List<Wallet> childWallets; List<Wallet> childWallets;
if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { if(standardAccount == StandardAccount.WHIRLPOOL_PREMIX) {
childWallets = WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); childWallets = WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage());
} else { } else {
Wallet childWallet = masterWallet.addChildWallet(standardAccount); Wallet childWallet = masterWallet.addChildWallet(standardAccount);

View file

@ -170,6 +170,12 @@ public class WhirlpoolServices {
&& StandardAccount.MIXABLE_ACCOUNTS.contains(wallet.getStandardAccountType()); && StandardAccount.MIXABLE_ACCOUNTS.contains(wallet.getStandardAccountType());
} }
public static boolean canWatchPostmix(Wallet wallet) {
return Whirlpool.WHIRLPOOL_NETWORKS.contains(Network.get())
&& wallet.getScriptType() != ScriptType.P2TR //Taproot not yet supported
&& wallet.getKeystores().size() == 1;
}
public static List<Wallet> prepareWhirlpoolWallet(Wallet decryptedWallet, String walletId, Storage storage) { public static List<Wallet> prepareWhirlpoolWallet(Wallet decryptedWallet, String walletId, Storage storage) {
Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(walletId); Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(walletId);
whirlpool.setScode(decryptedWallet.getMasterMixConfig().getScode()); whirlpool.setScode(decryptedWallet.getMasterMixConfig().getScode());