Skip to content

Commit

Permalink
Factor out shared segwit keychain setup to WalletsManager
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
stejbac committed Jan 30, 2021
1 parent 790bb30 commit cf9d162
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
5 changes: 1 addition & 4 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/java/bisq/core/btc/wallet/WalletsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions core/src/test/java/bisq/core/locale/MockTestnetCoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -55,7 +53,7 @@ public Regtest() {
}
}

public static class BSQAddressValidator extends Base58AddressValidator {
public static class BSQAddressValidator extends BitcoinAddressValidator {

public BSQAddressValidator(NetworkParameters networkParameters) {
super(networkParameters);
Expand Down

0 comments on commit cf9d162

Please sign in to comment.