mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
b31fb1a269
* Auto label utxos based on invoice and payjoin This PR introduces automatic labelling to transactions. * If it is an incoming tx to an invoice, it will tag it as such. * If it was a payjoin tx , it will tag it as such. * If a transaction's inputs were exposed to a payjoin sender, we tag it as such. * wip * wip * support in coinselection * remove ugly hack * support wallet transactions page * remove messy loop * better label template helpers * add tests and susbcribe to event * simplify data * fix test * fix label + color * fix remove label * renove useless call * add toString * fix potential crash by txid * trim json keyword in manual label * format file
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore.Internal;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
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))
|
|
{
|
|
if (walletTransactionData.Labels.StartsWith('['))
|
|
{
|
|
blobInfo.Labels.AddRange(JArray.Parse(walletTransactionData.Labels).Values<string>());
|
|
}
|
|
else
|
|
{
|
|
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;
|
|
}
|
|
|
|
walletTransactionData.Labels = JArray.FromObject(blobInfo.Labels).ToString();
|
|
walletTransactionData.Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo));
|
|
}
|
|
}
|
|
}
|