2022-10-11 17:34:29 +09:00
|
|
|
#nullable enable
|
2020-04-28 08:06:28 +02:00
|
|
|
using System.Collections.Generic;
|
2021-12-27 13:46:31 +09:00
|
|
|
using System.Globalization;
|
2020-04-28 08:06:28 +02:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Events;
|
2021-11-22 17:16:08 +09:00
|
|
|
using BTCPayServer.Logging;
|
2020-04-28 08:06:28 +02:00
|
|
|
using BTCPayServer.Payments;
|
|
|
|
using BTCPayServer.Payments.Bitcoin;
|
|
|
|
using BTCPayServer.Services;
|
2020-09-17 16:39:55 +02:00
|
|
|
using BTCPayServer.Services.Apps;
|
2020-12-12 14:10:47 +09:00
|
|
|
using BTCPayServer.Services.Labels;
|
2020-09-17 16:39:55 +02:00
|
|
|
using BTCPayServer.Services.PaymentRequests;
|
2020-04-28 08:06:28 +02:00
|
|
|
using NBitcoin;
|
2022-10-11 17:34:29 +09:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
2020-04-28 08:06:28 +02:00
|
|
|
|
|
|
|
namespace BTCPayServer.HostedServices
|
|
|
|
{
|
|
|
|
public class TransactionLabelMarkerHostedService : EventHostedServiceBase
|
|
|
|
{
|
|
|
|
private readonly EventAggregator _eventAggregator;
|
|
|
|
private readonly WalletRepository _walletRepository;
|
|
|
|
|
2021-11-22 17:16:08 +09:00
|
|
|
public TransactionLabelMarkerHostedService(EventAggregator eventAggregator, WalletRepository walletRepository, Logs logs) :
|
|
|
|
base(eventAggregator, logs)
|
2020-04-28 08:06:28 +02:00
|
|
|
{
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
_walletRepository = walletRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SubscribeToEvents()
|
|
|
|
{
|
|
|
|
Subscribe<InvoiceEvent>();
|
|
|
|
}
|
|
|
|
protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
if (evt is InvoiceEvent invoiceEvent && invoiceEvent.Name == InvoiceEvent.ReceivedPayment &&
|
2020-08-09 14:43:13 +02:00
|
|
|
invoiceEvent.Payment.GetPaymentMethodId()?.PaymentType == BitcoinPaymentType.Instance &&
|
2020-04-28 08:06:28 +02:00
|
|
|
invoiceEvent.Payment.GetCryptoPaymentData() is BitcoinLikePaymentData bitcoinLikePaymentData)
|
|
|
|
{
|
|
|
|
var walletId = new WalletId(invoiceEvent.Invoice.StoreId, invoiceEvent.Payment.GetCryptoCode());
|
|
|
|
var transactionId = bitcoinLikePaymentData.Outpoint.Hash;
|
2022-10-11 17:34:29 +09:00
|
|
|
var labels = new List<Attachment>
|
2020-04-28 08:06:28 +02:00
|
|
|
{
|
2022-10-11 17:34:29 +09:00
|
|
|
Attachment.Invoice(invoiceEvent.Invoice.Id)
|
2020-04-28 08:06:28 +02:00
|
|
|
};
|
2020-09-17 16:39:55 +02:00
|
|
|
foreach (var paymentId in PaymentRequestRepository.GetPaymentIdsFromInternalTags(invoiceEvent.Invoice))
|
|
|
|
{
|
2022-10-11 17:34:29 +09:00
|
|
|
labels.Add(Attachment.PaymentRequest(paymentId));
|
2020-09-17 16:39:55 +02:00
|
|
|
}
|
2021-12-31 16:59:02 +09:00
|
|
|
foreach (var appId in AppService.GetAppInternalTags(invoiceEvent.Invoice))
|
2020-09-17 16:39:55 +02:00
|
|
|
{
|
2022-10-11 17:34:29 +09:00
|
|
|
labels.Add(Attachment.App(appId));
|
2020-09-17 16:39:55 +02:00
|
|
|
}
|
|
|
|
|
2022-10-11 17:34:29 +09:00
|
|
|
await _walletRepository.AddWalletTransactionAttachment(walletId, transactionId, labels);
|
2020-04-28 08:06:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|