diff --git a/.globalconfig b/.globalconfig new file mode 100644 index 0000000..086944d --- /dev/null +++ b/.globalconfig @@ -0,0 +1,23 @@ +# Top level global AnalyzerConfig file +is_global = true + +# Remove unused imports +dotnet_diagnostic.IDE0005.severity = error + +# Add braces +dotnet_diagnostic.IDE0011.severity = error + +# Inline variable declaration +dotnet_diagnostic.IDE0018.severity = error + +# Use collection initializers +dotnet_diagnostic.IDE0028.severity = error + +# Simplify default expression +dotnet_diagnostic.IDE0034.severity = error + +# Remove unused parameter +dotnet_diagnostic.IDE0060.severity = error + +# Simplify new expression +dotnet_diagnostic.IDE0090.severity = error diff --git a/BTCPayServer.Plugins.IntegrationTests/Monero/MoneroIntegrationTestBase.cs b/BTCPayServer.Plugins.IntegrationTests/Monero/MoneroAndBitcoinIntegrationTestBase.cs similarity index 100% rename from BTCPayServer.Plugins.IntegrationTests/Monero/MoneroIntegrationTestBase.cs rename to BTCPayServer.Plugins.IntegrationTests/Monero/MoneroAndBitcoinIntegrationTestBase.cs diff --git a/BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginUITest.cs b/BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginIntegrationTest.cs similarity index 99% rename from BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginUITest.cs rename to BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginIntegrationTest.cs index 287dd0c..7c4db0a 100644 --- a/BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginUITest.cs +++ b/BTCPayServer.Plugins.IntegrationTests/Monero/MoneroPluginIntegrationTest.cs @@ -1,6 +1,5 @@ using BTCPayServer.Rating; using BTCPayServer.Services.Rates; -using BTCPayServer.Tests; using BTCPayServer.Tests.Mocks; using Xunit; diff --git a/BTCPayServer.Plugins.UnitTests/Monero/RPC/Models/ParseStringConverterTest.cs b/BTCPayServer.Plugins.UnitTests/Monero/RPC/Models/ParseStringConverterTest.cs index 3e2225b..183ebe2 100644 --- a/BTCPayServer.Plugins.UnitTests/Monero/RPC/Models/ParseStringConverterTest.cs +++ b/BTCPayServer.Plugins.UnitTests/Monero/RPC/Models/ParseStringConverterTest.cs @@ -48,7 +48,7 @@ namespace BTCPayServer.Plugins.UnitTests.Monero.RPC.Models var serializer = new JsonSerializer(); reader.Read(); - Assert.Throws(() => ParseStringConverter.Singleton.ReadJson(reader, typeof(long), null, serializer)); + Assert.Throws(() => ParseStringConverter.Singleton.ReadJson(reader, typeof(long), null, serializer)); } [Fact] diff --git a/Plugins/Monero/BTCPayServer.Plugins.Monero.csproj b/Plugins/Monero/BTCPayServer.Plugins.Monero.csproj index 33ed450..3287596 100644 --- a/Plugins/Monero/BTCPayServer.Plugins.Monero.csproj +++ b/Plugins/Monero/BTCPayServer.Plugins.Monero.csproj @@ -1,6 +1,7 @@ net8.0 + true @@ -29,6 +30,12 @@ + + + true + $(NoWarn);CS1591;CS1573 + + diff --git a/Plugins/Monero/Configuration/MoneroLikeConfiguration.cs b/Plugins/Monero/Configuration/MoneroLikeConfiguration.cs index 95893f3..8fb399a 100644 --- a/Plugins/Monero/Configuration/MoneroLikeConfiguration.cs +++ b/Plugins/Monero/Configuration/MoneroLikeConfiguration.cs @@ -5,8 +5,7 @@ namespace BTCPayServer.Plugins.Monero.Configuration { public class MoneroLikeConfiguration { - public Dictionary MoneroLikeConfigurationItems { get; set; } = - new Dictionary(); + public Dictionary MoneroLikeConfigurationItems { get; set; } = []; } public class MoneroLikeConfigurationItem diff --git a/Plugins/Monero/Controllers/MoneroDaemonCallbackController.cs b/Plugins/Monero/Controllers/MoneroDaemonCallbackController.cs index 41390f1..15468da 100644 --- a/Plugins/Monero/Controllers/MoneroDaemonCallbackController.cs +++ b/Plugins/Monero/Controllers/MoneroDaemonCallbackController.cs @@ -1,4 +1,3 @@ -using BTCPayServer.Filters; using BTCPayServer.Plugins.Monero.RPC; using Microsoft.AspNetCore.Mvc; diff --git a/Plugins/Monero/Controllers/MoneroLikeStoreController.cs b/Plugins/Monero/Controllers/MoneroLikeStoreController.cs index 9207e0c..aa675dd 100644 --- a/Plugins/Monero/Controllers/MoneroLikeStoreController.cs +++ b/Plugins/Monero/Controllers/MoneroLikeStoreController.cs @@ -12,7 +12,6 @@ using BTCPayServer.Abstractions.Extensions; using BTCPayServer.Abstractions.Models; using BTCPayServer.Client; using BTCPayServer.Data; -using BTCPayServer.Filters; using BTCPayServer.Payments; using BTCPayServer.Plugins.Monero.Configuration; using BTCPayServer.Plugins.Monero.Payments; @@ -87,7 +86,11 @@ namespace BTCPayServer.Plugins.Monero.Controllers return _MoneroRpcProvider.WalletRpcClients[cryptoCode].SendCommandAsync("get_accounts", new GetAccountsRequest()); } } - catch { } + catch + { + // ignored + } + return Task.FromResult(null); } @@ -224,6 +227,7 @@ namespace BTCPayServer.Plugins.Monero.Controllers } catch { + // ignored } } @@ -237,8 +241,8 @@ namespace BTCPayServer.Plugins.Monero.Controllers } catch { + // ignored } - } fileAddress = Path.Combine(configurationItem.WalletDirectory, "password"); @@ -251,6 +255,7 @@ namespace BTCPayServer.Plugins.Monero.Controllers } catch { + // ignored } } @@ -263,7 +268,7 @@ namespace BTCPayServer.Plugins.Monero.Controllers }); if (response?.Error != null) { - throw new Exception(response.Error.Message); + throw new WalletOpenException(response.Error.Message); } } catch (Exception ex) diff --git a/Plugins/Monero/Controllers/WalletOpenException.cs b/Plugins/Monero/Controllers/WalletOpenException.cs new file mode 100644 index 0000000..e1b1e00 --- /dev/null +++ b/Plugins/Monero/Controllers/WalletOpenException.cs @@ -0,0 +1,5 @@ +using System; + +namespace BTCPayServer.Plugins.Monero.Controllers; + +public class WalletOpenException(string message) : Exception(message); \ No newline at end of file diff --git a/Plugins/Monero/Payments/MoneroLikeOnChainPaymentMethodDetails.cs b/Plugins/Monero/Payments/MoneroLikeOnChainPaymentMethodDetails.cs index 4dbc8e2..0e0bf5e 100644 --- a/Plugins/Monero/Payments/MoneroLikeOnChainPaymentMethodDetails.cs +++ b/Plugins/Monero/Payments/MoneroLikeOnChainPaymentMethodDetails.cs @@ -1,5 +1,3 @@ -using BTCPayServer.Payments; - namespace BTCPayServer.Plugins.Monero.Payments { public class MoneroLikeOnChainPaymentMethodDetails diff --git a/Plugins/Monero/Payments/MoneroLikePaymentData.cs b/Plugins/Monero/Payments/MoneroLikePaymentData.cs index 44f1d6e..8aee98e 100644 --- a/Plugins/Monero/Payments/MoneroLikePaymentData.cs +++ b/Plugins/Monero/Payments/MoneroLikePaymentData.cs @@ -1,9 +1,3 @@ -using BTCPayServer.Client.Models; -using BTCPayServer.Payments; -using BTCPayServer.Plugins.Altcoins; -using BTCPayServer.Plugins.Monero.Utils; -using BTCPayServer.Services.Invoices; - namespace BTCPayServer.Plugins.Monero.Payments { public class MoneroLikePaymentData diff --git a/Plugins/Monero/Payments/MoneroLikePaymentMethodHandler.cs b/Plugins/Monero/Payments/MoneroLikePaymentMethodHandler.cs index 681b935..19d7af6 100644 --- a/Plugins/Monero/Payments/MoneroLikePaymentMethodHandler.cs +++ b/Plugins/Monero/Payments/MoneroLikePaymentMethodHandler.cs @@ -62,8 +62,12 @@ namespace BTCPayServer.Plugins.Monero.Payments { throw new PaymentMethodUnavailableException($"BTCPAY_XMR_WALLET_DAEMON_URI or BTCPAY_XMR_DAEMON_URI isn't configured"); } + if (!_moneroRpcProvider.IsAvailable(_network.CryptoCode) || context.State is not Prepare moneroPrepare) + { throw new PaymentMethodUnavailableException($"Node or wallet not available"); + } + var invoice = context.InvoiceEntity; var feeRatePerKb = await moneroPrepare.GetFeeRate; var address = await moneroPrepare.ReserveAddress(invoice.Id); diff --git a/Plugins/Monero/Payments/MoneroPaymentLinkExtension.cs b/Plugins/Monero/Payments/MoneroPaymentLinkExtension.cs index efd719e..9278b62 100644 --- a/Plugins/Monero/Payments/MoneroPaymentLinkExtension.cs +++ b/Plugins/Monero/Payments/MoneroPaymentLinkExtension.cs @@ -2,7 +2,6 @@ using System.Globalization; using BTCPayServer.Payments; -using BTCPayServer.Plugins.Altcoins; using BTCPayServer.Services.Invoices; using Microsoft.AspNetCore.Mvc; diff --git a/Plugins/Monero/Payments/MoneroPaymentPromptDetails.cs b/Plugins/Monero/Payments/MoneroPaymentPromptDetails.cs index 021918f..c6c2a2e 100644 --- a/Plugins/Monero/Payments/MoneroPaymentPromptDetails.cs +++ b/Plugins/Monero/Payments/MoneroPaymentPromptDetails.cs @@ -1,7 +1,3 @@ -using BTCPayServer.Payments; - -using Newtonsoft.Json; - namespace BTCPayServer.Plugins.Monero.Payments { public class MoneroPaymentPromptDetails diff --git a/Plugins/Monero/RPC/JsonRpcClient.cs b/Plugins/Monero/RPC/JsonRpcClient.cs index ce22a6a..f7284ca 100644 --- a/Plugins/Monero/RPC/JsonRpcClient.cs +++ b/Plugins/Monero/RPC/JsonRpcClient.cs @@ -27,7 +27,7 @@ namespace BTCPayServer.Plugins.Monero.RPC public async Task SendCommandAsync(string method, TRequest data, - CancellationToken cts = default(CancellationToken)) + CancellationToken cts = default) { var jsonSerializer = new JsonSerializerSettings { @@ -75,7 +75,7 @@ namespace BTCPayServer.Plugins.Monero.RPC public class NoRequestModel { - public static readonly NoRequestModel Instance = new NoRequestModel(); + public static readonly NoRequestModel Instance = new(); } public class JsonRpcApiException : Exception diff --git a/Plugins/Monero/RPC/Models/GetAddressRequest.cs b/Plugins/Monero/RPC/Models/GetAddressRequest.cs index 623d8ef..7b6916b 100644 --- a/Plugins/Monero/RPC/Models/GetAddressRequest.cs +++ b/Plugins/Monero/RPC/Models/GetAddressRequest.cs @@ -1,5 +1,4 @@ - -using Newtonsoft.Json; +using Newtonsoft.Json; namespace BTCPayServer.Plugins.Monero.RPC.Models; diff --git a/Plugins/Monero/RPC/Models/GetInfoResponse.cs b/Plugins/Monero/RPC/Models/GetInfoResponse.cs index 6db434d..b9a663c 100644 --- a/Plugins/Monero/RPC/Models/GetInfoResponse.cs +++ b/Plugins/Monero/RPC/Models/GetInfoResponse.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - using Newtonsoft.Json; namespace BTCPayServer.Plugins.Monero.RPC.Models diff --git a/Plugins/Monero/RPC/Models/ParseStringConverter.cs b/Plugins/Monero/RPC/Models/ParseStringConverter.cs index 4bf3b89..c79b7d7 100644 --- a/Plugins/Monero/RPC/Models/ParseStringConverter.cs +++ b/Plugins/Monero/RPC/Models/ParseStringConverter.cs @@ -16,13 +16,12 @@ namespace BTCPayServer.Plugins.Monero.RPC.Models return null; } var value = serializer.Deserialize(reader); - long l; - if (Int64.TryParse(value, out l)) + if (Int64.TryParse(value, out long l)) { return l; } - throw new Exception("Cannot unmarshal type long"); + throw new FormatException("Cannot unmarshal type long"); } public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) @@ -38,6 +37,6 @@ namespace BTCPayServer.Plugins.Monero.RPC.Models return; } - public static readonly ParseStringConverter Singleton = new ParseStringConverter(); + public static readonly ParseStringConverter Singleton = new(); } } \ No newline at end of file diff --git a/Plugins/Monero/Services/MoneroCheckoutCheatModeExtension.cs b/Plugins/Monero/Services/MoneroCheckoutCheatModeExtension.cs index 1dd9a70..57e8b7f 100644 --- a/Plugins/Monero/Services/MoneroCheckoutCheatModeExtension.cs +++ b/Plugins/Monero/Services/MoneroCheckoutCheatModeExtension.cs @@ -1,13 +1,9 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using BTCPayServer.Payments; -using BTCPayServer.Plugins.Altcoins; using BTCPayServer.Plugins.Monero.RPC; using BTCPayServer.Plugins.Monero.RPC.Models; -using NBitcoin; - namespace BTCPayServer.Plugins.Monero.Services; public class MoneroCheckoutCheatModeExtension : ICheckoutCheatModeExtension diff --git a/Plugins/Monero/Services/MoneroLikeSummaryUpdaterHostedService.cs b/Plugins/Monero/Services/MoneroLikeSummaryUpdaterHostedService.cs index c7e0a39..899c029 100644 --- a/Plugins/Monero/Services/MoneroLikeSummaryUpdaterHostedService.cs +++ b/Plugins/Monero/Services/MoneroLikeSummaryUpdaterHostedService.cs @@ -60,7 +60,10 @@ namespace BTCPayServer.Plugins.Monero.Services } } } - catch when (cancellation.IsCancellationRequested) { } + catch when (cancellation.IsCancellationRequested) + { + // ignored + } } public Task StopAsync(CancellationToken cancellationToken) diff --git a/Plugins/Monero/Services/MoneroListener.cs b/Plugins/Monero/Services/MoneroListener.cs index a986c91..3380f7b 100644 --- a/Plugins/Monero/Services/MoneroListener.cs +++ b/Plugins/Monero/Services/MoneroListener.cs @@ -152,8 +152,7 @@ namespace BTCPayServer.Plugins.Monero.Services foreach (var expandedInvoice in expandedInvoices) { var addressIndexList = - accountToAddressQuery.GetValueOrDefault(expandedInvoice.PaymentMethodDetails.AccountIndex, - new List()); + accountToAddressQuery.GetValueOrDefault(expandedInvoice.PaymentMethodDetails.AccountIndex, []); addressIndexList.AddRange( expandedInvoice.ExistingPayments.Select(tuple => tuple.PaymentData.SubaddressIndex)); @@ -210,7 +209,7 @@ namespace BTCPayServer.Plugins.Monero.Services } - return HandlePaymentData(cryptoCode, transfer.Address, transfer.Amount, transfer.SubaddrIndex.Major, + return HandlePaymentData(cryptoCode, transfer.Amount, transfer.SubaddrIndex.Major, transfer.SubaddrIndex.Minor, transfer.Txid, transfer.Confirmations, transfer.Height, transfer.UnlockTime, invoice, updatedPaymentEntities); @@ -259,7 +258,6 @@ namespace BTCPayServer.Plugins.Monero.Services var index = destination.First().SubaddrIndex; await HandlePaymentData(cryptoCode, - destination.Key, destination.Sum(destination1 => destination1.Amount), index.Major, index.Minor, @@ -329,7 +327,7 @@ namespace BTCPayServer.Plugins.Monero.Services } } - private async Task HandlePaymentData(string cryptoCode, string address, long totalAmount, long subaccountIndex, + private async Task HandlePaymentData(string cryptoCode, long totalAmount, long subaccountIndex, long subaddressIndex, string txId, long confirmations, long blockHeight, long locktime, InvoiceEntity invoice, List<(PaymentEntity Payment, InvoiceEntity invoice)> paymentsToUpdate) diff --git a/Plugins/Monero/Services/MoneroRPCProvider.cs b/Plugins/Monero/Services/MoneroRPCProvider.cs index 86dfc8c..37cf160 100644 --- a/Plugins/Monero/Services/MoneroRPCProvider.cs +++ b/Plugins/Monero/Services/MoneroRPCProvider.cs @@ -25,8 +25,7 @@ namespace BTCPayServer.Plugins.Monero.Services public ImmutableDictionary DaemonRpcClients; public ImmutableDictionary WalletRpcClients; - private readonly ConcurrentDictionary _summaries = - new ConcurrentDictionary(); + private readonly ConcurrentDictionary _summaries = new(); public ConcurrentDictionary Summaries => _summaries; @@ -185,6 +184,7 @@ namespace BTCPayServer.Plugins.Monero.Services } catch { + // ignored } await walletRpcClient.SendCommandAsync("create_wallet", diff --git a/Plugins/Monero/Utils/MoneroMoney.cs b/Plugins/Monero/Utils/MoneroMoney.cs index 20f2db9..9907b6b 100644 --- a/Plugins/Monero/Utils/MoneroMoney.cs +++ b/Plugins/Monero/Utils/MoneroMoney.cs @@ -2,7 +2,7 @@ using System.Globalization; namespace BTCPayServer.Plugins.Monero.Utils { - public class MoneroMoney + public static class MoneroMoney { public static decimal Convert(long piconero) { diff --git a/README.md b/README.md index 3192395..e3cc478 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ We use the **unmodified** standardized `.editorconfig` from .NET SDK. Run `dotne To enforce formatting for the whole project, run `dotnet format btcpay-monero-plugin.sln --exclude submodules/* --verbosity diagnostic` +To enforce custom analyzer configuration options, we do use global _AnalyzerConfig_ `.globalconfig` file. + ## 4. Configure BTCPay Server to Load the Plugin For vscode, open the `launch.json` file in the `.vscode` folder and set the `launchSettingsProfile` to `Altcoins-HTTPS`. diff --git a/btcpay-monero-plugin.sln b/btcpay-monero-plugin.sln index eb8942e..708a9bf 100644 --- a/btcpay-monero-plugin.sln +++ b/btcpay-monero-plugin.sln @@ -32,6 +32,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{BDB6EEEA-4 .dockerignore = .dockerignore .gitignore = .gitignore .gitmodules = .gitmodules + .editorconfig = .editorconfig + .globalconfig = .globalconfig LICENSE.md = LICENSE.md README.md = README.md EndProjectSection @@ -87,10 +89,10 @@ Global {BC95362E-D430-4CB4-B888-EE1C054C1E7A}.Debug|Any CPU.Build.0 = Debug|Any CPU {BC95362E-D430-4CB4-B888-EE1C054C1E7A}.Release|Any CPU.ActiveCfg = Release|Any CPU {BC95362E-D430-4CB4-B888-EE1C054C1E7A}.Release|Any CPU.Build.0 = Release|Any CPU - {EE24163B-B82C-4561-92F2-C7198CE91F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EE24163B-B82C-4561-92F2-C7198CE91F67}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EE24163B-B82C-4561-92F2-C7198CE91F67}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EE24163B-B82C-4561-92F2-C7198CE91F67}.Release|Any CPU.Build.0 = Release|Any CPU + {DA3599F0-C2DD-4323-A52F-DED5F86722ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA3599F0-C2DD-4323-A52F-DED5F86722ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA3599F0-C2DD-4323-A52F-DED5F86722ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA3599F0-C2DD-4323-A52F-DED5F86722ED}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {049FC011-1952-4140-9652-12921C106B02} = {891F21E0-262C-4430-90C5-7A540AD7C9AD}