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:
bisq-network#4299 (comment)

This PR should be reviewed/merged after PR 4309.
bisq-network#4309
  • Loading branch information
ghubstan authored and eigentsmis committed Jun 26, 2020
1 parent fd9d182 commit 4599d20
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 4599d20

Please sign in to comment.