Factor duplicate unlocked wallet checks into new method

Response to comment in PR 4299:
https://github.com/bisq-network/bisq/pull/4299#discussion_r440769032

This PR should be reviewed/merged after PR 4309.
https://github.com/bisq-network/bisq/pull/4309
This commit is contained in:
ghubstan 2020-06-16 12:48:41 -03:00
parent bac3ed5697
commit 258d1801d2
No known key found for this signature in database
GPG key ID: E35592D6800A861E

View file

@ -65,8 +65,7 @@ class CoreWalletsService {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
if (walletsManager.areWalletsEncrypted() && tempAesKey == null)
throw new IllegalStateException("wallet is locked");
verifyEncryptedWalletIsUnlocked();
var balance = balances.getAvailableBalance().get();
if (balance == null)
@ -93,8 +92,7 @@ class CoreWalletsService {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
if (walletsManager.areWalletsEncrypted() && tempAesKey == null)
throw new IllegalStateException("wallet is locked");
verifyEncryptedWalletIsUnlocked();
// Create a new funding address if none exists.
if (btcWalletService.getAvailableAddressEntries().size() == 0)
@ -246,6 +244,12 @@ class CoreWalletsService {
throw new IllegalStateException("wallet is not encrypted with a password");
}
// Throws a RuntimeException if wallets are encrypted and locked.
private void verifyEncryptedWalletIsUnlocked() {
if (walletsManager.areWalletsEncrypted() && tempAesKey == null)
throw new IllegalStateException("wallet is locked");
}
private KeyCrypterScrypt getKeyCrypterScrypt() {
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
if (keyCrypterScrypt == null)