diff --git a/BTCPayServer.Common/BTCPayNetworkProvider.cs b/BTCPayServer.Common/BTCPayNetworkProvider.cs index 15951d397..83bc3a4e1 100644 --- a/BTCPayServer.Common/BTCPayNetworkProvider.cs +++ b/BTCPayServer.Common/BTCPayNetworkProvider.cs @@ -22,13 +22,14 @@ namespace BTCPayServer } } - BTCPayNetworkProvider(BTCPayNetworkProvider filtered, string[] cryptoCodes) + BTCPayNetworkProvider(BTCPayNetworkProvider unfiltered, string[] cryptoCodes) { - NetworkType = filtered.NetworkType; - _NBXplorerNetworkProvider = new NBXplorerNetworkProvider(filtered.NetworkType); + UnfilteredNetworks = unfiltered.UnfilteredNetworks ?? unfiltered; + NetworkType = unfiltered.NetworkType; + _NBXplorerNetworkProvider = new NBXplorerNetworkProvider(unfiltered.NetworkType); _Networks = new Dictionary(); cryptoCodes = cryptoCodes.Select(c => c.ToUpperInvariant()).ToArray(); - foreach (var network in filtered._Networks) + foreach (var network in unfiltered._Networks) { if(cryptoCodes.Contains(network.Key)) { @@ -37,9 +38,12 @@ namespace BTCPayServer } } + public BTCPayNetworkProvider UnfilteredNetworks { get; } + public NetworkType NetworkType { get; private set; } public BTCPayNetworkProvider(NetworkType networkType) { + UnfilteredNetworks = this; _NBXplorerNetworkProvider = new NBXplorerNetworkProvider(networkType); NetworkType = networkType; InitBitcoin(); diff --git a/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs b/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs index aad4468af..df0c192c3 100644 --- a/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs +++ b/BTCPayServer/Payments/PaymentTypes.Bitcoin.cs @@ -2,6 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Payments.Bitcoin; +using BTCPayServer.Services.Invoices; +using Newtonsoft.Json; namespace BTCPayServer.Payments { @@ -15,5 +18,10 @@ namespace BTCPayServer.Payments public override string ToPrettyString() => "On-Chain"; public override string GetId() => "BTCLike"; + + public override CryptoPaymentData DeserializePaymentData(string cryptoPaymentData) + { + return JsonConvert.DeserializeObject(cryptoPaymentData); + } } } diff --git a/BTCPayServer/Payments/PaymentTypes.Lightning.cs b/BTCPayServer/Payments/PaymentTypes.Lightning.cs index de591f0f7..b91c9402e 100644 --- a/BTCPayServer/Payments/PaymentTypes.Lightning.cs +++ b/BTCPayServer/Payments/PaymentTypes.Lightning.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Services.Invoices; +using Newtonsoft.Json; namespace BTCPayServer.Payments { @@ -15,5 +17,10 @@ namespace BTCPayServer.Payments public override string ToPrettyString() => "Off-Chain"; public override string GetId() => "LightningLike"; + + public override CryptoPaymentData DeserializePaymentData(string cryptoPaymentData) + { + return JsonConvert.DeserializeObject(cryptoPaymentData); + } } } diff --git a/BTCPayServer/Payments/PaymentTypes.cs b/BTCPayServer/Payments/PaymentTypes.cs index a799ededf..487611747 100644 --- a/BTCPayServer/Payments/PaymentTypes.cs +++ b/BTCPayServer/Payments/PaymentTypes.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Services.Invoices; namespace BTCPayServer.Payments { @@ -54,5 +55,6 @@ namespace BTCPayServer.Payments } public abstract string GetId(); + public abstract CryptoPaymentData DeserializePaymentData(string cryptoPaymentData); } } diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index 7f86c5e43..9ab7649c7 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -513,7 +513,7 @@ namespace BTCPayServer.Services.Invoices r.CryptoCode = paymentMethodId.CryptoCode; r.PaymentType = paymentMethodId.PaymentType.ToString(); r.ParentEntity = this; - r.Network = Networks?.GetNetwork(r.CryptoCode); + r.Network = Networks?.UnfilteredNetworks.GetNetwork(r.CryptoCode); paymentMethods.Add(r); } } @@ -918,37 +918,31 @@ namespace BTCPayServer.Services.Invoices public CryptoPaymentData GetCryptoPaymentData() { - var paymentMethodId = GetPaymentMethodId(); - if (paymentMethodId.PaymentType == PaymentTypes.LightningLike) + CryptoPaymentData paymentData = null; #pragma warning disable CS0618 // Type or member is obsolete - return JsonConvert.DeserializeObject(CryptoPaymentData); -#pragma warning restore CS0618 // Type or member is obsolete + if (string.IsNullOrEmpty(CryptoPaymentData)) + { + // For invoices created when CryptoPaymentDataType was not existing, we just consider that it is a RBFed payment for safety + var bitcoin = new BitcoinLikePaymentData(); + bitcoin.Outpoint = Outpoint; + bitcoin.Output = Output; + bitcoin.RBF = true; + bitcoin.ConfirmationCount = 0; + bitcoin.Legacy = true; + bitcoin.Output = Output; + bitcoin.Outpoint = Outpoint; + paymentData = bitcoin; + } else { -#pragma warning disable CS0618 - - BitcoinLikePaymentData paymentData; - if (string.IsNullOrEmpty(CryptoPaymentDataType)) + paymentData = GetPaymentMethodId().PaymentType.DeserializePaymentData(CryptoPaymentData); + if (paymentData is BitcoinLikePaymentData bitcoin) { - // For invoices created when CryptoPaymentDataType was not existing, we just consider that it is a RBFed payment for safety - paymentData = new BitcoinLikePaymentData(); - paymentData.Outpoint = Outpoint; - paymentData.Output = Output; - paymentData.RBF = true; - paymentData.ConfirmationCount = 0; - paymentData.Legacy = true; - return paymentData; + bitcoin.Output = Output; + bitcoin.Outpoint = Outpoint; } - - paymentData = - JsonConvert.DeserializeObject(CryptoPaymentData); - // legacy - paymentData.Output = Output; - paymentData.Outpoint = Outpoint; -#pragma warning restore CS0618 - return paymentData; } - + return paymentData; } public PaymentEntity SetCryptoPaymentData(CryptoPaymentData cryptoPaymentData)