mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-11 01:35:22 +01:00
Import xpub: Surface error details (#4205)
Checks if the input is an output descriptor and explicitely handles that case instead of catching any errors. This allows us to display more detailed information about why an import might fail.
This commit is contained in:
parent
e883714446
commit
895462ac7f
2 changed files with 11 additions and 14 deletions
|
@ -119,17 +119,16 @@ namespace BTCPayServer.Controllers
|
|||
accountSettings.AccountKeyPath =
|
||||
vm.KeyPath == null ? null : KeyPath.Parse(vm.KeyPath);
|
||||
accountSettings.RootFingerprint = string.IsNullOrEmpty(vm.RootFingerprint)
|
||||
? (HDFingerprint?)null
|
||||
: new HDFingerprint(
|
||||
NBitcoin.DataEncoders.Encoders.Hex.DecodeData(vm.RootFingerprint));
|
||||
? null
|
||||
: new HDFingerprint(Encoders.Hex.DecodeData(vm.RootFingerprint));
|
||||
}
|
||||
}
|
||||
vm.DerivationScheme = strategy.AccountDerivation.ToString();
|
||||
ModelState.Remove(nameof(vm.DerivationScheme));
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid wallet format");
|
||||
ModelState.AddModelError(nameof(vm.DerivationScheme), $"Invalid wallet format: {ex.Message}");
|
||||
return View(vm.ViewName, vm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
|
@ -672,10 +673,10 @@ namespace BTCPayServer.Controllers
|
|||
private DerivationSchemeSettings ParseDerivationStrategy(string derivationScheme, BTCPayNetwork network)
|
||||
{
|
||||
var parser = new DerivationSchemeParser(network);
|
||||
try
|
||||
var isOD = Regex.Match(derivationScheme, @"\(.*?\)");
|
||||
if (isOD.Success)
|
||||
{
|
||||
var derivationSchemeSettings = new DerivationSchemeSettings();
|
||||
derivationSchemeSettings.Network = network;
|
||||
var derivationSchemeSettings = new DerivationSchemeSettings { Network = network };
|
||||
var result = parser.ParseOutputDescriptor(derivationScheme);
|
||||
derivationSchemeSettings.AccountOriginal = derivationScheme.Trim();
|
||||
derivationSchemeSettings.AccountDerivation = result.Item1;
|
||||
|
@ -687,12 +688,9 @@ namespace BTCPayServer.Controllers
|
|||
}).ToArray() ?? new AccountKeySettings[result.Item1.GetExtPubKeys().Count()];
|
||||
return derivationSchemeSettings;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
return new DerivationSchemeSettings(parser.Parse(derivationScheme), network);
|
||||
|
||||
var strategy = parser.Parse(derivationScheme);
|
||||
return new DerivationSchemeSettings(strategy, network);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
|
Loading…
Add table
Reference in a new issue