2019-08-29 17:24:42 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-04-28 08:06:28 +02:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Internal;
|
2019-08-29 17:24:42 +02:00
|
|
|
|
using Newtonsoft.Json;
|
2020-04-28 08:06:28 +02:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2019-08-29 17:24:42 +02:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
|
{
|
|
|
|
|
public static class WalletTransactionDataExtensions
|
|
|
|
|
{
|
|
|
|
|
public static WalletTransactionInfo GetBlobInfo(this WalletTransactionData walletTransactionData)
|
|
|
|
|
{
|
|
|
|
|
if (walletTransactionData.Blob == null || walletTransactionData.Blob.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return new WalletTransactionInfo();
|
|
|
|
|
}
|
|
|
|
|
var blobInfo = JsonConvert.DeserializeObject<WalletTransactionInfo>(ZipUtils.Unzip(walletTransactionData.Blob));
|
|
|
|
|
if (!string.IsNullOrEmpty(walletTransactionData.Labels))
|
|
|
|
|
{
|
2020-04-28 08:06:28 +02:00
|
|
|
|
if (walletTransactionData.Labels.StartsWith('['))
|
|
|
|
|
{
|
|
|
|
|
blobInfo.Labels.AddRange(JArray.Parse(walletTransactionData.Labels).Values<string>());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
blobInfo.Labels.AddRange(walletTransactionData.Labels.Split(',',
|
|
|
|
|
StringSplitOptions.RemoveEmptyEntries));
|
|
|
|
|
}
|
2019-08-29 17:24:42 +02:00
|
|
|
|
}
|
|
|
|
|
return blobInfo;
|
|
|
|
|
}
|
|
|
|
|
public static void SetBlobInfo(this WalletTransactionData walletTransactionData, WalletTransactionInfo blobInfo)
|
|
|
|
|
{
|
|
|
|
|
if (blobInfo == null)
|
|
|
|
|
{
|
|
|
|
|
walletTransactionData.Labels = string.Empty;
|
|
|
|
|
walletTransactionData.Blob = Array.Empty<byte>();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-28 08:06:28 +02:00
|
|
|
|
|
|
|
|
|
walletTransactionData.Labels = JArray.FromObject(blobInfo.Labels).ToString();
|
2019-08-29 17:24:42 +02:00
|
|
|
|
walletTransactionData.Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|