mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-23 06:35:13 +01:00
get onchain txs
This commit is contained in:
parent
8c0d1fde45
commit
e1b2bc1a05
2 changed files with 44 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Lightning;
|
||||
using NBitcoin;
|
||||
|
||||
namespace BTCPayApp.CommonServer;
|
||||
|
||||
|
@ -30,6 +32,15 @@ public interface IBTCPayAppHubClient
|
|||
Task<List<LightningPayment>> GetLightningPayments(ListPaymentsParams request);
|
||||
Task<List<LightningPayment>> GetLightningInvoices(ListInvoicesParams request);
|
||||
}
|
||||
|
||||
public record TxResp(long Confirmations, long? Height, decimal BalanceChange, DateTimeOffset Timestamp, string TransactionId)
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ Confirmations = {Confirmations}, Height = {Height}, BalanceChange = {BalanceChange}, Timestamp = {Timestamp}, TransactionId = {TransactionId} }}";
|
||||
}
|
||||
}
|
||||
|
||||
//methods available on the hub in the server
|
||||
public interface IBTCPayAppHubServer
|
||||
{
|
||||
|
@ -47,6 +58,7 @@ public interface IBTCPayAppHubServer
|
|||
Task TrackScripts(string identifier, string[] scripts);
|
||||
Task<string> UpdatePsbt(string[] identifiers, string psbt);
|
||||
Task<CoinResponse[]> GetUTXOs(string[] identifiers);
|
||||
Task<Dictionary<string, TxResp[]>> GetTransactions(string[] identifiers);
|
||||
|
||||
|
||||
Task SendPaymentUpdate(string identifier, LightningPayment lightningPayment);
|
||||
|
|
|
@ -244,9 +244,11 @@ var resultPsbt = PSBT.Parse(psbt, explorerClient.Network.NBitcoinNetwork);
|
|||
foreach (string identifier in identifiers)
|
||||
{
|
||||
var ts = TrackedSource.Parse(identifier,explorerClient.Network);
|
||||
if (ts is not DerivationSchemeTrackedSource derivationSchemeTrackedSource)
|
||||
if (ts is null)
|
||||
{
|
||||
continue;
|
||||
var utxos = await explorerClient.GetUTXOsAsync(derivationSchemeTrackedSource.DerivationStrategy);
|
||||
}
|
||||
var utxos = await explorerClient.GetUTXOsAsync(ts);
|
||||
result.AddRange(utxos.GetUnspentUTXOs(0).Select(utxo => new CoinResponse()
|
||||
{
|
||||
Identifier = identifier,
|
||||
|
@ -254,12 +256,36 @@ var resultPsbt = PSBT.Parse(psbt, explorerClient.Network.NBitcoinNetwork);
|
|||
Script = utxo.ScriptPubKey.ToHex(),
|
||||
Outpoint = utxo.Outpoint.ToString(),
|
||||
Value = utxo.Value.GetValue(_btcPayNetworkProvider.BTC),
|
||||
Path = utxo.KeyPath.ToString()
|
||||
Path = utxo.KeyPath?.ToString()
|
||||
}));
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, TxResp[]>> GetTransactions(string[] identifiers)
|
||||
{
|
||||
var explorerClient = _explorerClientProvider.GetExplorerClient( _btcPayNetworkProvider.BTC);
|
||||
var result = new Dictionary<string, TxResp[]>();
|
||||
foreach (string identifier in identifiers)
|
||||
{
|
||||
var ts = TrackedSource.Parse(identifier,explorerClient.Network);
|
||||
if (ts is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var txs = await explorerClient.GetTransactionsAsync(ts);
|
||||
|
||||
var items = txs.ConfirmedTransactions.Transactions
|
||||
.Concat(txs.UnconfirmedTransactions.Transactions)
|
||||
.Concat(txs.ImmatureTransactions.Transactions)
|
||||
.Concat(txs.ReplacedTransactions.Transactions)
|
||||
.Select(tx => new TxResp(tx.Confirmations, tx.Height, tx.BalanceChange.GetValue(_btcPayNetworkProvider.BTC), tx.Timestamp, tx.TransactionId.ToString())).OrderByDescending(arg => arg.Timestamp);
|
||||
result.Add(identifier,items.ToArray());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task SendPaymentUpdate(string identifier, LightningPayment lightningPayment)
|
||||
{
|
||||
await _appState.PaymentUpdate(identifier, lightningPayment);
|
||||
|
@ -286,3 +312,5 @@ var resultPsbt = PSBT.Parse(psbt, explorerClient.Network.NBitcoinNetwork);
|
|||
return await _appState.Handshake(Context.ConnectionId, request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue