Show REST connection information for LND in a QR Code

This commit is contained in:
nicolas.dorier
2018-12-07 19:31:07 +09:00
parent 591d7b4b80
commit 8afc103ae7
8 changed files with 83 additions and 104 deletions

View File

@@ -136,9 +136,6 @@
<Content Update="Views\Home\BitpayTranslator.cshtml"> <Content Update="Views\Home\BitpayTranslator.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack> <Pack>$(IncludeRazorContentInPack)</Pack>
</Content> </Content>
<Content Update="Views\Server\LndRestServices.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Server\SSHService.cshtml"> <Content Update="Views\Server\SSHService.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack> <Pack>$(IncludeRazorContentInPack)</Pack>
</Content> </Content>
@@ -154,7 +151,7 @@
<Content Update="Views\Public\PayButtonHandle.cshtml"> <Content Update="Views\Public\PayButtonHandle.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack> <Pack>$(IncludeRazorContentInPack)</Pack>
</Content> </Content>
<Content Update="Views\Server\LndGrpcServices.cshtml"> <Content Update="Views\Server\LndServices.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack> <Pack>$(IncludeRazorContentInPack)</Pack>
</Content> </Content>
<Content Update="Views\Server\Maintenance.cshtml"> <Content Update="Views\Server\Maintenance.cshtml">

View File

@@ -454,8 +454,8 @@ namespace BTCPayServer.Controllers
return View(result); return View(result);
} }
[Route("server/services/lnd-grpc/{cryptoCode}/{index}")] [Route("server/services/lnd/{cryptoCode}/{index}")]
public IActionResult LndGrpcServices(string cryptoCode, int index, uint? nonce) public IActionResult LndServices(string cryptoCode, int index, uint? nonce)
{ {
if (!_dashBoard.IsFullySynched(cryptoCode, out var unusud)) if (!_dashBoard.IsFullySynched(cryptoCode, out var unusud))
{ {
@@ -466,9 +466,18 @@ namespace BTCPayServer.Controllers
if (external == null) if (external == null)
return NotFound(); return NotFound();
var model = new LndGrpcServicesViewModel(); var model = new LndGrpcServicesViewModel();
if (external.ConnectionType == LightningConnectionType.LndGRPC)
{
model.Host = $"{external.BaseUri.DnsSafeHost}:{external.BaseUri.Port}"; model.Host = $"{external.BaseUri.DnsSafeHost}:{external.BaseUri.Port}";
model.SSL = external.BaseUri.Scheme == "https"; model.SSL = external.BaseUri.Scheme == "https";
model.ConnectionType = "GRPC";
}
else if(external.ConnectionType == LightningConnectionType.LndREST)
{
model.Uri = external.BaseUri.AbsoluteUri;
model.ConnectionType = "REST";
}
if (external.CertificateThumbprint != null) if (external.CertificateThumbprint != null)
{ {
model.CertificateThumbprint = Encoders.Hex.EncodeData(external.CertificateThumbprint); model.CertificateThumbprint = Encoders.Hex.EncodeData(external.CertificateThumbprint);
@@ -480,7 +489,7 @@ namespace BTCPayServer.Controllers
if (nonce != null) if (nonce != null)
{ {
var configKey = GetConfigKey("lnd-grpc", cryptoCode, index, nonce.Value); var configKey = GetConfigKey("lnd", cryptoCode, index, nonce.Value);
var lnConfig = _LnConfigProvider.GetConfig(configKey); var lnConfig = _LnConfigProvider.GetConfig(configKey);
if (lnConfig != null) if (lnConfig != null)
{ {
@@ -507,14 +516,16 @@ namespace BTCPayServer.Controllers
return Json(conf); return Json(conf);
} }
[Route("server/services/lnd-grpc/{cryptoCode}/{index}")] [Route("server/services/lnd/{cryptoCode}/{index}")]
[HttpPost] [HttpPost]
public IActionResult LndGrpcServicesPost(string cryptoCode, int index) public IActionResult LndServicesPost(string cryptoCode, int index)
{ {
var external = GetExternalLndConnectionString(cryptoCode, index); var external = GetExternalLndConnectionString(cryptoCode, index);
if (external == null) if (external == null)
return NotFound(); return NotFound();
LightningConfigurations confs = new LightningConfigurations(); LightningConfigurations confs = new LightningConfigurations();
if (external.ConnectionType == LightningConnectionType.LndGRPC)
{
LightningConfiguration conf = new LightningConfiguration(); LightningConfiguration conf = new LightningConfiguration();
conf.Type = "grpc"; conf.Type = "grpc";
conf.ChainType = _Options.NetworkType.ToString(); conf.ChainType = _Options.NetworkType.ToString();
@@ -525,11 +536,22 @@ namespace BTCPayServer.Controllers
conf.Macaroon = external.Macaroon == null ? null : Encoders.Hex.EncodeData(external.Macaroon); conf.Macaroon = external.Macaroon == null ? null : Encoders.Hex.EncodeData(external.Macaroon);
conf.CertificateThumbprint = external.CertificateThumbprint == null ? null : Encoders.Hex.EncodeData(external.CertificateThumbprint); conf.CertificateThumbprint = external.CertificateThumbprint == null ? null : Encoders.Hex.EncodeData(external.CertificateThumbprint);
confs.Configurations.Add(conf); confs.Configurations.Add(conf);
}
else if (external.ConnectionType == LightningConnectionType.LndREST)
{
var restconf = new LNDRestConfiguration();
restconf.Type = "lnd-rest";
restconf.ChainType = _Options.NetworkType.ToString();
restconf.CryptoCode = cryptoCode;
restconf.Uri = external.BaseUri.AbsoluteUri;
restconf.Macaroon = external.Macaroon == null ? null : Encoders.Hex.EncodeData(external.Macaroon);
restconf.CertificateThumbprint = external.CertificateThumbprint == null ? null : Encoders.Hex.EncodeData(external.CertificateThumbprint);
confs.Configurations.Add(restconf);
}
var nonce = RandomUtils.GetUInt32(); var nonce = RandomUtils.GetUInt32();
var configKey = GetConfigKey("lnd-grpc", cryptoCode, index, nonce); var configKey = GetConfigKey("lnd", cryptoCode, index, nonce);
_LnConfigProvider.KeepConfig(configKey, confs); _LnConfigProvider.KeepConfig(configKey, confs);
return RedirectToAction(nameof(LndGrpcServices), new { cryptoCode = cryptoCode, nonce = nonce }); return RedirectToAction(nameof(LndServices), new { cryptoCode = cryptoCode, nonce = nonce });
} }
private LightningConnectionString GetExternalLndConnectionString(string cryptoCode, int index) private LightningConnectionString GetExternalLndConnectionString(string cryptoCode, int index)
@@ -554,28 +576,6 @@ namespace BTCPayServer.Controllers
return connectionString; return connectionString;
} }
[Route("server/services/lnd-rest/{cryptoCode}/{index}")]
public IActionResult LndRestServices(string cryptoCode, int index, uint? nonce)
{
if (!_dashBoard.IsFullySynched(cryptoCode, out var unusud))
{
StatusMessage = $"Error: {cryptoCode} is not fully synched";
return RedirectToAction(nameof(Services));
}
var external = GetExternalLndConnectionString(cryptoCode, index);
if (external == null)
return NotFound();
var model = new LndRestServicesViewModel();
model.BaseApiUrl = external.BaseUri.ToString();
if (external.CertificateThumbprint != null)
model.CertificateThumbprint = Encoders.Hex.EncodeData(external.CertificateThumbprint);
if (external.Macaroon != null)
model.Macaroon = Encoders.Hex.EncodeData(external.Macaroon);
return View(model);
}
[Route("server/services/ssh")] [Route("server/services/ssh")]
public IActionResult SSHService(bool downloadKeyFile = false) public IActionResult SSHService(bool downloadKeyFile = false)
{ {

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -13,5 +14,8 @@ namespace BTCPayServer.Models.ServerViewModels
public string CertificateThumbprint { get; set; } public string CertificateThumbprint { get; set; }
public string QRCode { get; set; } public string QRCode { get; set; }
public string QRCodeLink { get; set; } public string QRCodeLink { get; set; }
[Display(Name = "REST Uri")]
public string Uri { get; set; }
public string ConnectionType { get; internal set; }
} }
} }

View File

@@ -28,7 +28,7 @@
"BTCPAY_LTCEXPLORERURL": "http://127.0.0.1:32838/", "BTCPAY_LTCEXPLORERURL": "http://127.0.0.1:32838/",
"BTCPAY_BTCLIGHTNING": "type=charge;server=http://127.0.0.1:54938/;api-token=foiewnccewuify", "BTCPAY_BTCLIGHTNING": "type=charge;server=http://127.0.0.1:54938/;api-token=foiewnccewuify",
"BTCPAY_BTCEXTERNALLNDGRPC": "type=lnd-grpc;server=https://lnd:lnd@127.0.0.1:53280/;allowinsecure=true", "BTCPAY_BTCEXTERNALLNDGRPC": "type=lnd-grpc;server=https://lnd:lnd@127.0.0.1:53280/;allowinsecure=true",
"BTCPAY_BTCEXTERNALLNDREST": "type=lnd-rest;server=https://lnd:lnd@127.0.0.1:53280/lnd-rest/btc/;allowinsecure=true;macaroonfilepath=D:\\admin.macaroon", "BTCPAY_BTCEXTERNALLNDREST": "type=lnd-rest;server=https://lnd:lnd@127.0.0.1:53280/lnd-rest/btc/;allowinsecure=true",
"BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/", "BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/",
"ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_ENVIRONMENT": "Development",
"BTCPAY_CHAINS": "btc,ltc", "BTCPAY_CHAINS": "btc,ltc",

View File

@@ -39,7 +39,7 @@ namespace BTCPayServer.Services
public class LightningConfigurations public class LightningConfigurations
{ {
public List<LightningConfiguration> Configurations { get; set; } = new List<LightningConfiguration>(); public List<object> Configurations { get; set; } = new List<object>();
} }
public class LightningConfiguration public class LightningConfiguration
{ {
@@ -52,4 +52,13 @@ namespace BTCPayServer.Services
public string CertificateThumbprint { get; set; } public string CertificateThumbprint { get; set; }
public string Macaroon { get; set; } public string Macaroon { get; set; }
} }
public class LNDRestConfiguration
{
public string ChainType { get; set; }
public string Type { get; set; }
public string CryptoCode { get; set; }
public string Uri { get; set; }
public string Macaroon { get; set; }
public string CertificateThumbprint { get; set; }
}
} }

View File

@@ -1,41 +0,0 @@
@model LndRestServicesViewModel
@{
ViewData.SetActivePageAndTitle(ServerNavPages.Services);
}
<h4>LND REST</h4>
<partial name="_StatusMessage" for="@TempData["StatusMessage"]" />
<div class="row">
<div class="col-md-6">
<div asp-validation-summary="All" class="text-danger"></div>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div class="form-group">
<p>BTCPay exposes LND Rest services for outside consumption. See connection information below</p>
</div>
<div class="form-group">
<label asp-for="BaseApiUrl">Base API Url</label>
<input asp-for="BaseApiUrl" readonly class="form-control" />
</div>
@if (Model.Macaroon != null)
{
<div class="form-group">
<label asp-for="Macaroon"></label>
<input asp-for="Macaroon" readonly class="form-control" />
</div>
}
@if (Model.CertificateThumbprint != null)
{
<div class="form-group">
<label asp-for="CertificateThumbprint"></label>
<input asp-for="CertificateThumbprint" readonly class="form-control" />
</div>
}
</div>
</div>

View File

@@ -4,7 +4,7 @@
} }
<h4>LND GRPC</h4> <h4>LND @Model.ConnectionType</h4>
<partial name="_StatusMessage" for="@TempData["StatusMessage"]" /> <partial name="_StatusMessage" for="@TempData["StatusMessage"]" />
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
@@ -17,14 +17,14 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="form-group"> <div class="form-group">
<p> <p>
<span>BTCPay exposes gRPC services for outside consumption, you will find connection information here.<br /></span> <span>BTCPay exposes LND's @Model.ConnectionType service for outside consumption, you will find connection information here.<br /></span>
</p> </p>
</div> </div>
<div class="form-group"> <div class="form-group">
<h5>QR Code connection</h5> <h5>QR Code connection</h5>
<p> <p>
<span>You can use this QR Code to connect your Zap wallet to your LND instance.<br /></span> <span>You can use this QR Code to connect external software to your LND instance.<br /></span>
<span>This QR Code is only valid for 10 minutes</span> <span>This QR Code is only valid for 10 minutes</span>
</p> </p>
</div> </div>
@@ -61,6 +61,8 @@
<p>Alternatively, you can see the settings by clicking <a href="#details" data-toggle="collapse">here</a></p> <p>Alternatively, you can see the settings by clicking <a href="#details" data-toggle="collapse">here</a></p>
</div> </div>
<div id="details" class="collapse"> <div id="details" class="collapse">
@if (Model.Uri == null)
{
<div class="form-group"> <div class="form-group">
<label asp-for="Host"></label> <label asp-for="Host"></label>
<input asp-for="Host" readonly class="form-control" /> <input asp-for="Host" readonly class="form-control" />
@@ -69,6 +71,14 @@
<label asp-for="SSL"></label> <label asp-for="SSL"></label>
<input asp-for="SSL" disabled type="checkbox" class="form-check-inline" /> <input asp-for="SSL" disabled type="checkbox" class="form-check-inline" />
</div> </div>
}
else
{
<div class="form-group">
<label asp-for="Uri"></label>
<input asp-for="Uri" readonly class="form-control" />
</div>
}
@if (Model.Macaroon != null) @if (Model.Macaroon != null)
{ {
<div class="form-group"> <div class="form-group">

View File

@@ -38,11 +38,11 @@
<td style="text-align:right"> <td style="text-align:right">
@if (lnd.Type == BTCPayServer.Configuration.External.LndTypes.gRPC) @if (lnd.Type == BTCPayServer.Configuration.External.LndTypes.gRPC)
{ {
<a asp-action="LNDGRPCServices" asp-route-cryptoCode="@lnd.Crypto" asp-route-index="@lnd.Index">See information</a> <a asp-action="LNDServices" asp-route-cryptoCode="@lnd.Crypto" asp-route-index="@lnd.Index">See information</a>
} }
else if (lnd.Type == BTCPayServer.Configuration.External.LndTypes.Rest) else if (lnd.Type == BTCPayServer.Configuration.External.LndTypes.Rest)
{ {
<a asp-action="LndRestServices" asp-route-cryptoCode="@lnd.Crypto" asp-route-index="@lnd.Index">See information</a> <a asp-action="LNDServices" asp-route-cryptoCode="@lnd.Crypto" asp-route-index="@lnd.Index">See information</a>
} }
</td> </td>
</tr> </tr>