From d08dc57ab8740154a67a78d08d36001a51bfa45a Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 25 Jun 2022 10:25:57 -0300 Subject: [PATCH 1/3] Add newline to end of file --- java-examples/scripts/create-bot-jars.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-examples/scripts/create-bot-jars.sh b/java-examples/scripts/create-bot-jars.sh index 74d8c97..183ab93 100755 --- a/java-examples/scripts/create-bot-jars.sh +++ b/java-examples/scripts/create-bot-jars.sh @@ -49,4 +49,4 @@ extractdistribution ./create-runnable-jar.sh "$GRADLE_DIST_NAME" bisq.bots.TakeBestPricedOfferToSellBsq rm -r "$GRADLE_DIST_TARBALL" -echo "Done" \ No newline at end of file +echo "Done" From b0b6c9c771469f641812139479c447e50234e96d Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 25 Jun 2022 11:00:28 -0300 Subject: [PATCH 2/3] Uncomment wallet password prompt, and validate input during startup - When bot is run from a *nix terminal, password input will not be echoed. - When bot is run from an IDE, it's virtual terminal will echo the input (cannot be avoided). Validate the input during startup, to fail early instead of waiting for the right offer to take, then failing to unlock the wallet with an incorrect password. --- .../src/main/java/bisq/bots/AbstractBot.java | 21 +++++++++++++++++++ .../src/main/java/bisq/bots/BotUtils.java | 2 +- .../src/main/java/bisq/bots/OfferTaker.java | 2 +- .../bots/TakeBestPricedOfferToBuyBsq.java | 5 ++--- .../bots/TakeBestPricedOfferToBuyBtc.java | 6 +++--- .../bots/TakeBestPricedOfferToSellBsq.java | 5 ++--- .../bots/TakeBestPricedOfferToSellBtc.java | 5 ++--- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/java-examples/src/main/java/bisq/bots/AbstractBot.java b/java-examples/src/main/java/bisq/bots/AbstractBot.java index 9f59f75..edeb9f0 100644 --- a/java-examples/src/main/java/bisq/bots/AbstractBot.java +++ b/java-examples/src/main/java/bisq/bots/AbstractBot.java @@ -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. * diff --git a/java-examples/src/main/java/bisq/bots/BotUtils.java b/java-examples/src/main/java/bisq/bots/BotUtils.java index 86646ff..98ae329 100644 --- a/java-examples/src/main/java/bisq/bots/BotUtils.java +++ b/java-examples/src/main/java/bisq/bots/BotUtils.java @@ -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. diff --git a/java-examples/src/main/java/bisq/bots/OfferTaker.java b/java-examples/src/main/java/bisq/bots/OfferTaker.java index 08a29b3..ada4056 100644 --- a/java-examples/src/main/java/bisq/bots/OfferTaker.java +++ b/java-examples/src/main/java/bisq/bots/OfferTaker.java @@ -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. *
diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBsq.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBsq.java
index b9b1226..e7079ce 100644
--- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBsq.java
+++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBsq.java
@@ -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();
}
diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java
index a6f1d9a..7b1e8f6 100644
--- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java
+++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java
@@ -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();
}
diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBsq.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBsq.java
index 9ce7d1b..2919d7e 100644
--- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBsq.java
+++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBsq.java
@@ -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();
}
diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java
index 1e0dc89..20c235b 100644
--- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java
+++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java
@@ -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();
}
From b8bec325747446861c571549047211a19d258f38 Mon Sep 17 00:00:00 2001
From: ghubstan <36207203+ghubstan@users.noreply.github.com>
Date: Sat, 25 Jun 2022 11:04:14 -0300
Subject: [PATCH 3/3] Fix typo
---
.../src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java
index 7b1e8f6..db81b77 100644
--- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java
+++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java
@@ -404,7 +404,7 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot {
var filterResultsByLabel = new LinkedHashMap