Skip to content

Commit

Permalink
Remove duplication in wallets availability checks
Browse files Browse the repository at this point in the history
This change adds a new 'verifyWalletsAreAvailable' method to the client,
which eliminates this duplicated statement:
    throw new IllegalStateException("wallet is not yet available");

The commit is in response to a requested change in PR 4312:
bisq-network#4312 (review)
  • Loading branch information
ghubstan authored and eigentsmis committed Jun 26, 2020
1 parent 2484a96 commit 7e35180
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/src/main/java/bisq/core/grpc/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public CoreWalletsService(Balances balances,
}

public long getAvailableBalance() {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");

verifyWalletsAreAvailable();
verifyEncryptedWalletIsUnlocked();

var balance = balances.getAvailableBalance().get();
Expand All @@ -96,9 +94,7 @@ public AddressBalanceInfo getAddressBalanceInfo(String addressString) {
}

public List<AddressBalanceInfo> getFundingAddresses() {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");

verifyWalletsAreAvailable();
verifyEncryptedWalletIsUnlocked();

// Create a new funding address if none exists.
Expand Down Expand Up @@ -140,8 +136,7 @@ public int getNumConfirmationsForMostRecentTransaction(String addressString) {
}

public void setWalletPassword(String password, String newPassword) {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
verifyWalletsAreAvailable();

KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();

Expand Down Expand Up @@ -230,6 +225,12 @@ public void removeWalletPassword(String password) {
walletsManager.backupWallets();
}

// Throws a RuntimeException if wallets are not available (encrypted or not).
private void verifyWalletsAreAvailable() {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
}

// Throws a RuntimeException if wallets are not available or not encrypted.
private void verifyWalletIsAvailableAndEncrypted() {
if (!walletsManager.areWalletsAvailable())
Expand Down

0 comments on commit 7e35180

Please sign in to comment.