micronode

This commit is contained in:
Kukks
2024-01-17 09:07:18 +01:00
parent d27a31ee8e
commit cfcaa17e94
24 changed files with 2388 additions and 11 deletions

View File

@@ -0,0 +1,96 @@
@using BTCPayServer
@using BTCPayServer.Client
@using BTCPayServer.Lightning
@using BTCPayServer.Plugins.MicroNode
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model BTCPayServer.Plugins.MicroNode.MicroNodeStoreSettings?
@inject IAuthorizationService AuthorizationService
@inject MicroNodeService MicroNodeService
@{
ViewData.SetActivePage("MicroNode ", "Configure", "Configure");
var storeId = Context.GetCurrentStoreId();
var isAdmin = (await AuthorizationService.AuthorizeAsync(User, Policies.CanModifyServerSettings)).Succeeded;
var masters = (await MicroNodeService.GetMasterSettings())
.Where(pair => pair.Key != storeId && (isAdmin || pair.Value.AdminOnly is false))
.Select(m => new SelectListItem(m.Value.Name, m.Key)).ToArray();
var masterId = Context.Items.TryGetValue("MasterId", out var masterIdObj) ? masterIdObj?.ToString() : null;
var payments = await MicroNodeService.GetTransactions(storeId);
}
<form method="post" asp-action="Configure" asp-controller="MicroNode" asp-route-storeId="@storeId">
<div class="row mb-4">
<div class="col-12">
<div class="d-flex align-items-center justify-content-between mb-3">
<h3 class="mb-0">
<span>@ViewData["Title"]</span>
</h3>
<div class="d-flex gap-3 mt-3 mt-sm-0">
@if (masters.Any())
{
<button name="command" type="submit" value="save" class="btn btn-primary">Save</button>
}
@if (Model?.Key is not null)
{
<button name="command" type="submit" value="clear" class="btn btn-danger">Clear</button>
}
</div>
</div>
@if (masters.Any())
{
<div class="row">
<div class="col-xl-8 col-xxl-constrain">
<div class="form-group">
<label for="masterStoreId" class="form-label" data-required>Master</label>
<select name="masterStoreId" id="masterStoreId" asp-items="@masters" class="form-select" value="@masterId"></select>
</div>
<div class="form-group">
<label asp-for="ForwardDestination" class="form-label">Forward Destination</label>
<input asp-for="ForwardDestination" class="form-control"/>
<span asp-validation-for="ForwardDestination" class="text-danger"></span>
<p class="text-muted pt-2">Forward Destination</p>
</div>
</div>
</div>
}
else
{
<div class="alert alert-warning">
<p class="mb-0">There is no master node available to use</p>
</div>
}
@if (payments?.Any() is true)
{
<div class="row">
<div class="table-responsive">
<table class="table">
<tr>
<th>Id</th>
<th>Accounted</th>
<th>Active</th>
<th>Type</th>
<th>Amount</th>
</tr>
@foreach (var p in payments)
{
<tr>
<td>@p.Id</td>
<td>@p.Accounted</td>
<td>@p.Active</td>
<td>@p.Type</td>
<td>@LightMoney.MilliSatoshis(p.Amount).ToDecimal(LightMoneyUnit.BTC) BTC</td>
</tr>
}
</table>
</div>
</div>
}
<input type="hidden" asp-for="Key"/>
</div>
</div>
</form>

View File

@@ -0,0 +1,102 @@
@using BTCPayServer
@using BTCPayServer.Lightning
@using BTCPayServer.Plugins.MicroNode
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model BTCPayServer.Plugins.MicroNode.MicroNodeSettings
@inject MicroNodeService MicroNodeService
@{
ViewData.SetActivePage("MicroNode ", "Configure Master", "ConfigureMaster");
var storeId = Context.GetCurrentStoreId();
}
<form method="post" asp-action="ConfigureMaster" asp-controller="MicroNode" asp-route-storeId="@storeId">
<div class="row mb-4">
<div class="col-12">
<div class="d-flex align-items-center justify-content-between mb-3">
<h3 class="mb-0">
<span>@ViewData["Title"]</span>
</h3>
<div class="d-flex gap-3 mt-3 mt-sm-0">
<button name="command" type="submit" value="save" class="btn btn-primary">Save</button>
@if (Model is not null)
{
<button name="command" type="submit" value="clear" class="btn btn-danger">Clear</button>
}
</div>
</div>
<div class="row">
<div class="col-xl-8 col-xxl-constrain">
<div class="form-group form-check">
<input asp-for="Enabled" type="checkbox" class="form-check-input"/>
<label asp-for="Enabled" class="form-check-label"></label>
<span asp-validation-for="Enabled" class="text-danger"></span>
</div>
<div class="form-group form-check">
<input asp-for="AdminOnly" type="checkbox" class="form-check-input"/>
<label asp-for="AdminOnly" class="form-check-label"></label>
<span asp-validation-for="AdminOnly" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Name" class="form-label" ></label>
<input asp-for="Name" type="text" class="form-control" required/>
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
</div>
@if (Model is not null)
{
var ls = await MicroNodeService.GetMasterLiabilities(storeId, true);
<table class="table">
<tr>
<th>Store id</th>
<th>Key</th>
<th>Balance</th>
</tr>
@foreach (var l in ls)
{
var ssk = await MicroNodeService.GetStoreSettingsFromKey(l.Key);
<tr>
<td>
@ssk?.Key
</td>
<td>@l.Key</td>
<td>@LightMoney.MilliSatoshis(l.Balance).ToDecimal(LightMoneyUnit.BTC) BTC</td>
</tr>
<tr >
<td colspan="2">
<table class="table">
<tr>
<th>Id</th>
<th>Accounted</th>
<th>Active</th>
<th>Type</th>
<th>Amount</th>
</tr>
@foreach(var p in l.Transactions)
{
<tr>
<td>@p.Id</td>
<td>@p.Accounted</td>
<td>@p.Active</td>
<td>@p.Type</td>
<td>@LightMoney.MilliSatoshis(p.Amount).ToDecimal(LightMoneyUnit.BTC) BTC</td>
</tr>
}
</table>
</td>
</tr>
}
</table>
}
</div>
</div>
</form>

View File

@@ -0,0 +1,66 @@
@inject MicroNodeService MicroNodeService;
@using BTCPayServer.Plugins.MicroNode
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using BTCPayServer.Abstractions.TagHelpers
@model BTCPayServer.Models.StoreViewModels.LightningNodeViewModel
@{
var storeId = Model.StoreId;
if (Model.CryptoCode != "BTC")
{
return;
}
var client = await MicroNodeService.GetStoreSettings(storeId);
}
<div id="MicroNodeSetup" class="pt-3 tab-pane fade" role="tabpanel" aria-labelledby="LightningNodeType-MicroNode">
@if (client is not null)
{
}
else
{
<a asp-action="Configure" asp-controller="MicroNode" asp-route-storeId="@storeId">MicroNode needs to be configured beforehand.</a>
}
</div>
@if (client is not null)
{
<script>
const typePrefix = 'type=micro;key=@client.Key';
const triggerEl = document.getElementById('LightningNodeType-MicroNode')
const connStringEl = document.getElementById('ConnectionString')
const connString = connStringEl.value;
const isMicro = connString.startsWith(typePrefix);
if (isMicro) {
// deactivate currently active tab and activate Breez tab
const activeEl = document.querySelector('input[name="LightningNodeType"]:checked')
if (activeEl) {
activeEl.removeAttribute('checked')
activeEl.setAttribute('aria-selected', 'false')
document.querySelector('#LightningNodeTypeTabs .tab-pane.active').classList.remove('active', 'show')
triggerEl.setAttribute('checked', 'checked')
triggerEl.setAttribute('aria-selected', 'true')
document.getElementById('MicroNodeSetup').classList.add('active', 'show')
}
}
document.addEventListener('DOMContentLoaded', () => {
if (isBreez) {
const tabTrigger = new bootstrap.Tab(triggerEl)
triggerEl.checked = true
tabTrigger.show()
}
delegate('change', 'input[name="LightningNodeType"]', e => {
const activeEl = document.querySelector('input[name="LightningNodeType"]:checked')
if (activeEl.id === "LightningNodeType-MicroNode"){
connStringEl.value =typePrefix;
}
})
})
</script>
}

View File

@@ -0,0 +1,19 @@
@inject MicroNodeService MicroNodeService;
@using BTCPayServer.Plugins.MicroNode
@model BTCPayServer.Models.StoreViewModels.LightningNodeViewModel
@if (Model.CryptoCode != "BTC")
{
return;
}
@{
var client = await MicroNodeService.GetStoreSettings(Model.StoreId);
var storeId = Model.StoreId;
}
@if (client is null)
{
<a asp-action="Configure" asp-controller="MicroNode" asp-route-storeId="@storeId" value="Custom" type="radio" id="LightningNodeType-MicroNode" role="tab" aria-controls="MicroNodeSetup" aria-selected="false" name="LightningNodeType" ><label for="LightningNodeType-MicroNode">Configure Micro Node</label></a>
}else{
<input value="Custom" type="radio" id="LightningNodeType-MicroNode" data-bs-toggle="pill" data-bs-target="#MicroNodeSetup" role="tab" aria-controls="MicroNodeSetup" aria-selected="false" name="LightningNodeType">
<label for="LightningNodeType-MicroNode">Use Micro node</label>}

View File

@@ -0,0 +1,31 @@
@using BTCPayServer.Abstractions.Contracts
@using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Client
@using BTCPayServer.Plugins.MicroNode
@using Microsoft.AspNetCore.Mvc.TagHelpers
@inject IScopeProvider ScopeProvider
@inject MicroNodeService MicroNodeService
@{
var storeId = ScopeProvider.GetCurrentStoreId();
}
@if (!string.IsNullOrEmpty(storeId))
{
var masters = (await MicroNodeService.GetMasterSettings()).Select(m => new SelectListItem(m.Value.Name, m.Key)).ToArray();
@if (masters.Any())
{
<li class="nav-item">
<a permission="@Policies.CanModifyStoreSettings" asp-controller="MicroNode" asp-action="Configure" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("MicroNode")" id="Nav-MicroNode">
<span>MicroNode</span>
</a>
</li>
}
<li class="nav-item">
<a permission="@Policies.CanModifyStoreSettings" asp-controller="MicroNode" asp-action="ConfigureMaster" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("MicroNodeMaster")" id="Nav-MicroNodeMaster">
<span>MicroNode Master</span>
</a>
</li>
}

View File

@@ -0,0 +1,9 @@
@using BTCPayServer.Abstractions.Extensions
@inject BTCPayServer.Abstractions.Services.Safe Safe
@addTagHelper *, BTCPayServer.Abstractions
@addTagHelper *, BTCPayServer.TagHelpers
@addTagHelper *, BTCPayServer.Views.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, BTCPayServer