Remove multiple definitions of constants.
MODIFY
WalletWasabi/BitcoinCore/RpcParser.cs
WalletWasabi/BitcoinCore/RpcParser.cs
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using NBitcoin;
using NBitcoin.RPC;
@@ -10,12 +11,23 @@ namespace WalletWasabi.BitcoinCore
{
public static class RpcParser
{
+ public const string SpentError1 = "bad-txns-inputs-missingorspent";
+ public const string SpentError2 = "missing-inputs";
+ public const string SpentError3 = "txn-mempool-conflict";
+ public const string TooLongMempoolChainError = "too-long-mempool-chain";
+
+ public const string SpentErrorTranslation = "At least one coin you are trying to spend is already spent.";
+
+ public static bool IsSpentError(string error) => new[] { SpentError1, SpentError2, SpentError3 }.Any(x => error.Contains(x, StringComparison.OrdinalIgnoreCase));
+
+ public static bool IsTooLongMempoolChainError(string error) => error.Contains(TooLongMempoolChainError, StringComparison.OrdinalIgnoreCase);
+
public static Dictionary<string, string> ErrorTranslations { get; } = new Dictionary<string, string>
{
- ["too-long-mempool-chain"] = "At least one coin you are trying to spend is part of long or heavy chain of unconfirmed transactions. You must wait for some previous transactions to confirm.",
- ["bad-txns-inputs-missingorspent"] = "At least one coin you are trying to spend is already spent.",
- ["missing-inputs"] = "At least one coin you are trying to spend is already spent.",
- ["txn-mempool-conflict"] = "At least one coin you are trying to spend is already spent.",
+ [TooLongMempoolChainError] = "At least one coin you are trying to spend is part of long or heavy chain of unconfirmed transactions. You must wait for some previous transactions to confirm.",
+ [SpentError1] = SpentErrorTranslation,
+ [SpentError2] = SpentErrorTranslation,
+ [SpentError3] = SpentErrorTranslation,
["bad-txns-inputs-duplicate"] = "The transaction contains duplicated inputs.",
["bad-txns-nonfinal"] = "The transaction is not final and cannot be broadcasted.",
["bad-txns-oversize"] = "The transaction is too big.",

MODIFY
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
@@ -97,9 +97,7 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
{
await client.BroadcastAsync(transaction).ConfigureAwait(false);
}
- catch (HttpRequestException ex2) when (ex2.Message.Contains("bad-txns-inputs-missingorspent", StringComparison.InvariantCultureIgnoreCase)
- || ex2.Message.Contains("missing-inputs", StringComparison.InvariantCultureIgnoreCase)
- || ex2.Message.Contains("txn-mempool-conflict", StringComparison.InvariantCultureIgnoreCase))
+ catch (HttpRequestException ex2) when (RpcParser.IsSpentError(ex2.Message))
{
if (transaction.Transaction.Inputs.Count == 1) // If we tried to only spend one coin, then we can mark it as spent. If there were more coins, then we do not know.
{

MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
@@ -11,6 +11,7 @@ using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Backend.Models.Responses;
+using WalletWasabi.BitcoinCore;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs;
@@ -546,7 +547,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
aliceClient?.Dispose();
return;
}
- catch (HttpRequestException ex) when (ex.Message.Contains("too-long-mempool-chain", StringComparison.InvariantCultureIgnoreCase))
+ catch (HttpRequestException ex) when (RpcParser.IsTooLongMempoolChainError(ex.Message))
{
Logger.LogInfo("Coordinator failed because too much unconfirmed parent transactions. Trying again later.");
aliceClient?.Dispose();

Remove multiple definitions of constants.