From f48bb5a40a8cdfde1b1ecfc032758b495ffb8f1a Mon Sep 17 00:00:00 2001 From: d11n Date: Wed, 15 Jun 2022 04:17:10 +0200 Subject: [PATCH] Fix build warnings (#3870) Fixes #3866. --- BTCPayServer.Client/Models/AssetPairData.cs | 9 +++---- .../GreenField/GreenfieldAppsController.cs | 8 ++++-- .../Controllers/UIInvoiceController.UI.cs | 9 ++++++- BTCPayServer/HostedServices/InvoiceWatcher.cs | 25 +++++++++---------- .../OnChainAutomatedPayoutProcessor.cs | 2 +- .../Services/Stores/StoreRepository.cs | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/BTCPayServer.Client/Models/AssetPairData.cs b/BTCPayServer.Client/Models/AssetPairData.cs index 65cc1b88f..1503695bf 100644 --- a/BTCPayServer.Client/Models/AssetPairData.cs +++ b/BTCPayServer.Client/Models/AssetPairData.cs @@ -2,21 +2,20 @@ namespace BTCPayServer.Client.Models; public class AssetPairData { - public AssetPairData() { } - public AssetPairData(string AssetBought, string AssetSold) + public AssetPairData(string assetBought, string assetSold) { - this.AssetBought = AssetBought; - this.AssetSold = AssetSold; + AssetBought = assetBought; + AssetSold = assetSold; } public string AssetBought { set; get; } public string AssetSold { set; get; } - public string ToString() + public override string ToString() { return AssetBought + "/" + AssetSold; } diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldAppsController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldAppsController.cs index 1d432679e..035397c82 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldAppsController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldAppsController.cs @@ -43,8 +43,12 @@ namespace BTCPayServer.Controllers.Greenfield { return validationResult; } - - var defaultCurrency = (await _storeRepository.FindStore(storeId)).GetStoreBlob().DefaultCurrency; + + var store = await _storeRepository.FindStore(storeId); + if (store == null) + return this.CreateAPIError(404, "store-not-found", "The store was not found"); + + var defaultCurrency = store.GetStoreBlob().DefaultCurrency; var appData = new AppData { StoreDataId = storeId, diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 4c1dbd2f9..dd1e1c0e8 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -86,7 +86,7 @@ namespace BTCPayServer.Controllers [Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] public async Task Invoice(string invoiceId) { - var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery() + var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery { InvoiceId = new[] { invoiceId }, UserId = GetUserId(), @@ -99,6 +99,9 @@ namespace BTCPayServer.Controllers return NotFound(); var store = await _StoreRepository.FindStore(invoice.StoreId); + if (store == null) + return NotFound(); + var invoiceState = invoice.GetInvoiceState(); var model = new InvoiceDetailsModel { @@ -541,7 +544,11 @@ namespace BTCPayServer.Controllers var invoice = await _InvoiceRepository.GetInvoice(invoiceId); if (invoice == null) return null; + var store = await _StoreRepository.FindStore(invoice.StoreId); + if (store == null) + return null; + bool isDefaultPaymentId = false; if (paymentMethodId is null) { diff --git a/BTCPayServer/HostedServices/InvoiceWatcher.cs b/BTCPayServer/HostedServices/InvoiceWatcher.cs index 9d97c8ced..259a98b41 100644 --- a/BTCPayServer/HostedServices/InvoiceWatcher.cs +++ b/BTCPayServer/HostedServices/InvoiceWatcher.cs @@ -26,23 +26,22 @@ namespace BTCPayServer.HostedServices Invoice = invoice; } public InvoiceEntity Invoice { get; set; } - public List Events { get; set; } = new List(); + public List Events { get; set; } = new (); - bool _Dirty = false; - private bool _Unaffect; + bool _dirty; public void MarkDirty() { - _Dirty = true; + _dirty = true; } - public bool Dirty => _Dirty; + public bool Dirty => _dirty; - bool _IsBlobUpdated; - public bool IsBlobUpdated => _IsBlobUpdated; + bool _isBlobUpdated; + public bool IsBlobUpdated => _isBlobUpdated; public void BlobUpdated() { - _IsBlobUpdated = true; + _isBlobUpdated = true; } } @@ -66,10 +65,10 @@ namespace BTCPayServer.HostedServices _explorerClientProvider = explorerClientProvider; _notificationSender = notificationSender; _paymentService = paymentService; - this.Logs = logs; + Logs = logs; } - readonly CompositeDisposable leases = new CompositeDisposable(); + readonly CompositeDisposable _leases = new (); private void UpdateInvoice(UpdateInvoiceContext context) @@ -270,11 +269,11 @@ namespace BTCPayServer.HostedServices _Loop = StartLoop(_Cts.Token); _ = WaitPendingInvoices(); - leases.Add(_eventAggregator.Subscribe(b => + _leases.Add(_eventAggregator.Subscribe(b => { Watch(b.InvoiceId); })); - leases.Add(_eventAggregator.SubscribeAsync(async b => + _leases.Add(_eventAggregator.SubscribeAsync(async b => { if (InvoiceEventNotification.HandlesEvent(b.Name)) { @@ -410,7 +409,7 @@ namespace BTCPayServer.HostedServices { if (_Cts == null) return; - leases.Dispose(); + _leases.Dispose(); _Cts.Cancel(); try { diff --git a/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs b/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs index bfdb04fea..cc4c1bf47 100644 --- a/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs +++ b/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs @@ -130,7 +130,7 @@ namespace BTCPayServer.PayoutProcessors.OnChain workingTx = txBuilder.BuildTransaction(true); transfersProcessing.Add(transferRequest); } - catch (NotEnoughFundsException e) + catch (NotEnoughFundsException) { failedAmount = blob.CryptoAmount; diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index d8e969ae1..73c715d70 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -33,7 +33,7 @@ namespace BTCPayServer.Services.Stores { if (storeId == null) return null; - using var ctx = _ContextFactory.CreateContext(); + await using var ctx = _ContextFactory.CreateContext(); var result = await ctx.FindAsync(storeId).ConfigureAwait(false); return result; }