2019-08-29 17:24:42 +02:00
|
|
|
using BTCPayServer.Services.Invoices;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
{
|
|
|
|
public static class InvoiceDataExtensions
|
|
|
|
{
|
2022-04-24 05:19:34 +02:00
|
|
|
public static InvoiceEntity GetBlob(this InvoiceData invoiceData, BTCPayNetworkProvider networks)
|
2020-06-28 10:15:42 +02:00
|
|
|
{
|
2022-04-24 05:19:34 +02:00
|
|
|
|
|
|
|
var entity = InvoiceRepository.FromBytes<InvoiceEntity>(invoiceData.Blob);
|
2020-06-28 10:15:42 +02:00
|
|
|
entity.Networks = networks;
|
2020-08-25 07:33:00 +02:00
|
|
|
if (entity.Metadata is null)
|
|
|
|
{
|
|
|
|
if (entity.Version < InvoiceEntity.GreenfieldInvoices_Version)
|
|
|
|
{
|
|
|
|
entity.MigrateLegacyInvoice();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entity.Metadata = new InvoiceMetadata();
|
|
|
|
}
|
|
|
|
}
|
2020-06-28 10:15:42 +02:00
|
|
|
return entity;
|
|
|
|
}
|
2019-08-29 17:24:42 +02:00
|
|
|
public static InvoiceState GetInvoiceState(this InvoiceData invoiceData)
|
|
|
|
{
|
|
|
|
return new InvoiceState(invoiceData.Status, invoiceData.ExceptionStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|