Decouple RPC error tools from RPC Parser
ADD
WalletWasabi/BitcoinCore/Rpc/RpcErrorTools.cs
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace WalletWasabi.BitcoinCore.Rpc
+{
+ public static class RpcErrorTools
+ {
+ 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>
+ {
+ [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.",
+
+ ["invalid password"] = "Wrong password.",
+ ["Invalid wallet name"] = "Invalid wallet name.",
+ ["Wallet name is already taken"] = "Wallet name is already taken."
+ };
+ }
+}

MODIFY
WalletWasabi/BitcoinCore/Rpc/RpcParser.cs
WalletWasabi/BitcoinCore/Rpc/RpcParser.cs
@@ -11,32 +11,6 @@ namespace WalletWasabi.BitcoinCore.Rpc
{
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>
- {
- [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.",
-
- ["invalid password"] = "Wrong password.",
- ["Invalid wallet name"] = "Invalid wallet name.",
- ["Wallet name is already taken"] = "Wallet name is already taken."
- };
-
public static RpcPubkeyType ConvertPubkeyType(string pubKeyType)
{
return pubKeyType switch

MODIFY
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
WalletWasabi/Blockchain/TransactionBroadcasting/TransactionBroadcaster.cs
@@ -97,7 +97,7 @@ namespace WalletWasabi.Blockchain.TransactionBroadcasting
{
await client.BroadcastAsync(transaction).ConfigureAwait(false);
}
- catch (HttpRequestException ex2) when (RpcParser.IsSpentError(ex2.Message))
+ catch (HttpRequestException ex2) when (RpcErrorTools.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
@@ -547,7 +547,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
aliceClient?.Dispose();
return;
}
- catch (HttpRequestException ex) when (RpcParser.IsTooLongMempoolChainError(ex.Message))
+ catch (HttpRequestException ex) when (RpcErrorTools.IsTooLongMempoolChainError(ex.Message))
{
Logger.LogInfo("Coordinator failed because too much unconfirmed parent transactions. Trying again later.");
aliceClient?.Dispose();

MODIFY
WalletWasabi/Extensions/ExceptionExtensions.cs
WalletWasabi/Extensions/ExceptionExtensions.cs
@@ -49,7 +49,7 @@ namespace System
}
}
- foreach (KeyValuePair<string, string> pair in RpcParser.ErrorTranslations)
+ foreach (KeyValuePair<string, string> pair in RpcErrorTools.ErrorTranslations)
{
if (trimmed.Contains(pair.Key, StringComparison.InvariantCultureIgnoreCase))
{

Decouple RPC error tools from RPC Parser