Add View seed to wallet settings

This commit is contained in:
Kukks
2020-04-29 08:28:13 +02:00
parent 3e13e478ad
commit d323bb35cc
3 changed files with 53 additions and 13 deletions

View File

@@ -1137,7 +1137,10 @@ namespace BTCPayServer.Controllers
Label = derivationSchemeSettings.Label, Label = derivationSchemeSettings.Label,
DerivationScheme = derivationSchemeSettings.AccountDerivation.ToString(), DerivationScheme = derivationSchemeSettings.AccountDerivation.ToString(),
DerivationSchemeInput = derivationSchemeSettings.AccountOriginal, DerivationSchemeInput = derivationSchemeSettings.AccountOriginal,
SelectedSigningKey = derivationSchemeSettings.SigningKey.ToString() SelectedSigningKey = derivationSchemeSettings.SigningKey.ToString(),
NBXSeedAvailable = await CanUseHotWallet() && !string.IsNullOrEmpty(await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
.GetMetadataAsync<string>(GetDerivationSchemeSettings(walletId).AccountDerivation,
WellknownMetadataKeys.MasterHDKey))
}; };
vm.AccountKeys = derivationSchemeSettings.AccountKeySettings vm.AccountKeys = derivationSchemeSettings.AccountKeySettings
.Select(e => new WalletSettingsAccountKeyViewModel() .Select(e => new WalletSettingsAccountKeyViewModel()
@@ -1153,7 +1156,8 @@ namespace BTCPayServer.Controllers
[HttpPost] [HttpPost]
public async Task<IActionResult> WalletSettings( public async Task<IActionResult> WalletSettings(
[ModelBinder(typeof(WalletIdModelBinder))] [ModelBinder(typeof(WalletIdModelBinder))]
WalletId walletId, WalletSettingsViewModel vm, string command = "save", CancellationToken cancellationToken = default) WalletId walletId, WalletSettingsViewModel vm, string command = "save",
CancellationToken cancellationToken = default)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(vm); return View(vm);
@@ -1164,14 +1168,21 @@ namespace BTCPayServer.Controllers
if (command == "save") if (command == "save")
{ {
derivationScheme.Label = vm.Label; derivationScheme.Label = vm.Label;
derivationScheme.SigningKey = string.IsNullOrEmpty(vm.SelectedSigningKey) ? null : new BitcoinExtPubKey(vm.SelectedSigningKey, derivationScheme.Network.NBitcoinNetwork); derivationScheme.SigningKey = string.IsNullOrEmpty(vm.SelectedSigningKey)
? null
: new BitcoinExtPubKey(vm.SelectedSigningKey, derivationScheme.Network.NBitcoinNetwork);
for (int i = 0; i < derivationScheme.AccountKeySettings.Length; i++) for (int i = 0; i < derivationScheme.AccountKeySettings.Length; i++)
{ {
derivationScheme.AccountKeySettings[i].AccountKeyPath = string.IsNullOrWhiteSpace(vm.AccountKeys[i].AccountKeyPath) ? null derivationScheme.AccountKeySettings[i].AccountKeyPath =
string.IsNullOrWhiteSpace(vm.AccountKeys[i].AccountKeyPath)
? null
: new KeyPath(vm.AccountKeys[i].AccountKeyPath); : new KeyPath(vm.AccountKeys[i].AccountKeyPath);
derivationScheme.AccountKeySettings[i].RootFingerprint = string.IsNullOrWhiteSpace(vm.AccountKeys[i].MasterFingerprint) ? (HDFingerprint?)null derivationScheme.AccountKeySettings[i].RootFingerprint =
string.IsNullOrWhiteSpace(vm.AccountKeys[i].MasterFingerprint)
? (HDFingerprint?)null
: new HDFingerprint(Encoders.Hex.DecodeData(vm.AccountKeys[i].MasterFingerprint)); : new HDFingerprint(Encoders.Hex.DecodeData(vm.AccountKeys[i].MasterFingerprint));
} }
var store = (await Repository.FindStore(walletId.StoreId, GetUserId())); var store = (await Repository.FindStore(walletId.StoreId, GetUserId()));
store.SetSupportedPaymentMethod(derivationScheme); store.SetSupportedPaymentMethod(derivationScheme);
await Repository.UpdateStore(store); await Repository.UpdateStore(store);
@@ -1180,15 +1191,41 @@ namespace BTCPayServer.Controllers
} }
else if (command == "prune") else if (command == "prune")
{ {
var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode).PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken); var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
.PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken);
if (result.TotalPruned == 0) if (result.TotalPruned == 0)
{ {
TempData[WellKnownTempData.SuccessMessage] = $"The wallet is already pruned"; TempData[WellKnownTempData.SuccessMessage] = $"The wallet is already pruned";
} }
else else
{ {
TempData[WellKnownTempData.SuccessMessage] = $"The wallet has been successfully pruned ({result.TotalPruned} transactions have been removed from the history)"; TempData[WellKnownTempData.SuccessMessage] =
$"The wallet has been successfully pruned ({result.TotalPruned} transactions have been removed from the history)";
} }
return RedirectToAction(nameof(WalletSettings));
}
else if (command == "view-seed" && await CanUseHotWallet())
{
var seed = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
.GetMetadataAsync<string>(derivationScheme.AccountDerivation,
WellknownMetadataKeys.Mnemonic, cancellationToken);
if (string.IsNullOrEmpty(seed))
{
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Severity = StatusMessageModel.StatusSeverity.Error, Message = "The seed was not found"
});
}
else
{
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Severity = StatusMessageModel.StatusSeverity.Success,
Html = $"Please store your seed securely! <br/><code class=\"alert-link\">{seed}</code>"
});
}
return RedirectToAction(nameof(WalletSettings)); return RedirectToAction(nameof(WalletSettings));
} }
else else
@@ -1197,8 +1234,6 @@ namespace BTCPayServer.Controllers
} }
} }
private string GetImage(PaymentMethodId paymentMethodId, BTCPayNetwork network) private string GetImage(PaymentMethodId paymentMethodId, BTCPayNetwork network)
{ {
var res = paymentMethodId.PaymentType == PaymentTypes.BTCLike var res = paymentMethodId.PaymentType == PaymentTypes.BTCLike

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@@ -16,6 +16,7 @@ namespace BTCPayServer.Models.WalletViewModels
public bool IsMultiSig => AccountKeys.Count > 1; public bool IsMultiSig => AccountKeys.Count > 1;
public List<WalletSettingsAccountKeyViewModel> AccountKeys { get; set; } = new List<WalletSettingsAccountKeyViewModel>(); public List<WalletSettingsAccountKeyViewModel> AccountKeys { get; set; } = new List<WalletSettingsAccountKeyViewModel>();
public bool NBXSeedAvailable { get; set; }
} }
public class WalletSettingsAccountKeyViewModel public class WalletSettingsAccountKeyViewModel

View File

@@ -76,6 +76,10 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="SendMenu"> <div class="dropdown-menu" aria-labelledby="SendMenu">
<button name="command" type="submit" class="dropdown-item" value="prune">Prune old transactions from history</button> <button name="command" type="submit" class="dropdown-item" value="prune">Prune old transactions from history</button>
@if (Model.NBXSeedAvailable)
{
<button name="command" type="submit" class="dropdown-item" value="view-seed">View seed</button>
}
</div> </div>
</div> </div>
</div> </div>