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 9760526
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
7 changes: 1 addition & 6 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import bisq.core.btc.exceptions.WalletException;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.model.BsqTransferModel;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqTransferService;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
Expand Down Expand Up @@ -97,7 +96,6 @@ class CoreWalletsService {
private final CoreContext coreContext;
private final Balances balances;
private final WalletsManager walletsManager;
private final WalletsSetup walletsSetup;
private final BsqWalletService bsqWalletService;
private final BsqTransferService bsqTransferService;
private final BsqFormatter bsqFormatter;
Expand All @@ -119,7 +117,6 @@ public CoreWalletsService(AppStartupState appStartupState,
CoreContext coreContext,
Balances balances,
WalletsManager walletsManager,
WalletsSetup walletsSetup,
BsqWalletService bsqWalletService,
BsqTransferService bsqTransferService,
BsqFormatter bsqFormatter,
Expand All @@ -131,7 +128,6 @@ public CoreWalletsService(AppStartupState appStartupState,
this.coreContext = coreContext;
this.balances = balances;
this.walletsManager = walletsManager;
this.walletsSetup = walletsSetup;
this.bsqWalletService = bsqWalletService;
this.bsqTransferService = bsqTransferService;
this.bsqFormatter = bsqFormatter;
Expand Down Expand Up @@ -581,8 +577,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 9760526

Please sign in to comment.