Displaying information from walletunlock.json if file is present

This commit is contained in:
rockstardev 2019-11-05 13:40:06 -06:00
parent 2b1aac9aa9
commit 58b834fe9d
5 changed files with 78 additions and 13 deletions

View File

@ -49,11 +49,17 @@ namespace BTCPayServer.Configuration
var connStr = configuration.GetOrDefault<string>(setting, string.Empty);
if (connStr.Length != 0)
{
if (!ExternalConnectionString.TryParse(connStr, out var connectionString, out var error))
ExternalConnectionString serviceConnection;
if (type == ExternalServiceTypes.LNDSeedBackup)
{
// just using CookieFilePath to hold variable instead of refactoring whole holder class to better conform
serviceConnection = new ExternalConnectionString { CookieFilePath = connStr };
}
else if (!ExternalConnectionString.TryParse(connStr, out serviceConnection, out var error))
{
throw new ConfigException(string.Format(CultureInfo.InvariantCulture, errorMessage, setting, error));
}
this.Add(new ExternalService() { Type = type, ConnectionString = connectionString, CryptoCode = cryptoCode, DisplayName = displayName, ServiceName = serviceName });
this.Add(new ExternalService() { Type = type, ConnectionString = serviceConnection, CryptoCode = cryptoCode, DisplayName = displayName, ServiceName = serviceName });
}
}

View File

@ -623,7 +623,7 @@ namespace BTCPayServer.Controllers
}
if (service.Type == ExternalServiceTypes.LNDSeedBackup)
{
var model = new LndSeedBackupViewModel();
var model = LndSeedBackupViewModel.Parse(service.ConnectionString.CookieFilePath);
return View("LndSeedBackup", model);
}
if (service.Type == ExternalServiceTypes.RPC)

View File

@ -1,4 +1,8 @@
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using Newtonsoft.Json;
namespace BTCPayServer.Models.ServerViewModels
{
@ -8,6 +12,39 @@ namespace BTCPayServer.Models.ServerViewModels
public string WalletPassword { get; set; }
public string[] Seed { get; set; }
public List<string> Seed { get; set; }
public static LndSeedBackupViewModel Parse(string lndSeedFilePath)
{
try
{
if (!String.IsNullOrEmpty(lndSeedFilePath) && File.Exists(lndSeedFilePath))
{
var unlockFileContents = File.ReadAllText(lndSeedFilePath);
var unlockFile = JsonConvert.DeserializeObject<LndSeedFile>(unlockFileContents);
if (!String.IsNullOrEmpty(unlockFile.wallet_password))
{
return new LndSeedBackupViewModel
{
WalletPassword = unlockFile.wallet_password,
Seed = unlockFile.cipher_seed_mnemonic,
IsWalletUnlockPresent = true,
};
}
}
}
catch
{
}
return new LndSeedBackupViewModel();
}
private class LndSeedFile
{
public string wallet_password { get; set; }
public List<string> cipher_seed_mnemonic { get; set; }
}
}
}

View File

@ -11,7 +11,7 @@
"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_BTCEXTERNALLNDREST": "type=lnd-rest;server=https://lnd:lnd@127.0.0.1:53280/lnd-rest/btc/;allowinsecure=true;macaroonfilepath=D:\\admin.macaroon",
"BTCPAY_BTCEXTERNALLNDSEEDBACKUP": "/etc/merchant_lnd/data/chain/bitcoin/regtest/walletunlock.json",
"BTCPAY_BTCEXTERNALLNDSEEDBACKUP": "D:\\walletunlock.json",
"BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/",
"BTCPAY_ALLOW-ADMIN-REGISTRATION": "true",
"BTCPAY_DISABLE-REGISTRATION": "false",

View File

@ -18,16 +18,27 @@
<div class="form-group">
@if (Model.IsWalletUnlockPresent)
{
<p>Unlock file is present... here are details</p>
<p>Wallet Password: @Model.WalletPassword</p>
<p>Seed: @String.Join(',', Model.Seed)</p>
<p>Wallet Password: <b>@Model.WalletPassword</b></p>
@if (Model.Seed.Count > 1)
{
<p>
<div><a href="#details" data-toggle="collapse">Reveal Seed Information</a></div>
<div id="details" class="collapse">
@String.Join(", ", Model.Seed)
</div>
</p>
}
else
{
<p>Seed information was deleted on <b>@Model.Seed.First()</b></p>
}
}
else
{
<p>
You don't have LND unlock file, which means you need to migrate to new version of LND docker container.
<a href="https://github.com/btcpayserver/lnd/pull/4" target="_blank">More information</a>
</p>
<p class="text-danger">Unlock file is NOT present</p>
<p>You have old version of LND deployment that was auto-initialized using `noseedbackup=1`.</p>
<p>Please migrate to new version of LND deployment that is auto-initialized through script which creates seed backup file as part of the startup process.</p>
<p><a href="https://github.com/btcpayserver/lnd/pull/4" target="_blank">Visit this link for more information</a></p>
}
</div>
</div>
@ -35,4 +46,15 @@
</div>
@section Scripts {
<script type="text/javascript">
function confirmSeedDelete() {
var conf = confirm('This operation is not undoable. Are you sure you want to proceed with deleting seed from LND container?');
if (conf) {
return true;
}
else {
return false;
}
}
</script>
}