[Refactor] Move SQL classes in their own assembly

This commit is contained in:
nicolas.dorier
2019-08-30 00:24:42 +09:00
parent 5b4e78f8d1
commit f257f9f91d
127 changed files with 896 additions and 787 deletions

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
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))
{
blobInfo.Labels.AddRange(walletTransactionData.Labels.Split(',', StringSplitOptions.RemoveEmptyEntries));
}
return blobInfo;
}
public static void SetBlobInfo(this WalletTransactionData walletTransactionData, WalletTransactionInfo blobInfo)
{
if (blobInfo == null)
{
walletTransactionData.Labels = string.Empty;
walletTransactionData.Blob = Array.Empty<byte>();
return;
}
if (blobInfo.Labels.Any(l => l.Contains(',', StringComparison.OrdinalIgnoreCase)))
throw new ArgumentException(paramName: nameof(blobInfo), message: "Labels must not contains ','");
walletTransactionData.Labels = String.Join(',', blobInfo.Labels);
walletTransactionData.Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo));
}
}
}