From ff43db08423c9fad3cc82431e0efdfd1ddcfd939 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sat, 20 Mar 2021 11:49:17 +0200 Subject: [PATCH] retain messages from rpc errors when loading wallets with bwt --- .../sparrow/net/ElectrumServer.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index b29ed130..30744aa2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -29,6 +29,8 @@ import java.io.*; import java.util.*; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; public class ElectrumServer { @@ -46,6 +48,8 @@ public class ElectrumServer { private static String bwtElectrumServer; + private static final Pattern RPC_WALLET_LOADING_PATTERN = Pattern.compile(".*\"(Wallet loading failed:[^\"]*)\".*"); + private static synchronized Transport getTransport() throws ServerException { if(transport == null) { try { @@ -824,11 +828,16 @@ public class ElectrumServer { bwtStartCondition.await(); if(!bwt.isReady()) { - if(bwtStartException != null && bwtStartException.getMessage().contains("Wallet file not specified")) { - throw new ServerException("Bitcoin Core requires Multi-Wallet to be enabled in the Server Preferences"); - } else { - throw new ServerException("Check if Bitcoin Core is running, and the authentication details are correct."); + if(bwtStartException != null) { + Matcher walletLoadingMatcher = RPC_WALLET_LOADING_PATTERN.matcher(bwtStartException.getMessage()); + if(bwtStartException.getMessage().contains("Wallet file not specified")) { + throw new ServerException("Bitcoin Core requires Multi-Wallet to be enabled in the Server Preferences"); + } else if(walletLoadingMatcher.matches() && walletLoadingMatcher.group(1) != null) { + throw new ServerException(walletLoadingMatcher.group(1)); + } } + + throw new ServerException("Check if Bitcoin Core is running, and the authentication details are correct."); } } catch(InterruptedException e) { Thread.currentThread().interrupt();