mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Move extensions methods in specific classes
This commit is contained in:
@@ -4,6 +4,8 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Tests.Logging;
|
using BTCPayServer.Tests.Logging;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using OpenQA.Selenium;
|
using OpenQA.Selenium;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@@ -11,6 +13,12 @@ namespace BTCPayServer.Tests
|
|||||||
{
|
{
|
||||||
public static class Extensions
|
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)
|
public static void ScrollTo(this IWebDriver driver, By by)
|
||||||
{
|
{
|
||||||
var element = driver.FindElement(by);
|
var element = driver.FindElement(by);
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ namespace BTCPayServer.Data
|
|||||||
{
|
{
|
||||||
public static class InvoiceDataExtensions
|
public static class InvoiceDataExtensions
|
||||||
{
|
{
|
||||||
|
public static InvoiceEntity GetBlob(this Data.InvoiceData invoiceData, BTCPayNetworkProvider networks)
|
||||||
|
{
|
||||||
|
var entity = NBitcoin.JsonConverters.Serializer.ToObject<InvoiceEntity>(ZipUtils.Unzip(invoiceData.Blob), null);
|
||||||
|
entity.Networks = networks;
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
public static InvoiceState GetInvoiceState(this InvoiceData invoiceData)
|
public static InvoiceState GetInvoiceState(this InvoiceData invoiceData)
|
||||||
{
|
{
|
||||||
return new InvoiceState(invoiceData.Status, invoiceData.ExceptionStatus);
|
return new InvoiceState(invoiceData.Status, invoiceData.ExceptionStatus);
|
||||||
|
|||||||
33
BTCPayServer/Data/PaymentDataExtensions.cs
Normal file
33
BTCPayServer/Data/PaymentDataExtensions.cs
Normal file
@@ -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<string>();
|
||||||
|
var network = networks.GetNetwork<BTCPayNetworkBase>(cryptoCode);
|
||||||
|
PaymentEntity paymentEntity = null;
|
||||||
|
if (network == null)
|
||||||
|
{
|
||||||
|
paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject<PaymentEntity>(unziped, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
paymentEntity = network.ToObject<PaymentEntity>(unziped);
|
||||||
|
}
|
||||||
|
paymentEntity.Network = network;
|
||||||
|
paymentEntity.Accounted = paymentData.Accounted;
|
||||||
|
return paymentEntity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,32 +45,6 @@ namespace BTCPayServer
|
|||||||
{
|
{
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
public static InvoiceEntity GetBlob(this Data.InvoiceData invoiceData, BTCPayNetworkProvider networks)
|
|
||||||
{
|
|
||||||
var entity = NBitcoin.JsonConverters.Serializer.ToObject<InvoiceEntity>(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<string>();
|
|
||||||
var network = networks.GetNetwork<BTCPayNetworkBase>(cryptoCode);
|
|
||||||
PaymentEntity paymentEntity = null;
|
|
||||||
if (network == null)
|
|
||||||
{
|
|
||||||
paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject<PaymentEntity>(unziped, null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
paymentEntity = network.ToObject<PaymentEntity>(unziped);
|
|
||||||
}
|
|
||||||
paymentEntity.Network = network;
|
|
||||||
paymentEntity.Accounted = paymentData.Accounted;
|
|
||||||
return paymentEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool TryGetPayjoinEndpoint(this BitcoinUrlBuilder bip21, out Uri endpoint)
|
public static bool TryGetPayjoinEndpoint(this BitcoinUrlBuilder bip21, out Uri endpoint)
|
||||||
{
|
{
|
||||||
@@ -483,22 +457,5 @@ namespace BTCPayServer
|
|||||||
{
|
{
|
||||||
ctx.Items["BTCPAY.STORESDATA"] = storeData;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user