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:
Andrew Camilleri
2020-04-28 08:06:28 +02:00
committed by GitHub
parent 3801eeec43
commit b31fb1a269
16 changed files with 254 additions and 49 deletions

View File

@@ -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));
}
}