From 8de14dcbcee3f94953db0140f843a67e2b41b860 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 2 Dec 2022 17:16:34 +0200 Subject: [PATCH] improve handling of certain electrum server errors --- .../sparrow/net/SimpleElectrumServerRpc.java | 7 ++++++- .../sparrow/transaction/HeadersController.java | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java b/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java index 46d585a1..25184386 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java @@ -150,7 +150,7 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc { //If there is an error with the server connection, don't keep trying - this may take too long given many blocks throw new ElectrumServerRpcException("Failed to retrieve block header for block height: " + blockHeight, e); } catch(JsonRpcException e) { - log.warn("Failed to retrieve block header for block height: " + blockHeight + " (" + e.getErrorMessage() + ")"); + log.warn("Failed to retrieve block header for block height: " + blockHeight + (e.getErrorMessage() != null ? " (" + e.getErrorMessage().getMessage() + ")" : "")); } catch(Exception e) { log.warn("Failed to retrieve block header for block height: " + blockHeight + " (" + e.getMessage() + ")"); } @@ -193,6 +193,11 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc { client.createRequest().returnAs(VerboseTransaction.class).method("blockchain.transaction.get").id(idCounter.incrementAndGet()).params(txid, true).execute()); result.put(txid, verboseTransaction); } catch(Exception e) { + if(e instanceof JsonRpcException jsonRpcException && jsonRpcException.getErrorMessage() != null + && jsonRpcException.getErrorMessage().getMessage().startsWith("No such mempool or blockchain transaction")) { + continue; + } + //electrs-esplora does not currently support the verbose parameter, so try to fetch an incomplete VerboseTransaction without it //Note that without the script hash associated with the transaction, we can't get a block height as there is no way in the Electrum RPC protocol to do this //We mark this VerboseTransaction as incomplete by assigning it a Sha256Hash.ZERO_HASH blockhash diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index af2cc81a..b8acd760 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -1109,11 +1109,18 @@ public class HeadersController extends TransactionFormController implements Init broadcastTransactionService.setOnFailed(workerStateEvent -> { broadcastProgressBar.setProgress(0); log.error("Error broadcasting transaction", workerStateEvent.getSource().getException()); - if(workerStateEvent.getSource().getException() != null && workerStateEvent.getSource().getException().getMessage() != null - && workerStateEvent.getSource().getException().getMessage().startsWith("min relay fee not met")) { + + String failMessage = ""; + if(workerStateEvent.getSource().getException() != null && workerStateEvent.getSource().getException().getMessage() != null) { + failMessage = workerStateEvent.getSource().getException().getMessage(); + } + + if(failMessage.startsWith("min relay fee not met")) { AppServices.showErrorDialog("Error broadcasting transaction", "The fee rate for the signed transaction is below the minimum " + AppServices.getMinimumRelayFeeRate() + " sats/vB. " + "This usually happens because a keystore has created a signature that is larger than necessary.\n\n" + "You can solve this by recreating the transaction with a slightly increased fee rate."); + } else if(failMessage.startsWith("bad-txns-inputs-missingorspent")) { + AppServices.showErrorDialog("Error broadcasting transaction", "The server returned an error indicating some or all of the UTXOs this transaction is spending are missing or have already been spent."); } else { AppServices.showErrorDialog("Error broadcasting transaction", "The server returned an error when broadcasting the transaction. The server response is contained in the log (See Help > Show Log File)."); }