mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 15:04:19 +01:00
[Refactor] Move SQL classes in their own assembly
This commit is contained in:
39
BTCPayServer/Data/AddressInvoiceDataExtensions.cs
Normal file
39
BTCPayServer/Data/AddressInvoiceDataExtensions.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Payments;
|
||||
|
||||
namespace BTCPayServer.Data
|
||||
{
|
||||
public static class AddressInvoiceDataExtensions
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
public static string GetAddress(this AddressInvoiceData addressInvoiceData)
|
||||
{
|
||||
if (addressInvoiceData.Address == null)
|
||||
return null;
|
||||
var index = addressInvoiceData.Address.LastIndexOf("#", StringComparison.InvariantCulture);
|
||||
if (index == -1)
|
||||
return addressInvoiceData.Address;
|
||||
return addressInvoiceData.Address.Substring(0, index);
|
||||
}
|
||||
public static AddressInvoiceData Set(this AddressInvoiceData addressInvoiceData, string address, PaymentMethodId paymentMethodId)
|
||||
{
|
||||
addressInvoiceData.Address = address + "#" + paymentMethodId.ToString();
|
||||
return addressInvoiceData;
|
||||
}
|
||||
public static PaymentMethodId GetpaymentMethodId(this AddressInvoiceData addressInvoiceData)
|
||||
{
|
||||
if (addressInvoiceData.Address == null)
|
||||
return null;
|
||||
var index = addressInvoiceData.Address.LastIndexOf("#", StringComparison.InvariantCulture);
|
||||
// Legacy AddressInvoiceData does not have the paymentMethodId attached to the Address
|
||||
if (index == -1)
|
||||
return PaymentMethodId.Parse("BTC");
|
||||
/////////////////////////
|
||||
return PaymentMethodId.Parse(addressInvoiceData.Address.Substring(index + 1));
|
||||
}
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user