mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 05:12:51 +01:00
Fix: Migration bug on old instances (Could not cast or convert from System.String to BTCPayServer.DerivationSchemeSettings) (#6551)
This commit is contained in:
parent
2250853b3e
commit
e479522d9f
@ -224,6 +224,12 @@ namespace BTCPayServer.Hosting
|
|||||||
settings.MigrateStoreExcludedPaymentMethods = true;
|
settings.MigrateStoreExcludedPaymentMethods = true;
|
||||||
await _Settings.UpdateSetting(settings);
|
await _Settings.UpdateSetting(settings);
|
||||||
}
|
}
|
||||||
|
if (!settings.MigrateOldDerivationSchemes)
|
||||||
|
{
|
||||||
|
await MigrateOldDerivationSchemes();
|
||||||
|
settings.MigrateOldDerivationSchemes = true;
|
||||||
|
await _Settings.UpdateSetting(settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -232,6 +238,31 @@ namespace BTCPayServer.Hosting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task MigrateOldDerivationSchemes()
|
||||||
|
{
|
||||||
|
await using var ctx = _DBContextFactory.CreateContext();
|
||||||
|
var stores = await ctx.Stores.ToArrayAsync();
|
||||||
|
foreach (var store in stores)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(store.DerivationStrategies))
|
||||||
|
continue;
|
||||||
|
JObject strategies = JObject.Parse(store.DerivationStrategies);
|
||||||
|
if (strategies is null)
|
||||||
|
continue;
|
||||||
|
foreach (var prop in strategies.Properties())
|
||||||
|
{
|
||||||
|
var h = _handlers.TryGet(new PaymentMethodId(prop.Name));
|
||||||
|
if (h is not BitcoinLikePaymentHandler bh ||
|
||||||
|
prop.Value is not JValue { Type: JTokenType.String, Value: string v })
|
||||||
|
continue;
|
||||||
|
var settings = DerivationSchemeSettings.Parse(v, bh.Network);
|
||||||
|
prop.Value = JToken.FromObject(settings, bh.Serializer);
|
||||||
|
store.DerivationStrategies = strategies.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task MigrateStoreExcludedPaymentMethods()
|
private async Task MigrateStoreExcludedPaymentMethods()
|
||||||
{
|
{
|
||||||
await using var ctx = _DBContextFactory.CreateContext();
|
await using var ctx = _DBContextFactory.CreateContext();
|
||||||
|
@ -32,6 +32,7 @@ namespace BTCPayServer.Services
|
|||||||
public bool MigrateAppYmlToJson { get; set; }
|
public bool MigrateAppYmlToJson { get; set; }
|
||||||
public bool MigrateToStoreConfig { get; set; }
|
public bool MigrateToStoreConfig { get; set; }
|
||||||
public bool MigrateBlockExplorerLinks { get; set; }
|
public bool MigrateBlockExplorerLinks { get; set; }
|
||||||
public bool MigrateStoreExcludedPaymentMethods { get; internal set; }
|
public bool MigrateStoreExcludedPaymentMethods { get; set; }
|
||||||
|
public bool MigrateOldDerivationSchemes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user