Treat some wallet-is-locked errors as trivial

This commit is contained in:
ghubstan 2022-06-29 18:07:34 -03:00
parent 897401ba0e
commit 9307c08d4d
No known key found for this signature in database
GPG Key ID: E35592D6800A861E

View File

@ -345,6 +345,19 @@ public abstract class AbstractBot {
}
}
/**
* Return true if gRPC StatusRuntimeException indicates wallet is locked. Sometimes this is a trivial error.
*
* @param grpcException a StatusRuntimeException
* @return true if gRPC StatusRuntimeException indicates wallet is locked
*/
protected boolean walletIsLocked(StatusRuntimeException grpcException) {
var errorMsg = toCleanErrorMessage.apply(grpcException).toLowerCase();
return (exceptionHasStatus.test(grpcException, FAILED_PRECONDITION)
&& errorMsg.contains("wallet")
&& errorMsg.contains("locked"));
}
/**
* 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.
@ -575,6 +588,22 @@ public abstract class AbstractBot {
BotUtils.printTradesSummary(category, trades);
}
/**
* Print the completed trades since midnight today, if the wallet is unlocked, else log an error message.
*/
protected void printTradesSummaryForTodayIfWalletIsUnlocked() {
try {
log.info("Here are today's completed trades:");
printTradesSummaryForToday(CLOSED);
} catch (StatusRuntimeException grpcException) {
if (walletIsLocked(grpcException)) {
log.error("Cannot retrieve trades while API daemon's wallet is locked.");
} else {
throw grpcException;
}
}
}
/**
* Print list of today's trade summaries to stdout.
*
@ -813,9 +842,7 @@ public abstract class AbstractBot {
* @param maxTakeOffers the max number of offers that can be taken during bot run
*/
protected void maybeShutdownAfterSuccessfulTradeCreation(int numOffersTaken, int maxTakeOffers) {
log.info("Here are today's completed trades:");
printTradesSummaryForToday(CLOSED);
printTradesSummaryForTodayIfWalletIsUnlocked();
if (!isDryRun) {
// If the bot is not in dryrun mode, lock the wallet. If dryrun=true, leave the wallet unlocked until the
// timeout expires, so the user can look at data in the daemon with the CLI (a convenience in dev/test).