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 Apr 27, 2021
1 parent 5f1e32a commit c8e847c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ private void maybeSetWalletsManagerKey() {
if (btcWalletService.getAesKey() == null || bsqWalletService.getAesKey() == null) {
KeyParameter aesKey = new KeyParameter(tempAesKey.getKey());
walletsManager.setAesKey(aesKey);
walletsSetup.getWalletConfig().maybeAddSegwitKeychain(walletsSetup.getWalletConfig().btcWallet(), aesKey, false);
walletsSetup.getWalletConfig().maybeAddSegwitKeychain(walletsSetup.getWalletConfig().bsqWallet(), aesKey, true);
walletsManager.maybeAddSegwitKeychains(aesKey);
}
}

Expand Down
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 @@ -423,10 +423,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 (getResyncSpvSemaphore()) {
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 c8e847c

Please sign in to comment.