diff --git a/BTCPayServer.Tests/Extensions.cs b/BTCPayServer.Tests/Extensions.cs index 22f3822eb..1ff3fa6ad 100644 --- a/BTCPayServer.Tests/Extensions.cs +++ b/BTCPayServer.Tests/Extensions.cs @@ -4,6 +4,8 @@ using System.Threading; using System.Threading.Tasks; using BTCPayServer.Tests.Logging; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using OpenQA.Selenium; using Xunit; @@ -11,6 +13,12 @@ namespace BTCPayServer.Tests { public static class Extensions { + private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; + public static string ToJson(this object o) + { + var res = JsonConvert.SerializeObject(o, Formatting.None, jsonSettings); + return res; + } public static void ScrollTo(this IWebDriver driver, By by) { var element = driver.FindElement(by); diff --git a/BTCPayServer/Data/InvoiceDataExtensions.cs b/BTCPayServer/Data/InvoiceDataExtensions.cs index dfefdf645..5ed69fb80 100644 --- a/BTCPayServer/Data/InvoiceDataExtensions.cs +++ b/BTCPayServer/Data/InvoiceDataExtensions.cs @@ -8,6 +8,12 @@ namespace BTCPayServer.Data { public static class InvoiceDataExtensions { + public static InvoiceEntity GetBlob(this Data.InvoiceData invoiceData, BTCPayNetworkProvider networks) + { + var entity = NBitcoin.JsonConverters.Serializer.ToObject(ZipUtils.Unzip(invoiceData.Blob), null); + entity.Networks = networks; + return entity; + } public static InvoiceState GetInvoiceState(this InvoiceData invoiceData) { return new InvoiceState(invoiceData.Status, invoiceData.ExceptionStatus); diff --git a/BTCPayServer/Data/PaymentDataExtensions.cs b/BTCPayServer/Data/PaymentDataExtensions.cs new file mode 100644 index 000000000..46bc10189 --- /dev/null +++ b/BTCPayServer/Data/PaymentDataExtensions.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using BTCPayServer.Services.Invoices; +using Newtonsoft.Json.Linq; + +namespace BTCPayServer.Data +{ + public static class PaymentDataExtensions + { + public static PaymentEntity GetBlob(this Data.PaymentData paymentData, BTCPayNetworkProvider networks) + { + var unziped = ZipUtils.Unzip(paymentData.Blob); + var cryptoCode = "BTC"; + if (JObject.Parse(unziped).TryGetValue("cryptoCode", out var v) && v.Type == JTokenType.String) + cryptoCode = v.Value(); + var network = networks.GetNetwork(cryptoCode); + PaymentEntity paymentEntity = null; + if (network == null) + { + paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject(unziped, null); + } + else + { + paymentEntity = network.ToObject(unziped); + } + paymentEntity.Network = network; + paymentEntity.Accounted = paymentData.Accounted; + return paymentEntity; + } + } +} diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index bd66c6a3c..e2aada89a 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -45,32 +45,6 @@ namespace BTCPayServer { public static class Extensions { - public static InvoiceEntity GetBlob(this Data.InvoiceData invoiceData, BTCPayNetworkProvider networks) - { - var entity = NBitcoin.JsonConverters.Serializer.ToObject(ZipUtils.Unzip(invoiceData.Blob), null); - entity.Networks = networks; - return entity; - } - public static PaymentEntity GetBlob(this Data.PaymentData paymentData, BTCPayNetworkProvider networks) - { - var unziped = ZipUtils.Unzip(paymentData.Blob); - var cryptoCode = "BTC"; - if (JObject.Parse(unziped).TryGetValue("cryptoCode", out var v) && v.Type == JTokenType.String) - cryptoCode = v.Value(); - var network = networks.GetNetwork(cryptoCode); - PaymentEntity paymentEntity = null; - if (network == null) - { - paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject(unziped, null); - } - else - { - paymentEntity = network.ToObject(unziped); - } - paymentEntity.Network = network; - paymentEntity.Accounted = paymentData.Accounted; - return paymentEntity; - } public static bool TryGetPayjoinEndpoint(this BitcoinUrlBuilder bip21, out Uri endpoint) { @@ -483,22 +457,5 @@ namespace BTCPayServer { ctx.Items["BTCPAY.STORESDATA"] = storeData; } - - private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; - public static string ToJson(this object o) - { - var res = JsonConvert.SerializeObject(o, Formatting.None, jsonSettings); - return res; - } - - public static string TrimEnd(this string input, string suffixToRemove, - StringComparison comparisonType) { - - if (input != null && suffixToRemove != null - && input.EndsWith(suffixToRemove, comparisonType)) { - return input.Substring(0, input.Length - suffixToRemove.Length); - } - else return input; - } } }