Remove duplication in wallets availability checks

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:
https://github.com/bisq-network/bisq/pull/4312#pullrequestreview-435659314
This commit is contained in:
ghubstan 2020-06-23 13:11:36 -03:00
parent 9691f35082
commit e1fddfacf8
No known key found for this signature in database
GPG Key ID: E35592D6800A861E

View File

@ -72,9 +72,7 @@ class CoreWalletsService {
}
public long getAvailableBalance() {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
verifyWalletsAreAvailable();
verifyEncryptedWalletIsUnlocked();
var balance = balances.getAvailableBalance().get();
@ -96,9 +94,7 @@ class CoreWalletsService {
}
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.
@ -140,8 +136,7 @@ class CoreWalletsService {
}
public void setWalletPassword(String password, String newPassword) {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
verifyWalletsAreAvailable();
KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();
@ -230,6 +225,12 @@ class CoreWalletsService {
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())