2020-06-28 21:44:35 -05:00
|
|
|
using BTCPayServer.Client.Models;
|
2019-08-30 00:24:42 +09:00
|
|
|
using NBXplorer;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
{
|
|
|
|
public static class PaymentRequestDataExtensions
|
|
|
|
{
|
2020-05-19 19:59:23 +02:00
|
|
|
public static PaymentRequestBaseData GetBlob(this PaymentRequestData paymentRequestData)
|
2019-08-30 00:24:42 +09:00
|
|
|
{
|
|
|
|
var result = paymentRequestData.Blob == null
|
2020-05-19 19:59:23 +02:00
|
|
|
? new PaymentRequestBaseData()
|
|
|
|
: JObject.Parse(ZipUtils.Unzip(paymentRequestData.Blob)).ToObject<PaymentRequestBaseData>();
|
2019-08-30 00:24:42 +09:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-19 19:59:23 +02:00
|
|
|
public static bool SetBlob(this PaymentRequestData paymentRequestData, PaymentRequestBaseData blob)
|
2019-08-30 00:24:42 +09:00
|
|
|
{
|
2019-11-15 18:53:20 +09:00
|
|
|
var original = new Serializer(null).ToString(paymentRequestData.GetBlob());
|
|
|
|
var newBlob = new Serializer(null).ToString(blob);
|
2019-08-30 00:24:42 +09:00
|
|
|
if (original == newBlob)
|
|
|
|
return false;
|
|
|
|
paymentRequestData.Blob = ZipUtils.Zip(newBlob);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|