From cf9d1628ed799f159ed3a6cd1be947466a2e20db Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Sat, 30 Jan 2021 02:35:53 +0000 Subject: [PATCH] Factor out shared segwit keychain setup to WalletsManager Move consecutive maybeAddSegwitKeychain(..) calls for the BTC & BSQ wallets from BisqSetup to WalletsManager, as the latter class is used for operations which should be applied to both wallets and this moves the logic closer to the wallet domain. Also migrate a BSQ address validator in one of the test mock classes from Base58AddressValidator to BitcoinAddressValidator (missed earlier). --- core/src/main/java/bisq/core/app/BisqSetup.java | 5 +---- .../java/bisq/core/btc/wallet/WalletsManager.java | 14 ++++++++++++-- .../java/bisq/core/locale/MockTestnetCoin.java | 12 +++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 4561b00ec32..1d8166b85a6 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -415,10 +415,7 @@ private void initWallet() { if (requestWalletPasswordHandler != null) { requestWalletPasswordHandler.accept(aesKey -> { walletsManager.setAesKey(aesKey); - walletsSetup.getWalletConfig().maybeAddSegwitKeychain(walletsSetup.getWalletConfig().btcWallet(), - aesKey, false); - walletsSetup.getWalletConfig().maybeAddSegwitKeychain(walletsSetup.getWalletConfig().bsqWallet(), - aesKey, true); + walletsManager.maybeAddSegwitKeychains(aesKey); if (preferences.isResyncSpvRequested()) { if (showFirstPopupIfResyncSPVRequestedHandler != null) showFirstPopupIfResyncSPVRequestedHandler.run(); diff --git a/core/src/main/java/bisq/core/btc/wallet/WalletsManager.java b/core/src/main/java/bisq/core/btc/wallet/WalletsManager.java index 2e6e9b6476a..df9705c67f6 100644 --- a/core/src/main/java/bisq/core/btc/wallet/WalletsManager.java +++ b/core/src/main/java/bisq/core/btc/wallet/WalletsManager.java @@ -91,7 +91,9 @@ public String getWalletsAsString(boolean includePrivKeys) { return baseCurrencyWalletDetails + bsqWalletDetails; } - public void restoreSeedWords(@Nullable DeterministicSeed seed, ResultHandler resultHandler, ExceptionHandler exceptionHandler) { + public void restoreSeedWords(@Nullable DeterministicSeed seed, + ResultHandler resultHandler, + ExceptionHandler exceptionHandler) { walletsSetup.restoreSeedWords(seed, resultHandler, exceptionHandler); } @@ -140,7 +142,15 @@ public void setAesKey(KeyParameter aesKey) { tradeWalletService.setAesKey(aesKey); } - public DeterministicSeed getDecryptedSeed(KeyParameter aesKey, DeterministicSeed keyChainSeed, KeyCrypter keyCrypter) { + public void maybeAddSegwitKeychains(KeyParameter aesKey) { + var walletConfig = walletsSetup.getWalletConfig(); + walletConfig.maybeAddSegwitKeychain(walletConfig.btcWallet(), aesKey, false); + walletConfig.maybeAddSegwitKeychain(walletConfig.bsqWallet(), aesKey, true); + } + + public DeterministicSeed getDecryptedSeed(KeyParameter aesKey, + DeterministicSeed keyChainSeed, + KeyCrypter keyCrypter) { if (keyCrypter != null) { return keyChainSeed.decrypt(keyCrypter, "", aesKey); } else { diff --git a/core/src/test/java/bisq/core/locale/MockTestnetCoin.java b/core/src/test/java/bisq/core/locale/MockTestnetCoin.java index 8ed0e85e9e7..cc35e0c35c3 100644 --- a/core/src/test/java/bisq/core/locale/MockTestnetCoin.java +++ b/core/src/test/java/bisq/core/locale/MockTestnetCoin.java @@ -17,17 +17,15 @@ package bisq.core.locale; +import bisq.asset.AddressValidationResult; +import bisq.asset.BitcoinAddressValidator; +import bisq.asset.Coin; + import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.RegTestParams; import org.bitcoinj.params.TestNet3Params; - - -import bisq.asset.AddressValidationResult; -import bisq.asset.Base58AddressValidator; -import bisq.asset.Coin; - public class MockTestnetCoin extends Coin { public MockTestnetCoin(Network network, NetworkParameters networkParameters) { @@ -55,7 +53,7 @@ public Regtest() { } } - public static class BSQAddressValidator extends Base58AddressValidator { + public static class BSQAddressValidator extends BitcoinAddressValidator { public BSQAddressValidator(NetworkParameters networkParameters) { super(networkParameters);