Create a dedicated IsHotwalletProperty in the DerivationSchemeSettings

This commit is contained in:
nicolas.dorier
2021-06-17 15:36:22 +09:00
parent afd479ac69
commit 956370592f
4 changed files with 26 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ using BTCPayServer.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using NBitcoin; using NBitcoin;
using NBXplorer; using NBXplorer;
using NBXplorer.DerivationStrategy; using NBXplorer.DerivationStrategy;
@@ -257,7 +258,8 @@ namespace BTCPayServer.Controllers
Confirmation = string.IsNullOrEmpty(request.ExistingMnemonic), Confirmation = string.IsNullOrEmpty(request.ExistingMnemonic),
Network = network, Network = network,
RootKeyPath = network.GetRootKeyPath(), RootKeyPath = network.GetRootKeyPath(),
Source = "NBXplorer", Source = isImport ? "SeedImported" : "NBXplorerGenerated",
IsHotWallet = isImport ? request.SavePrivateKeys : method == WalletSetupMethod.HotWallet,
DerivationSchemeFormat = "BTCPay", DerivationSchemeFormat = "BTCPay",
CanUseHotWallet = true, CanUseHotWallet = true,
CanUseRPCImport = rpcImport CanUseRPCImport = rpcImport

View File

@@ -276,8 +276,8 @@ namespace BTCPayServer
[JsonIgnore] [JsonIgnore]
public BTCPayNetwork Network { get; set; } public BTCPayNetwork Network { get; set; }
public string Source { get; set; } public string Source { get; set; }
[JsonIgnore]
public bool IsHotWallet => Source == "NBXplorer"; public bool IsHotWallet { get; set; }
[Obsolete("Use GetSigningAccountKeySettings().AccountKeyPath instead")] [Obsolete("Use GetSigningAccountKeySettings().AccountKeyPath instead")]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]

View File

@@ -128,6 +128,12 @@ namespace BTCPayServer.Hosting
settings.MigrateU2FToFIDO2 = true; settings.MigrateU2FToFIDO2 = true;
await _Settings.UpdateSetting(settings); await _Settings.UpdateSetting(settings);
} }
if (!settings.MigrateHotwalletProperty)
{
await MigrateHotwalletProperty();
settings.MigrateHotwalletProperty = true;
await _Settings.UpdateSetting(settings);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -136,6 +142,20 @@ namespace BTCPayServer.Hosting
} }
} }
private async Task MigrateHotwalletProperty()
{
await using var ctx = _DBContextFactory.CreateContext();
foreach (var store in await ctx.Stores.AsQueryable().ToArrayAsync())
{
foreach (var paymentMethod in store.GetSupportedPaymentMethods(_NetworkProvider).OfType<DerivationSchemeSettings>())
{
paymentMethod.IsHotWallet = paymentMethod.Source == "NBXplorer";
paymentMethod.Source = "NBXplorerGenerated";
}
}
await ctx.SaveChangesAsync();
}
private async Task MigrateU2FToFIDO2() private async Task MigrateU2FToFIDO2()
{ {
await using var ctx = _DBContextFactory.CreateContext(); await using var ctx = _DBContextFactory.CreateContext();

View File

@@ -2,6 +2,7 @@ namespace BTCPayServer.Services
{ {
public class MigrationSettings public class MigrationSettings
{ {
public bool MigrateHotwalletProperty { get; set; }
public bool MigrateU2FToFIDO2{ get; set; } public bool MigrateU2FToFIDO2{ get; set; }
public bool UnreachableStoreCheck { get; set; } public bool UnreachableStoreCheck { get; set; }
public bool DeprecatedLightningConnectionStringCheck { get; set; } public bool DeprecatedLightningConnectionStringCheck { get; set; }