expand tx update notif

This commit is contained in:
Kukks 2024-05-09 17:29:00 +02:00 committed by Dennis Reimann
parent 20c30cf0d1
commit 5b20aca1f2
No known key found for this signature in database
GPG key ID: 5009E1797F03F8D0
2 changed files with 11 additions and 5 deletions

View file

@ -11,7 +11,7 @@ namespace BTCPayApp.CommonServer;
public interface IBTCPayAppHubClient
{
Task NotifyNetwork(string network);
Task TransactionDetected(string identifier, string txId);
Task TransactionDetected(string identifier, string txId, string[] relatedScripts, bool confirmed);
Task NewBlock(string block);
Task<LightningPayment> CreateInvoice(CreateLightningInvoiceRequest createLightningInvoiceRequest);

View file

@ -54,19 +54,25 @@ public class BTCPayAppState : IHostedService
_compositeDisposable.Add(
_eventAggregator.Subscribe<NewBlockEvent>(OnNewBlock));
_compositeDisposable.Add(
_eventAggregator.Subscribe<NewOnChainTransactionEvent>(OnNewTransaction));
_eventAggregator.SubscribeAsync<NewOnChainTransactionEvent>(OnNewTransaction));
return Task.CompletedTask;
}
private void OnNewTransaction(NewOnChainTransactionEvent obj)
private async Task OnNewTransaction(NewOnChainTransactionEvent obj)
{
if (obj.CryptoCode != "BTC")
return;
var identifier = obj.NewTransactionEvent.TrackedSource.ToString()!;
_hubContext.Clients
var explorer = _explorerClientProvider.GetExplorerClient(obj.CryptoCode);
var expandedTx = await explorer.GetTransactionAsync(obj.NewTransactionEvent.TrackedSource,
obj.NewTransactionEvent.TransactionData.TransactionHash);
var scripts = expandedTx.Inputs.Concat(expandedTx.Outputs).Select(output => output.ScriptPubKey.ToHex()).Distinct().ToArray();
await _hubContext.Clients
.Group(identifier)
.TransactionDetected(identifier, obj.NewTransactionEvent.TransactionData.TransactionHash.ToString());
.TransactionDetected(identifier,
obj.NewTransactionEvent.TransactionData.TransactionHash.ToString(), scripts, obj.NewTransactionEvent.BlockId is not null && obj.NewTransactionEvent.BlockId != uint256.Zero);
}
private void OnNewBlock(NewBlockEvent obj)