diff --git a/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj b/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj index da07f55..20834b2 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj +++ b/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj @@ -9,7 +9,7 @@ Breez / Greenlight Lightweight lightning baby! - 1.0.5 + 1.0.6 true @@ -34,7 +34,7 @@ - + diff --git a/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs b/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs index 16c63c4..90e338e 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs +++ b/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs @@ -74,6 +74,18 @@ public class BreezController : Controller return View((object) storeId); } + [HttpGet("logs")] + [Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] + public async Task Logs(string storeId) + { + var client = _breezService.GetClient(storeId); + if (client is null) + { + return RedirectToAction(nameof(Configure), new {storeId}); + } + + return View( client.Events); + } [HttpGet("sweep")] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] diff --git a/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs b/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs index ebbe1a2..f7657f4 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs +++ b/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs @@ -22,6 +22,8 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener private readonly NBitcoin.Network _network; public readonly string PaymentKey; + public ConcurrentQueue<(DateTimeOffset timestamp, string log)> Events { get; set; } = new(); + public BreezLightningClient(string inviteCode, string apiKey, string workingDir, NBitcoin.Network network, Mnemonic mnemonic, string paymentKey) { @@ -60,6 +62,19 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener public void OnEvent(BreezEvent e) { + var msg = e switch + { + BreezEvent.BackupFailed backupFailed => $"{e.GetType().Name}: {backupFailed.details.error}", + BreezEvent.InvoicePaid invoicePaid => $"{e.GetType().Name}: {invoicePaid.details.paymentHash}", + BreezEvent.PaymentFailed paymentFailed => $"{e.GetType().Name}: {paymentFailed.details.error} {paymentFailed.details.invoice?.paymentHash}", + BreezEvent.PaymentSucceed paymentSucceed => $"{e.GetType().Name}: {paymentSucceed.details.id}", + BreezEvent.SwapUpdated swapUpdated => $"{e.GetType().Name}: {swapUpdated.details.status} {ConvertHelper.ToHexString(swapUpdated.details.paymentHash.ToArray())} {swapUpdated.details.bitcoinAddress}", + _ => e.GetType().Name + }; + + Events.Enqueue((DateTimeOffset.Now, msg)); + if(Events.Count > 100) + Events.TryDequeue(out _); EventReceived?.Invoke(this, e); } diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Logs.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Logs.cshtml new file mode 100644 index 0000000..3c637c1 --- /dev/null +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Logs.cshtml @@ -0,0 +1,46 @@ +@using BTCPayServer +@model System.Collections.Concurrent.ConcurrentQueue<(DateTimeOffset timestamp, string log)> +@{ + var storeId = Context.GetCurrentStoreId(); + + ViewData.SetActivePage("Breez", "Logs", "Logs"); +} + + + + @if (!Model.Any()) + { + + There are no recent logs. + + } + else + { + + + + + Timestamp + Log + + + + @foreach (var log in Model) + { + + + @log.timestamp.ToTimeAgo() + + + + @log.log + + + + } + + + + } + + \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml index 36ae375..24a12b4 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml @@ -1,14 +1,18 @@ -@using BTCPayServer.Abstractions.Extensions +@using BTCPayServer +@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Plugins.Breez @using BTCPayServer.Security +@using Microsoft.AspNetCore.Mvc.TagHelpers @using Microsoft.AspNetCore.Routing @model string @inject BreezService BreezService +@inject BTCPayNetworkProvider BtcPayNetworkProvider @{ var storeId = Context.GetImplicitStoreId(); var address = Context.GetRouteValue("address").ToString(); ViewData.SetActivePage("Breez", "Create Swapin Refund", "SwapIn"); + var deriv = Context.GetStoreData().GetDerivationSchemeSettings(BtcPayNetworkProvider, "BTC"); var sdk = BreezService.GetClient(storeId)?.Sdk; var f = sdk.RecommendedFees(); } @@ -20,7 +24,12 @@ Economic fee (@f.economyFee sat/vB) Minimum fee (@f.minimumFee sat/vB) - + + @if (deriv is not null) + { + Store wallet + } + @@ -40,7 +49,7 @@ Refund address - + Fees diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml index d6cd06b..b78ff32 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml @@ -13,7 +13,8 @@ StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, _ => Context.GetImplicitStoreId() }; - var sdk = BreezService.GetClient(storeId)?.Sdk; + var client = BreezService.GetClient(storeId); + var sdk = client?.Sdk; } @@ -30,7 +31,11 @@ Swap Out Configuration - + @if (client.Events.Any()) + { + Logs + } + } \ No newline at end of file
+ There are no recent logs. +