mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
add logs and bump breez
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<PropertyGroup>
|
||||
<Product>Breez / Greenlight</Product>
|
||||
<Description>Lightweight lightning baby!</Description>
|
||||
<Version>1.0.5</Version>
|
||||
<Version>1.0.6</Version>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
<!-- Plugin development properties -->
|
||||
@@ -34,7 +34,7 @@
|
||||
<ProjectReference Include="..\..\submodules\btcpayserver\BTCPayServer\BTCPayServer.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Breez.Sdk" Version="0.4.2-rc1" />
|
||||
<PackageReference Include="Breez.Sdk" Version="0.4.2-rc3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
|
||||
@@ -74,6 +74,18 @@ public class BreezController : Controller
|
||||
|
||||
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")]
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
46
Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Logs.cshtml
Normal file
46
Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Logs.cshtml
Normal 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>
|
||||
@@ -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 @@
|
||||
<option value="@f.economyFee">Economic fee (@f.economyFee sat/vB)</option>
|
||||
<option value="@f.minimumFee">Minimum fee (@f.minimumFee sat/vB)</option>
|
||||
</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">
|
||||
<div class="row mb-4">
|
||||
@@ -40,7 +49,7 @@
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<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 class="form-group">
|
||||
<label for="satPerByte" class="form-label" data-required>Fees</label>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
<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="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>
|
||||
}
|
||||
</div>
|
||||
Reference in New Issue
Block a user