using System; using System.Collections.Generic; using System.Threading.Tasks; using BTCPayServer.Client.Models; using BTCPayServer.Lightning; using NBitcoin; namespace BTCPayApp.CommonServer; //methods available on the hub in the client public interface IBTCPayAppHubClient { Task NotifyServerEvent(ServerEvent ev); Task NotifyNetwork(string network); Task NotifyServerNode(string nodeInfo); Task TransactionDetected(TransactionDetectedRequest request); Task NewBlock(string block); Task CreateInvoice(CreateLightningInvoiceRequest createLightningInvoiceRequest); Task GetLightningInvoice(uint256 paymentHash); Task GetLightningPayment(uint256 paymentHash); Task> GetLightningPayments(ListPaymentsParams request); Task> GetLightningInvoices(ListInvoicesParams request); Task PayInvoice(string bolt11, long? amountMilliSatoshi); } //methods available on the hub in the server public interface IBTCPayAppHubServer { Task DeviceMasterSignal(string deviceIdentifier, bool active); Task> Pair(PairRequest request); Task Handshake(AppHandshake request); Task BroadcastTransaction(string tx); Task GetFeeRate(int blockTarget); Task GetBestBlock(); Task FetchTxsAndTheirBlockHeads(string[] txIds); Task DeriveScript(string identifier); Task TrackScripts(string identifier, string[] scripts); Task UpdatePsbt(string[] identifiers, string psbt); Task GetUTXOs(string[] identifiers); Task> GetTransactions(string[] identifiers); Task SendInvoiceUpdate(string identifier, LightningInvoice lightningInvoice); } public class ServerEvent(string type) { public string Type { get; } = type; public string? StoreId { get; init; } public string? UserId { get; init; } public string? InvoiceId { get; init; } } 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} }}"; } } 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; } } 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 Txs { get; set; } public Dictionary Blocks { get; set; } public Dictionary 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 Derivations { get; set; } = new(); }