diff --git a/BTCPayServer.Client/App/IBTCPayAppHubClient.cs b/BTCPayServer.Client/App/IBTCPayAppHubClient.cs index 78e0c17a8..05f7090dc 100644 --- a/BTCPayServer.Client/App/IBTCPayAppHubClient.cs +++ b/BTCPayServer.Client/App/IBTCPayAppHubClient.cs @@ -44,7 +44,7 @@ public interface IBTCPayAppHubServer Task DeriveScript(string identifier); Task TrackScripts(string identifier, string[] scripts); Task UpdatePsbt(string[] identifiers, string psbt); - Task GetUTXOs(string[] identifiers); + Task> GetUTXOs(string[] identifiers); Task> GetTransactions(string[] identifiers); Task SendInvoiceUpdate(LightningInvoice lightningInvoice); Task GetCurrentMaster(); @@ -94,7 +94,6 @@ public class TransactionDetectedRequest public class CoinResponse { - public string? Identifier{ get; set; } public bool Confirmed { get; set; } public string? Script { get; set; } public string? Outpoint { get; set; } diff --git a/BTCPayServer/App/BTCPayAppHub.cs b/BTCPayServer/App/BTCPayAppHub.cs index aa8ccba3e..38c8cdf87 100644 --- a/BTCPayServer/App/BTCPayAppHub.cs +++ b/BTCPayServer/App/BTCPayAppHub.cs @@ -285,9 +285,10 @@ public class BTCPayAppHub : Hub, IBTCPayAppHubServer return resultPsbt.ToHex(); } - public async Task GetUTXOs(string[] identifiers) + public async Task> GetUTXOs(string[] identifiers) { - var result = new List(); + + var result = new Dictionary(); foreach (string identifier in identifiers) { var ts = TrackedSource.Parse(identifier,_explorerClient.Network); @@ -296,17 +297,18 @@ public class BTCPayAppHub : Hub, IBTCPayAppHubServer continue; } var utxos = await _explorerClient.GetUTXOsAsync(ts); - result.AddRange(utxos.GetUnspentUTXOs(0).Select(utxo => new CoinResponse() + result.Add(identifier, utxos.GetUnspentUTXOs(0).Select(utxo => new CoinResponse() { - Identifier = identifier, Confirmed = utxo.Confirmations >0, Script = utxo.ScriptPubKey.ToHex(), Outpoint = utxo.Outpoint.ToString(), Value = utxo.Value.GetValue(_network), Path = utxo.KeyPath?.ToString() - })); + }).ToArray()); + } - return result.ToArray(); + + return result; } public async Task> GetTransactions(string[] identifiers) diff --git a/BTCPayServer/App/BTCPayAppState.cs b/BTCPayServer/App/BTCPayAppState.cs index 3241cb3b3..21a0c3af9 100644 --- a/BTCPayServer/App/BTCPayAppState.cs +++ b/BTCPayServer/App/BTCPayAppState.cs @@ -24,6 +24,7 @@ using Microsoft.Extensions.Logging; using NBitcoin; using NBitcoin.Protocol; using NBXplorer; +using NBXplorer.DerivationStrategy; using NBXplorer.Models; using NewBlockEvent = BTCPayServer.Events.NewBlockEvent; @@ -338,19 +339,27 @@ public class BTCPayAppState : IHostedService _compositeDisposable?.Dispose(); return Task.CompletedTask; } + + private async Task IsTracked(TrackedSource trackedSource) + { + + + return true; + } public async Task Handshake(string contextConnectionId, AppHandshake handshake) { + var ack = new List(); foreach (var ts in handshake.Identifiers) { try { - if (TrackedSource.TryParse(ts, out var trackedSource, ExplorerClient.Network)) + if (TrackedSource.TryParse(ts, out var trackedSource, ExplorerClient.Network) && await IsTracked(trackedSource)) { - ExplorerClient.Track(trackedSource); + ack.Add(ts); + await AddToGroup(ts, contextConnectionId); } - await AddToGroup(ts, contextConnectionId); } catch (Exception e) { @@ -359,9 +368,7 @@ public class BTCPayAppState : IHostedService } } - //TODO: Check if the provided identifiers are already tracked on the server - //TODO: Maybe also introduce a checkpoint to make sure nothing is missed, but this may be somethign to handle alongside VSS - return new AppHandshakeResponse() {IdentifiersAcknowledged = handshake.Identifiers}; + return new AppHandshakeResponse() {IdentifiersAcknowledged = ack.ToArray()}; } public async Task> Pair(string contextConnectionId, PairRequest request)