mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Auto label utxos based on invoice and payjoin (#1499)
* 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
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
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
|
||||
{
|
||||
@@ -17,7 +19,15 @@ namespace BTCPayServer.Data
|
||||
var blobInfo = JsonConvert.DeserializeObject<WalletTransactionInfo>(ZipUtils.Unzip(walletTransactionData.Blob));
|
||||
if (!string.IsNullOrEmpty(walletTransactionData.Labels))
|
||||
{
|
||||
blobInfo.Labels.AddRange(walletTransactionData.Labels.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
if (walletTransactionData.Labels.StartsWith('['))
|
||||
{
|
||||
blobInfo.Labels.AddRange(JArray.Parse(walletTransactionData.Labels).Values<string>());
|
||||
}
|
||||
else
|
||||
{
|
||||
blobInfo.Labels.AddRange(walletTransactionData.Labels.Split(',',
|
||||
StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
return blobInfo;
|
||||
}
|
||||
@@ -29,9 +39,8 @@ namespace BTCPayServer.Data
|
||||
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.Labels = JArray.FromObject(blobInfo.Labels).ToString();
|
||||
walletTransactionData.Blob = ZipUtils.Zip(JsonConvert.SerializeObject(blobInfo));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user