Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor duplicate unlocked wallet checks into new method #4312

Merged
merged 8 commits into from
Jun 25, 2020
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