2024-05-24 10:56:08 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-05-02 15:00:09 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2024-05-06 16:13:57 +02:00
|
|
|
|
using BTCPayServer.Client.Models;
|
2024-05-08 12:16:25 +02:00
|
|
|
|
using BTCPayServer.Lightning;
|
2024-05-24 10:56:08 +02:00
|
|
|
|
using NBitcoin;
|
2024-05-27 11:34:40 +02:00
|
|
|
|
using LightningPayment = BTCPayApp.CommonServer.Models.LightningPayment;
|
2024-05-02 15:00:09 +02:00
|
|
|
|
|
|
|
|
|
namespace BTCPayApp.CommonServer;
|
|
|
|
|
|
2024-05-06 16:13:57 +02:00
|
|
|
|
|
2024-05-20 11:07:47 +02:00
|
|
|
|
public class TransactionDetectedRequest
|
|
|
|
|
{
|
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
|
public string TxId { get; set; }
|
|
|
|
|
public string[] SpentScripts { get; set; }
|
|
|
|
|
public string[] ReceivedScripts { get; set; }
|
|
|
|
|
public bool Confirmed { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 16:13:57 +02:00
|
|
|
|
|
2024-05-02 15:00:09 +02:00
|
|
|
|
//methods available on the hub in the client
|
|
|
|
|
public interface IBTCPayAppHubClient
|
|
|
|
|
{
|
|
|
|
|
Task NotifyNetwork(string network);
|
2024-05-20 14:02:44 +02:00
|
|
|
|
Task NotifyServerNode(string nodeInfo);
|
2024-05-20 11:07:47 +02:00
|
|
|
|
Task TransactionDetected(TransactionDetectedRequest request);
|
2024-05-02 15:00:09 +02:00
|
|
|
|
Task NewBlock(string block);
|
2024-05-06 16:13:57 +02:00
|
|
|
|
|
|
|
|
|
Task<LightningPayment> CreateInvoice(CreateLightningInvoiceRequest createLightningInvoiceRequest);
|
2024-05-08 12:16:25 +02:00
|
|
|
|
Task<LightningPayment?> GetLightningInvoice(string paymentHash);
|
|
|
|
|
Task<LightningPayment?> GetLightningPayment(string paymentHash);
|
|
|
|
|
Task<List<LightningPayment>> GetLightningPayments(ListPaymentsParams request);
|
|
|
|
|
Task<List<LightningPayment>> GetLightningInvoices(ListInvoicesParams request);
|
2024-05-24 12:11:56 +02:00
|
|
|
|
Task<PayResponse> PayInvoice(string bolt11, long? amountMilliSatoshi);
|
2024-05-02 15:00:09 +02:00
|
|
|
|
}
|
2024-05-24 10:56:08 +02:00
|
|
|
|
|
|
|
|
|
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} }}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 15:00:09 +02:00
|
|
|
|
//methods available on the hub in the server
|
|
|
|
|
public interface IBTCPayAppHubServer
|
|
|
|
|
{
|
2024-06-05 09:14:31 +02:00
|
|
|
|
Task<bool> IdentifierActive(string group, bool active);
|
2024-05-06 14:33:44 +02:00
|
|
|
|
|
2024-05-02 15:00:09 +02:00
|
|
|
|
Task<Dictionary<string,string>> Pair(PairRequest request);
|
|
|
|
|
Task<AppHandshakeResponse> Handshake(AppHandshake request);
|
|
|
|
|
Task<bool> BroadcastTransaction(string tx);
|
|
|
|
|
Task<decimal> GetFeeRate(int blockTarget);
|
|
|
|
|
Task<BestBlockResponse> GetBestBlock();
|
|
|
|
|
Task<string> GetBlockHeader(string hash);
|
|
|
|
|
|
|
|
|
|
Task<TxInfoResponse> FetchTxsAndTheirBlockHeads(string[] txIds);
|
|
|
|
|
Task<string> DeriveScript(string identifier);
|
|
|
|
|
Task TrackScripts(string identifier, string[] scripts);
|
|
|
|
|
Task<string> UpdatePsbt(string[] identifiers, string psbt);
|
|
|
|
|
Task<CoinResponse[]> GetUTXOs(string[] identifiers);
|
2024-05-24 10:56:08 +02:00
|
|
|
|
Task<Dictionary<string, TxResp[]>> GetTransactions(string[] identifiers);
|
2024-05-06 16:13:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Task SendPaymentUpdate(string identifier, LightningPayment lightningPayment);
|
2024-05-02 15:00:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CoinResponse
|
|
|
|
|
{
|
|
|
|
|
public string Identifier{ get; set; }
|
|
|
|
|
public bool Confirmed { get; set; }
|
|
|
|
|
public string Script { get; set; }
|
|
|
|
|
public string Outpoint { get; set; }
|
|
|
|
|
public decimal Value { get; set; }
|
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TxInfoResponse
|
|
|
|
|
{
|
|
|
|
|
public Dictionary<string,TransactionResponse> Txs { get; set; }
|
|
|
|
|
public Dictionary<string,string> Blocks { get; set; }
|
|
|
|
|
public Dictionary<string,int> BlockHeghts { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TransactionResponse
|
|
|
|
|
{
|
|
|
|
|
public string? BlockHash { get; set; }
|
|
|
|
|
public int? BlockHeight { get; set; }
|
|
|
|
|
public string Transaction { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class BestBlockResponse
|
|
|
|
|
{
|
|
|
|
|
public required string BlockHash { get; set; }
|
|
|
|
|
public required int BlockHeight { get; set; }
|
|
|
|
|
|
|
|
|
|
public string BlockHeader { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AppHandshake
|
|
|
|
|
{
|
|
|
|
|
public string[] Identifiers { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AppHandshakeResponse
|
|
|
|
|
{
|
|
|
|
|
//response about identifiers being tracked successfully
|
|
|
|
|
public string[] IdentifiersAcknowledged { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PairRequest
|
|
|
|
|
{
|
|
|
|
|
public Dictionary<string, string?> Derivations { get; set; } = new();
|
|
|
|
|
}
|