From b3516063b26e4e528992d6332e67fca3aa7f00ed Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 15 Nov 2023 10:52:05 +0200 Subject: [PATCH] add null safe tests for standard account types --- drongo | 2 +- .../com/sparrowwallet/sparrow/control/AddAccountDialog.java | 2 +- .../java/com/sparrowwallet/sparrow/net/ElectrumServer.java | 4 ++-- .../sparrow/terminal/wallet/AddAccountDialog.java | 4 ++-- .../sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java | 2 +- .../sparrowwallet/sparrow/terminal/wallet/WalletDialog.java | 2 +- .../java/com/sparrowwallet/sparrow/wallet/SendController.java | 4 ++-- .../java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java | 2 +- .../sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drongo b/drongo index 28551247..94aafbc1 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 28551247c699c79561180dfe1c2b02db2b742a27 +Subproject commit 94aafbc11e974e44ba53fe505940767ff77ef940 diff --git a/src/main/java/com/sparrowwallet/sparrow/control/AddAccountDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/AddAccountDialog.java index cd720980..eb6941b8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/AddAccountDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/AddAccountDialog.java @@ -55,7 +55,7 @@ public class AddAccountDialog extends Dialog> { List availableAccounts = new ArrayList<>(); for(StandardAccount standardAccount : StandardAccount.values()) { - if(!existingIndexes.contains(standardAccount.getAccountNumber()) && !WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { + if(!existingIndexes.contains(standardAccount.getAccountNumber()) && !StandardAccount.isWhirlpoolAccount(standardAccount)) { availableAccounts.add(standardAccount); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index 3079fb6f..4eba36bc 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -1697,7 +1697,7 @@ public class ElectrumServer { Map> childTransactionMap = new TreeMap<>(); electrumServer.getReferences(childWallet, childWallet.getNode(KeyPurpose.RECEIVE).getChildren(), childTransactionMap, 0); if(childTransactionMap.values().stream().anyMatch(blockTransactionHashes -> !blockTransactionHashes.isEmpty())) { - if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { + if(StandardAccount.isWhirlpoolAccount(standardAccount)) { foundAccounts.addAll(StandardAccount.WHIRLPOOL_ACCOUNTS); } else { foundAccounts.add(standardAccount); @@ -1726,7 +1726,7 @@ public class ElectrumServer { List accounts = new ArrayList<>(); for(StandardAccount account : StandardAccount.values()) { - if(account != StandardAccount.ACCOUNT_0 && (!StandardAccount.WHIRLPOOL_ACCOUNTS.contains(account) || wallet.getScriptType() == ScriptType.P2WPKH)) { + if(account != StandardAccount.ACCOUNT_0 && (!StandardAccount.isWhirlpoolAccount(account) || wallet.getScriptType() == ScriptType.P2WPKH)) { accounts.add(account); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddAccountDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddAccountDialog.java index a2db2544..0d886fd4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddAccountDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/AddAccountDialog.java @@ -40,7 +40,7 @@ final class AddAccountDialog extends DialogWindow { List availableAccounts = new ArrayList<>(); for(StandardAccount standardAccount : StandardAccount.values()) { - if(!existingIndexes.contains(standardAccount.getAccountNumber()) && !StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { + if(!existingIndexes.contains(standardAccount.getAccountNumber()) && !StandardAccount.isWhirlpoolAccount(standardAccount)) { availableAccounts.add(standardAccount); } } @@ -87,7 +87,7 @@ final class AddAccountDialog extends DialogWindow { @Override public String toString() { - if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(account)) { + if(StandardAccount.isWhirlpoolAccount(account)) { return "Whirlpool Accounts"; } diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java index c723d689..b814200f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/SettingsDialog.java @@ -114,7 +114,7 @@ public class SettingsDialog extends WalletDialog { if(standardAccount != null) { addAccount(masterWallet, standardAccount, () -> { SparrowTerminal.get().getGuiThread().invokeLater(() -> { - if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { + if(StandardAccount.isWhirlpoolAccount(standardAccount)) { showSuccessDialog("Added Accounts", "Whirlpool Accounts have been successfully added."); } else { showSuccessDialog("Added Account", standardAccount.getName() + " has been successfully added."); diff --git a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/WalletDialog.java b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/WalletDialog.java index 8faae108..d3fe2a7b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/WalletDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/terminal/wallet/WalletDialog.java @@ -124,7 +124,7 @@ public class WalletDialog extends DialogWindow { private void addAndSaveAccount(Wallet masterWallet, StandardAccount standardAccount, Key key) { List childWallets; - if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount)) { + if(StandardAccount.isWhirlpoolAccount(standardAccount)) { childWallets = WhirlpoolServices.prepareWhirlpoolWallet(masterWallet, getWalletForm().getWalletId(), getWalletForm().getStorage()); } else { Wallet childWallet = masterWallet.addChildWallet(standardAccount); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index da565ad5..59b2e95f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -411,7 +411,7 @@ public class SendController extends WalletFormController implements Initializabl }); efficiencyToggle.setOnAction(event -> { - if(StandardAccount.WHIRLPOOL_MIX_ACCOUNTS.contains(getWalletForm().getWallet().getStandardAccountType()) && !overrideOptimizationStrategy) { + if(StandardAccount.isWhirlpoolMixAccount(getWalletForm().getWallet().getStandardAccountType()) && !overrideOptimizationStrategy) { AppServices.showWarningDialog("Privacy may be lost!", "It is recommended to optimize for privacy when sending coinjoined outputs."); overrideOptimizationStrategy = true; } @@ -1014,7 +1014,7 @@ public class SendController extends WalletFormController implements Initializabl private OptimizationStrategy getPreferredOptimizationStrategy() { OptimizationStrategy optimizationStrategy = Config.get().getSendOptimizationStrategy(); - if(StandardAccount.WHIRLPOOL_MIX_ACCOUNTS.contains(getWalletForm().getWallet().getStandardAccountType()) && !overrideOptimizationStrategy) { + if(StandardAccount.isWhirlpoolMixAccount(getWalletForm().getWallet().getStandardAccountType()) && !overrideOptimizationStrategy) { optimizationStrategy = OptimizationStrategy.PRIVACY; } diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java index ec39594e..022de3c1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java @@ -390,7 +390,7 @@ public class Whirlpool { public static Wallet getStandardAccountWallet(WhirlpoolAccount whirlpoolAccount, Wallet wallet) { StandardAccount standardAccount = getStandardAccount(whirlpoolAccount); - if(StandardAccount.WHIRLPOOL_ACCOUNTS.contains(standardAccount) || wallet.getStandardAccountType() != standardAccount) { + if(StandardAccount.isWhirlpoolAccount(standardAccount) || wallet.getStandardAccountType() != standardAccount) { Wallet standardWallet = wallet.getChildWallet(standardAccount); if(standardWallet == null) { throw new IllegalStateException("Cannot find " + standardAccount + " wallet"); diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java index 5ee27c7f..571919c8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java @@ -173,7 +173,7 @@ public class WhirlpoolServices { && wallet.getKeystores().get(0).hasSeed() && wallet.getKeystores().get(0).getSeed().getType() == DeterministicSeed.Type.BIP39 && wallet.getStandardAccountType() != null - && StandardAccount.MIXABLE_ACCOUNTS.contains(wallet.getStandardAccountType()); + && StandardAccount.isMixableAccount(wallet.getStandardAccountType()); } public static boolean canWatchPostmix(Wallet wallet) {