mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Rename CanGenerateWallet to CanUseHotWallet, small refactoring on generatewallet
This commit is contained in:
parent
ed6a01469a
commit
47eb087d1b
@ -415,7 +415,7 @@ namespace BTCPayServer.Tests
|
|||||||
var mnemonic = s.GenerateWallet("BTC", "", true, false);
|
var mnemonic = s.GenerateWallet("BTC", "", true, false);
|
||||||
|
|
||||||
var invoiceId = s.CreateInvoice(storeId.storeId);
|
var invoiceId = s.CreateInvoice(storeId.storeId);
|
||||||
var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice( invoiceId);
|
var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId);
|
||||||
var address = invoice.EntityToDTO().Addresses["BTC"];
|
var address = invoice.EntityToDTO().Addresses["BTC"];
|
||||||
|
|
||||||
var result = await s.Server.ExplorerNode.GetAddressInfoAsync(BitcoinAddress.Create(address, Network.RegTest));
|
var result = await s.Server.ExplorerNode.GetAddressInfoAsync(BitcoinAddress.Create(address, Network.RegTest));
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -27,7 +28,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{storeId}/derivations/{cryptoCode}")]
|
[Route("{storeId}/derivations/{cryptoCode}")]
|
||||||
public IActionResult AddDerivationScheme(string storeId, string cryptoCode)
|
public async Task<IActionResult> AddDerivationScheme(string storeId, string cryptoCode)
|
||||||
{
|
{
|
||||||
var store = HttpContext.GetStoreData();
|
var store = HttpContext.GetStoreData();
|
||||||
if (store == null)
|
if (store == null)
|
||||||
@ -42,7 +43,14 @@ namespace BTCPayServer.Controllers
|
|||||||
vm.CryptoCode = cryptoCode;
|
vm.CryptoCode = cryptoCode;
|
||||||
vm.RootKeyPath = network.GetRootKeyPath();
|
vm.RootKeyPath = network.GetRootKeyPath();
|
||||||
vm.Network = network;
|
vm.Network = network;
|
||||||
SetExistingValues(store, vm);
|
var derivation = GetExistingDerivationStrategy(vm.CryptoCode, store);
|
||||||
|
if (derivation != null)
|
||||||
|
{
|
||||||
|
vm.DerivationScheme = derivation.AccountDerivation.ToString();
|
||||||
|
vm.Config = derivation.ToJson();
|
||||||
|
}
|
||||||
|
vm.Enabled = !store.GetStoreBlob().IsExcluded(new PaymentMethodId(vm.CryptoCode, PaymentTypes.BTCLike));
|
||||||
|
vm.CanUseHotWallet = await CanUseHotWallet();
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,20 +129,6 @@ namespace BTCPayServer.Controllers
|
|||||||
return new EmptyResult();
|
return new EmptyResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void SetExistingValues(StoreData store, DerivationSchemeViewModel vm)
|
|
||||||
{
|
|
||||||
var derivation = GetExistingDerivationStrategy(vm.CryptoCode, store);
|
|
||||||
if (derivation != null)
|
|
||||||
{
|
|
||||||
vm.DerivationScheme = derivation.AccountDerivation.ToString();
|
|
||||||
vm.Config = derivation.ToJson();
|
|
||||||
}
|
|
||||||
vm.Enabled = !store.GetStoreBlob().IsExcluded(new PaymentMethodId(vm.CryptoCode, PaymentTypes.BTCLike));
|
|
||||||
vm.CanUseGenerateWallet = CanUseGenerateWallet();
|
|
||||||
}
|
|
||||||
|
|
||||||
private DerivationSchemeSettings GetExistingDerivationStrategy(string cryptoCode, StoreData store)
|
private DerivationSchemeSettings GetExistingDerivationStrategy(string cryptoCode, StoreData store)
|
||||||
{
|
{
|
||||||
var id = new PaymentMethodId(cryptoCode, PaymentTypes.BTCLike);
|
var id = new PaymentMethodId(cryptoCode, PaymentTypes.BTCLike);
|
||||||
@ -326,7 +320,7 @@ namespace BTCPayServer.Controllers
|
|||||||
public async Task<IActionResult> GenerateNBXWallet(string storeId, string cryptoCode,
|
public async Task<IActionResult> GenerateNBXWallet(string storeId, string cryptoCode,
|
||||||
GenerateWalletRequest request)
|
GenerateWalletRequest request)
|
||||||
{
|
{
|
||||||
if (!CanUseGenerateWallet())
|
if (!await CanUseHotWallet())
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
@ -363,6 +357,15 @@ namespace BTCPayServer.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<bool> CanUseHotWallet()
|
||||||
|
{
|
||||||
|
var isAdmin = (await _authorizationService.AuthorizeAsync(User, BTCPayServer.Security.Policies.CanModifyServerSettings.Key)).Succeeded;
|
||||||
|
if (isAdmin)
|
||||||
|
return true;
|
||||||
|
var policies = await _settingsRepository.GetSettingAsync<PoliciesSettings>();
|
||||||
|
return policies?.AllowHotWalletForAll is true;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<string> ReadAllText(IFormFile file)
|
private async Task<string> ReadAllText(IFormFile file)
|
||||||
{
|
{
|
||||||
using (var stream = new StreamReader(file.OpenReadStream()))
|
using (var stream = new StreamReader(file.OpenReadStream()))
|
||||||
@ -391,10 +394,5 @@ namespace BTCPayServer.Controllers
|
|||||||
ModelState.Remove(nameof(vm.Config)); // Remove the cached value
|
ModelState.Remove(nameof(vm.Config)); // Remove the cached value
|
||||||
return View(nameof(AddDerivationScheme),vm);
|
return View(nameof(AddDerivationScheme),vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanUseGenerateWallet()
|
|
||||||
{
|
|
||||||
return (_BTCPayEnv.IsDevelopping || User.IsInRole(Roles.ServerAdmin) || _CssThemeManager.AllowGenerateWalletForAll);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ namespace BTCPayServer.Controllers
|
|||||||
ChangellyClientProvider changellyClientProvider,
|
ChangellyClientProvider changellyClientProvider,
|
||||||
IWebHostEnvironment env, IHttpClientFactory httpClientFactory,
|
IWebHostEnvironment env, IHttpClientFactory httpClientFactory,
|
||||||
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
|
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
|
||||||
|
SettingsRepository settingsRepository,
|
||||||
|
IAuthorizationService authorizationService,
|
||||||
CssThemeManager cssThemeManager)
|
CssThemeManager cssThemeManager)
|
||||||
{
|
{
|
||||||
_RateFactory = rateFactory;
|
_RateFactory = rateFactory;
|
||||||
@ -76,6 +78,8 @@ namespace BTCPayServer.Controllers
|
|||||||
_Env = env;
|
_Env = env;
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
||||||
|
_settingsRepository = settingsRepository;
|
||||||
|
_authorizationService = authorizationService;
|
||||||
_CssThemeManager = cssThemeManager;
|
_CssThemeManager = cssThemeManager;
|
||||||
_NetworkProvider = networkProvider;
|
_NetworkProvider = networkProvider;
|
||||||
_ExplorerProvider = explorerProvider;
|
_ExplorerProvider = explorerProvider;
|
||||||
@ -100,6 +104,8 @@ namespace BTCPayServer.Controllers
|
|||||||
IWebHostEnvironment _Env;
|
IWebHostEnvironment _Env;
|
||||||
private IHttpClientFactory _httpClientFactory;
|
private IHttpClientFactory _httpClientFactory;
|
||||||
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
|
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
|
||||||
|
private readonly SettingsRepository _settingsRepository;
|
||||||
|
private readonly IAuthorizationService _authorizationService;
|
||||||
private readonly CssThemeManager _CssThemeManager;
|
private readonly CssThemeManager _CssThemeManager;
|
||||||
|
|
||||||
[TempData]
|
[TempData]
|
||||||
|
@ -88,11 +88,8 @@ namespace BTCPayServer.HostedServices
|
|||||||
RootAppId = data.RootAppId;
|
RootAppId = data.RootAppId;
|
||||||
DomainToAppMapping = data.DomainToAppMapping;
|
DomainToAppMapping = data.DomainToAppMapping;
|
||||||
AllowLightningInternalNodeForAll = data.AllowLightningInternalNodeForAll;
|
AllowLightningInternalNodeForAll = data.AllowLightningInternalNodeForAll;
|
||||||
AllowGenerateWalletForAll = data.AllowGenerateWalletForAll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AllowGenerateWalletForAll { get; set; }
|
|
||||||
|
|
||||||
public bool AllowLightningInternalNodeForAll { get; set; }
|
public bool AllowLightningInternalNodeForAll { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public string DerivationSchemeFormat { get; set; }
|
public string DerivationSchemeFormat { get; set; }
|
||||||
public string AccountKey { get; set; }
|
public string AccountKey { get; set; }
|
||||||
public BTCPayNetwork Network { get; set; }
|
public BTCPayNetwork Network { get; set; }
|
||||||
public bool CanUseGenerateWallet { get; set; }
|
public bool CanUseHotWallet { get; set; }
|
||||||
|
|
||||||
public RootedKeyPath GetAccountKeypath()
|
public RootedKeyPath GetAccountKeypath()
|
||||||
{
|
{
|
||||||
|
@ -23,8 +23,8 @@ namespace BTCPayServer.Services
|
|||||||
public bool DiscourageSearchEngines { get; set; }
|
public bool DiscourageSearchEngines { get; set; }
|
||||||
[Display(Name = "Allow non-admins to use the internal lightning node in their stores")]
|
[Display(Name = "Allow non-admins to use the internal lightning node in their stores")]
|
||||||
public bool AllowLightningInternalNodeForAll { get; set; }
|
public bool AllowLightningInternalNodeForAll { get; set; }
|
||||||
[Display(Name = "Allow non-admins to use the NBXplorer wallet generator in their stores")]
|
[Display(Name = "Allow non-admins to create hot wallets for their stores")]
|
||||||
public bool AllowGenerateWalletForAll { get; set; }
|
public bool AllowHotWalletForAll { get; set; }
|
||||||
|
|
||||||
[Display(Name = "Display app on website root")]
|
[Display(Name = "Display app on website root")]
|
||||||
public string RootAppId { get; set; }
|
public string RootAppId { get; set; }
|
||||||
|
@ -33,9 +33,9 @@
|
|||||||
<span asp-validation-for="AllowLightningInternalNodeForAll" class="text-danger"></span>
|
<span asp-validation-for="AllowLightningInternalNodeForAll" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input asp-for="AllowGenerateWalletForAll" type="checkbox" class="form-check-input"/>
|
<input asp-for="AllowHotWalletForAll" type="checkbox" class="form-check-input"/>
|
||||||
<label asp-for="AllowGenerateWalletForAll" class="form-check-label"></label>
|
<label asp-for="AllowHotWalletForAll" class="form-check-label"></label>
|
||||||
<span asp-validation-for="AllowGenerateWalletForAll" class="text-danger"></span>
|
<span asp-validation-for="AllowHotWalletForAll" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
{
|
{
|
||||||
<button class="dropdown-item check-for-vault" type="button">... the vault (preview)</button>
|
<button class="dropdown-item check-for-vault" type="button">... the vault (preview)</button>
|
||||||
}
|
}
|
||||||
@if (Model.CanUseGenerateWallet)
|
@if (Model.CanUseHotWallet)
|
||||||
{
|
{
|
||||||
<button class="dropdown-item" data-toggle="modal" data-target="#nbxplorergeneratewallet" type="button" id="nbxplorergeneratewalletbtn">... a new/existing seed.</button>
|
<button class="dropdown-item" data-toggle="modal" data-target="#nbxplorergeneratewallet" type="button" id="nbxplorergeneratewalletbtn">... a new/existing seed.</button>
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
@using NBXplorer.Models
|
@using NBXplorer.Models
|
||||||
@model DerivationSchemeViewModel
|
@model DerivationSchemeViewModel
|
||||||
@if (Model.CanUseGenerateWallet)
|
@if (Model.CanUseHotWallet)
|
||||||
{
|
{
|
||||||
<partial name="AddDerivationSchemes_NBXWalletGenerate" model="@(new GenerateWalletRequest())"/>
|
<partial name="AddDerivationSchemes_NBXWalletGenerate" model="@(new GenerateWalletRequest())"/>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user