mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 02:08:32 +01:00
Refactoring: Move checking condition up
This commit is contained in:
parent
2e2c9764f3
commit
70a21c5136
1 changed files with 25 additions and 28 deletions
|
@ -110,42 +110,34 @@ namespace BTCPayServer.Controllers
|
||||||
return View(vm.ViewName, vm);
|
return View(vm.ViewName, vm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (!string.IsNullOrEmpty(vm.DerivationScheme))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(vm.DerivationScheme))
|
var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, null, network);
|
||||||
|
if (newStrategy.AccountDerivation != strategy?.AccountDerivation)
|
||||||
{
|
{
|
||||||
var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, null, network);
|
var accountKey = string.IsNullOrEmpty(vm.AccountKey)
|
||||||
if (newStrategy.AccountDerivation != strategy?.AccountDerivation)
|
? null
|
||||||
|
: new BitcoinExtPubKey(vm.AccountKey, network.NBitcoinNetwork);
|
||||||
|
if (accountKey != null)
|
||||||
{
|
{
|
||||||
var accountKey = string.IsNullOrEmpty(vm.AccountKey)
|
var accountSettings =
|
||||||
? null
|
newStrategy.AccountKeySettings.FirstOrDefault(a => a.AccountKey == accountKey);
|
||||||
: new BitcoinExtPubKey(vm.AccountKey, network.NBitcoinNetwork);
|
if (accountSettings != null)
|
||||||
if (accountKey != null)
|
|
||||||
{
|
{
|
||||||
var accountSettings =
|
accountSettings.AccountKeyPath =
|
||||||
newStrategy.AccountKeySettings.FirstOrDefault(a => a.AccountKey == accountKey);
|
vm.KeyPath == null ? null : KeyPath.Parse(vm.KeyPath);
|
||||||
if (accountSettings != null)
|
accountSettings.RootFingerprint = string.IsNullOrEmpty(vm.RootFingerprint)
|
||||||
{
|
? (HDFingerprint?)null
|
||||||
accountSettings.AccountKeyPath =
|
: new HDFingerprint(
|
||||||
vm.KeyPath == null ? null : KeyPath.Parse(vm.KeyPath);
|
NBitcoin.DataEncoders.Encoders.Hex.DecodeData(vm.RootFingerprint));
|
||||||
accountSettings.RootFingerprint = string.IsNullOrEmpty(vm.RootFingerprint)
|
|
||||||
? (HDFingerprint?)null
|
|
||||||
: new HDFingerprint(
|
|
||||||
NBitcoin.DataEncoders.Encoders.Hex.DecodeData(vm.RootFingerprint));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy = newStrategy;
|
|
||||||
strategy.Source = vm.Source;
|
|
||||||
vm.DerivationScheme = strategy.AccountDerivation.ToString();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
strategy = newStrategy;
|
||||||
{
|
strategy.Source = vm.Source;
|
||||||
ModelState.AddModelError(nameof(vm.DerivationScheme), "Please provide your extended public key");
|
vm.DerivationScheme = strategy.AccountDerivation.ToString();
|
||||||
return View(vm.ViewName, vm);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -154,6 +146,11 @@ namespace BTCPayServer.Controllers
|
||||||
return View(vm.ViewName, vm);
|
return View(vm.ViewName, vm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(nameof(vm.DerivationScheme), "Please provide your extended public key");
|
||||||
|
return View(vm.ViewName, vm);
|
||||||
|
}
|
||||||
|
|
||||||
var oldConfig = vm.Config;
|
var oldConfig = vm.Config;
|
||||||
vm.Config = strategy?.ToJson();
|
vm.Config = strategy?.ToJson();
|
||||||
|
|
Loading…
Add table
Reference in a new issue