add logs and bump breez

This commit is contained in:
Kukks
2024-06-18 11:00:28 +02:00
parent 218c694190
commit 0caeaac5b4
6 changed files with 94 additions and 7 deletions

View File

@@ -9,7 +9,7 @@
<PropertyGroup> <PropertyGroup>
<Product>Breez / Greenlight</Product> <Product>Breez / Greenlight</Product>
<Description>Lightweight lightning baby!</Description> <Description>Lightweight lightning baby!</Description>
<Version>1.0.5</Version> <Version>1.0.6</Version>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->
@@ -34,7 +34,7 @@
<ProjectReference Include="..\..\submodules\btcpayserver\BTCPayServer\BTCPayServer.csproj" /> <ProjectReference Include="..\..\submodules\btcpayserver\BTCPayServer\BTCPayServer.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Breez.Sdk" Version="0.4.2-rc1" /> <PackageReference Include="Breez.Sdk" Version="0.4.2-rc3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -74,6 +74,18 @@ public class BreezController : Controller
return View((object) storeId); return View((object) storeId);
} }
[HttpGet("logs")]
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
public async Task<IActionResult> Logs(string storeId)
{
var client = _breezService.GetClient(storeId);
if (client is null)
{
return RedirectToAction(nameof(Configure), new {storeId});
}
return View( client.Events);
}
[HttpGet("sweep")] [HttpGet("sweep")]
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]

View File

@@ -22,6 +22,8 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
private readonly NBitcoin.Network _network; private readonly NBitcoin.Network _network;
public readonly string PaymentKey; 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, public BreezLightningClient(string inviteCode, string apiKey, string workingDir, NBitcoin.Network network,
Mnemonic mnemonic, string paymentKey) Mnemonic mnemonic, string paymentKey)
{ {
@@ -60,6 +62,19 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
public void OnEvent(BreezEvent e) 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); EventReceived?.Invoke(this, e);
} }

View File

@@ -0,0 +1,46 @@
@using BTCPayServer
@model System.Collections.Concurrent.ConcurrentQueue<(DateTimeOffset timestamp, string log)>
@{
var storeId = Context.GetCurrentStoreId();
ViewData.SetActivePage("Breez", "Logs", "Logs");
}
<div class="row mb-4">
<div class="col-12">
@if (!Model.Any())
{
<p class="text-secondary mt-3 mb-0">
There are no recent logs.
</p>
}
else
{
<div class="table-responsive">
<table class="table table-hover w-100">
<thead>
<tr>
<th >Timestamp</th>
<th >Log</th>
</tr>
</thead>
<tbody>
@foreach (var log in Model)
{
<tr>
<td>
<span >@log.timestamp.ToTimeAgo()</span>
</td>
<td>
<span class="text-break">@log.log</span>
</td>
</tr>
}
</tbody>
</table>
</div>
}
</div>
</div>

View File

@@ -1,14 +1,18 @@
@using BTCPayServer.Abstractions.Extensions @using BTCPayServer
@using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Plugins.Breez @using BTCPayServer.Plugins.Breez
@using BTCPayServer.Security @using BTCPayServer.Security
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.AspNetCore.Routing @using Microsoft.AspNetCore.Routing
@model string @model string
@inject BreezService BreezService @inject BreezService BreezService
@inject BTCPayNetworkProvider BtcPayNetworkProvider
@{ @{
var storeId = Context.GetImplicitStoreId(); var storeId = Context.GetImplicitStoreId();
var address = Context.GetRouteValue("address").ToString(); var address = Context.GetRouteValue("address").ToString();
ViewData.SetActivePage("Breez", "Create Swapin Refund", "SwapIn"); ViewData.SetActivePage("Breez", "Create Swapin Refund", "SwapIn");
var deriv = Context.GetStoreData().GetDerivationSchemeSettings(BtcPayNetworkProvider, "BTC");
var sdk = BreezService.GetClient(storeId)?.Sdk; var sdk = BreezService.GetClient(storeId)?.Sdk;
var f = sdk.RecommendedFees(); var f = sdk.RecommendedFees();
} }
@@ -20,7 +24,12 @@
<option value="@f.economyFee">Economic fee (@f.economyFee sat/vB)</option> <option value="@f.economyFee">Economic fee (@f.economyFee sat/vB)</option>
<option value="@f.minimumFee">Minimum fee (@f.minimumFee sat/vB)</option> <option value="@f.minimumFee">Minimum fee (@f.minimumFee sat/vB)</option>
</datalist> </datalist>
<datalist list="addresses">
@if (deriv is not null)
{
<option value="store"> Store wallet</option>
}
</datalist>
<form method="post" asp-action="SwapInRefund" asp-route-storeId="@storeId" asp-route-address="@address"> <form method="post" asp-action="SwapInRefund" asp-route-storeId="@storeId" asp-route-address="@address">
<div class="row mb-4"> <div class="row mb-4">
@@ -40,7 +49,7 @@
<div asp-validation-summary="All" class="text-danger"></div> <div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group"> <div class="form-group">
<label for="refundAddress" class="form-label" data-required>Refund address</label> <label for="refundAddress" class="form-label" data-required>Refund address</label>
<input type="text" id="refundAddress" name="refundAddress" class="form-control" required/> <input type="text" id="refundAddress" name="refundAddress" class="form-control" list="addresses" required/>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="satPerByte" class="form-label" data-required>Fees</label> <label for="satPerByte" class="form-label" data-required>Fees</label>

View File

@@ -13,7 +13,8 @@
StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, StoreDashboardViewModel dashboardModel => dashboardModel.StoreId,
_ => Context.GetImplicitStoreId() _ => Context.GetImplicitStoreId()
}; };
var sdk = BreezService.GetClient(storeId)?.Sdk; var client = BreezService.GetClient(storeId);
var sdk = client?.Sdk;
} }
<div class="sticky-header-setup"></div> <div class="sticky-header-setup"></div>
@@ -30,7 +31,11 @@
<a permission="@Policies.CanModifyStoreSettings" asp-action="SwapOut" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "SwapOut")">Swap Out</a> <a permission="@Policies.CanModifyStoreSettings" asp-action="SwapOut" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "SwapOut")">Swap Out</a>
<a permission="@Policies.CanModifyStoreSettings" asp-action="Configure" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Configure")">Configuration</a> <a permission="@Policies.CanModifyStoreSettings" asp-action="Configure" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Configure")">Configuration</a>
</div> @if (client.Events.Any())
{
<a permission="@Policies.CanViewStoreSettings" asp-action="Logs" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Logs")">Logs</a>
}
</div>
</nav> </nav>
} }
</div> </div>