From 258d1801d2d5cecd06c60e60e31fa8b2ede744e0 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 16 Jun 2020 12:48:41 -0300 Subject: [PATCH] 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 --- .../main/java/bisq/core/grpc/CoreWalletsService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/grpc/CoreWalletsService.java b/core/src/main/java/bisq/core/grpc/CoreWalletsService.java index f9e3b7d1c60..be44122ab2e 100644 --- a/core/src/main/java/bisq/core/grpc/CoreWalletsService.java +++ b/core/src/main/java/bisq/core/grpc/CoreWalletsService.java @@ -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) @@ -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) @@ -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)