Merge pull request #6 from ghubstan/enable-walletpwd-prompt

Uncomment wallet password prompt, and validate input during startup
This commit is contained in:
Christoph Atteneder 2022-06-26 21:30:37 +02:00 committed by GitHub
commit b9e472f7ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 16 deletions

View File

@ -49,4 +49,4 @@ extractdistribution
./create-runnable-jar.sh "$GRADLE_DIST_NAME" bisq.bots.TakeBestPricedOfferToSellBsq
rm -r "$GRADLE_DIST_TARBALL"
echo "Done"
echo "Done"

View File

@ -326,6 +326,27 @@ public abstract class AbstractBot {
}
}
/**
* Attempt to unlock the wallet for 1 second using the given password, and shut down the bot if the
* password check fails for any reason.
*
* @param walletPassword String API daemon's wallet password
*/
protected void validateWalletPassword(String walletPassword) {
try {
var request = UnlockWalletRequest.newBuilder()
.setPassword(walletPassword)
.setTimeout(1)
.build();
//noinspection ResultOfMethodCallIgnored
grpcStubs.walletsService.unlockWallet(request);
} catch (StatusRuntimeException grpcException) {
log.error("Wallet password check failed.");
log.error((toCleanErrorMessage.apply(grpcException)));
exit(1);
}
}
/**
* Returns PaymentAccount for given paymentAccountId, else throws an IllegalArgumentException.
*

View File

@ -253,7 +253,7 @@ public class BotUtils {
*/
public static String readWalletPassword(String prompt) {
String walletPassword;
var console = console(); // Returns null in IDE console!
var console = console();
// System.console() returns null if you do not launch your java application with a real console.
if (console == null) {
// Have to read it in a less secure way in the IDE's virtual console.

View File

@ -237,7 +237,7 @@ class OfferTaker {
+ " Shut down the API bot and server, then check the server log."));
}
}
/**
* Wait and block until a new trade is fully initialized, with a trade contract and the user's trade role.
* <p>

View File

@ -262,9 +262,8 @@ public class TakeBestPricedOfferToBuyBsq extends AbstractBot {
public static void main(String[] args) {
@SuppressWarnings("unused")
String prompt = "An encrypted wallet must be unlocked before any offer can be taken.\n"
+ " Please enter your wallet password:";
String walletPassword = "be careful"; // readWalletPassword(prompt);
log.info("Your wallet password is {}", walletPassword.isBlank() ? "blank" : walletPassword);
+ "Please enter your wallet password:";
String walletPassword = readWalletPassword(prompt);
TakeBestPricedOfferToBuyBsq bot = new TakeBestPricedOfferToBuyBsq(appendWalletPasswordOpt(args, walletPassword));
bot.run();
}

View File

@ -133,6 +133,7 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot {
public void run() {
var startTime = new Date().getTime();
validatePollingInterval(pollingInterval);
validateWalletPassword(walletPassword);
validateTradeFeeCurrencyCode(bisqTradeFeeCurrency);
validatePaymentAccount(paymentAccount);
printBotConfiguration();
@ -329,9 +330,8 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot {
public static void main(String[] args) {
@SuppressWarnings("unused")
String prompt = "An encrypted wallet must be unlocked before any offer can be taken.\n"
+ " Please enter your wallet password:";
String walletPassword = "be careful"; // readWalletPassword(prompt);
log.info("Your wallet password is {}", walletPassword.isBlank() ? "blank" : walletPassword);
+ "Please enter your wallet password:";
String walletPassword = readWalletPassword(prompt);
TakeBestPricedOfferToBuyBtc bot = new TakeBestPricedOfferToBuyBtc(appendWalletPasswordOpt(args, walletPassword));
bot.run();
}
@ -404,7 +404,7 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot {
var filterResultsByLabel = new LinkedHashMap<String, Object>();
filterResultsByLabel.put("Current Market Price:", currentMarketPrice + " " + currencyCode);
filterResultsByLabel.put("Target Price (Max):", targetPrice + " " + currencyCode);
filterResultsByLabel.put("Target Price (Min):", targetPrice + " " + currencyCode);
filterResultsByLabel.put("Offer Price:", offer.getPrice() + " " + currencyCode);
filterResultsByLabel.put("Offer maker used same payment method?",
usesSamePaymentMethod.test(offer, getPaymentAccount()));

View File

@ -262,9 +262,8 @@ public class TakeBestPricedOfferToSellBsq extends AbstractBot {
public static void main(String[] args) {
@SuppressWarnings("unused")
String prompt = "An encrypted wallet must be unlocked before any offer can be taken.\n"
+ " Please enter your wallet password:";
String walletPassword = "be careful"; // readWalletPassword(prompt);
log.info("Your wallet password is {}", walletPassword.isBlank() ? "blank" : walletPassword);
+ "Please enter your wallet password:";
String walletPassword = readWalletPassword(prompt);
TakeBestPricedOfferToSellBsq bot = new TakeBestPricedOfferToSellBsq(appendWalletPasswordOpt(args, walletPassword));
bot.run();
}

View File

@ -330,9 +330,8 @@ public class TakeBestPricedOfferToSellBtc extends AbstractBot {
public static void main(String[] args) {
@SuppressWarnings("unused")
String prompt = "An encrypted wallet must be unlocked before any offer can be taken.\n"
+ " Please enter your wallet password:";
String walletPassword = "be careful"; // readWalletPassword(prompt);
log.info("Your wallet password is {}", walletPassword.isBlank() ? "blank" : walletPassword);
+ "Please enter your wallet password:";
String walletPassword = readWalletPassword(prompt);
TakeBestPricedOfferToSellBtc bot = new TakeBestPricedOfferToSellBtc(appendWalletPasswordOpt(args, walletPassword));
bot.run();
}