mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
small refactor to the signature
This commit is contained in:
parent
360037c6cc
commit
80dd5d7b6f
@ -44,7 +44,7 @@ public interface IBTCPayAppHubServer
|
||||
Task<string> DeriveScript(string identifier);
|
||||
Task TrackScripts(string identifier, string[] scripts);
|
||||
Task<string> UpdatePsbt(string[] identifiers, string psbt);
|
||||
Task<CoinResponse[]> GetUTXOs(string[] identifiers);
|
||||
Task<Dictionary<string, CoinResponse[]>> GetUTXOs(string[] identifiers);
|
||||
Task<Dictionary<string, TxResp[]>> GetTransactions(string[] identifiers);
|
||||
Task SendInvoiceUpdate(LightningInvoice lightningInvoice);
|
||||
Task<long?> 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; }
|
||||
|
@ -285,9 +285,10 @@ public class BTCPayAppHub : Hub<IBTCPayAppHubClient>, IBTCPayAppHubServer
|
||||
return resultPsbt.ToHex();
|
||||
}
|
||||
|
||||
public async Task<CoinResponse[]> GetUTXOs(string[] identifiers)
|
||||
public async Task<Dictionary<string, CoinResponse[]>> GetUTXOs(string[] identifiers)
|
||||
{
|
||||
var result = new List<CoinResponse>();
|
||||
|
||||
var result = new Dictionary<string, CoinResponse[]>();
|
||||
foreach (string identifier in identifiers)
|
||||
{
|
||||
var ts = TrackedSource.Parse(identifier,_explorerClient.Network);
|
||||
@ -296,17 +297,18 @@ public class BTCPayAppHub : Hub<IBTCPayAppHubClient>, 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<Dictionary<string, TxResp[]>> GetTransactions(string[] identifiers)
|
||||
|
@ -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<bool> IsTracked(TrackedSource trackedSource)
|
||||
{
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<AppHandshakeResponse> Handshake(string contextConnectionId, AppHandshake handshake)
|
||||
{
|
||||
var ack = new List<string>();
|
||||
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<Dictionary<string, string>> Pair(string contextConnectionId, PairRequest request)
|
||||
|
Loading…
Reference in New Issue
Block a user