Skip to content

Commit

Permalink
Factor duplicate unlocked wallet checks into new method
Browse files Browse the repository at this point in the history
Response to comment in PR 4299:
#4299 (comment)

This PR should be reviewed/merged after PR 4309.
#4309
  • Loading branch information
ghubstan committed Jun 16, 2020
1 parent bac3ed5 commit 258d180
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/main/java/bisq/core/grpc/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public long getAvailableBalance() {
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)
Expand All @@ -93,8 +92,7 @@ public String getFundingAddresses() {
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)
Expand Down Expand Up @@ -246,6 +244,12 @@ private void verifyWalletIsAvailableAndEncrypted() {
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)
Expand Down

0 comments on commit 258d180

Please sign in to comment.