Skip to content

Commit

Permalink
Renamed tempWalletPassword -> tempLockWalletPassword
Browse files Browse the repository at this point in the history
This @nullable class level variable's name needs to specifically
describe the use case.
  • Loading branch information
ghubstan committed Apr 30, 2020
1 parent ca68d05 commit c5fcafb
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions core/src/main/java/bisq/core/grpc/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
* Provides high level interface to functionality of core Bisq features.
* E.g. useful for different APIs to access data of different domains of Bisq.
Expand All @@ -67,7 +68,7 @@ public class CoreApi {
private final User user;

@Nullable
private String tempWalletPassword;
private String tempLockWalletPassword;

@Inject
public CoreApi(Balances balances,
Expand Down Expand Up @@ -180,7 +181,7 @@ public void placeOffer(String offerId,
log::error);
}

// Provided for automated wallet encryption password testing, despite the
// Provided for automated wallet protection method testing, despite the
// security risks exposed by providing users the ability to decrypt their wallets.
public Tuple2<Boolean, String> removeWalletPassword(String password) {
if (!walletsManager.areWalletsAvailable())
Expand Down Expand Up @@ -236,9 +237,9 @@ public Tuple2<Boolean, String> setWalletPassword(String password, String newPass
}

public Tuple2<Boolean, String> lockWallet() {
if (tempWalletPassword != null) {
Tuple2<Boolean, String> encrypted = setWalletPassword(tempWalletPassword, null);
tempWalletPassword = null;
if (tempLockWalletPassword != null) {
Tuple2<Boolean, String> encrypted = setWalletPassword(tempLockWalletPassword, null);
tempLockWalletPassword = null;
if (!encrypted.first)
return encrypted;

Expand All @@ -257,14 +258,15 @@ public Tuple2<Boolean, String> unlockWallet(String password, long timeout) {
public void run() {
log.info("Locking wallet");
setWalletPassword(password, null);
tempWalletPassword = null;
tempLockWalletPassword = null;
}
};
Timer timer = new Timer("Lock Wallet Timer");
timer.schedule(timerTask, TimeUnit.SECONDS.toMillis(timeout));
timer.schedule(timerTask, SECONDS.toMillis(timeout));

// Cache a temp password for timeout (secs) to allow user locks wallet before timeout expires.
tempWalletPassword = password;
// Cache wallet password for timeout (secs), in case
// user wants to lock the wallet for timeout expires.
tempLockWalletPassword = password;
return new Tuple2<>(true, "");
}
}

0 comments on commit c5fcafb

Please sign in to comment.