Add Bitcoin Output descriptor support (#2169)

* Add Output descriptor support

* Fix exception message and fix Parse Deriv Scheme Settings when electrum

* fix test
This commit is contained in:
Andrew Camilleri
2021-01-11 03:22:42 +01:00
committed by GitHub
parent b8da6847b9
commit 01be74b219
8 changed files with 267 additions and 43 deletions

View File

@@ -36,6 +36,7 @@ using Microsoft.Extensions.Options;
using NBitcoin;
using NBitcoin.DataEncoders;
using NBXplorer;
using NBXplorer.DerivationStrategy;
using StoreData = BTCPayServer.Data.StoreData;
namespace BTCPayServer.Controllers
@@ -699,6 +700,26 @@ namespace BTCPayServer.Controllers
{
var parser = new DerivationSchemeParser(network);
parser.HintScriptPubKey = hint;
try
{
var derivationSchemeSettings = new DerivationSchemeSettings();
derivationSchemeSettings.Network = network;
var result = parser.ParseOutputDescriptor(derivationScheme);
derivationSchemeSettings.AccountOriginal = derivationScheme.Trim();
derivationSchemeSettings.AccountDerivation = result.Item1;
derivationSchemeSettings.AccountKeySettings = result.Item2?.Select((path, i) => new AccountKeySettings()
{
RootFingerprint = path?.MasterFingerprint,
AccountKeyPath = path?.KeyPath,
AccountKey = result.Item1.GetExtPubKeys().ElementAt(i).GetWif(parser.Network)
}).ToArray() ?? new AccountKeySettings[result.Item1.GetExtPubKeys().Count()];
return derivationSchemeSettings;
}
catch (Exception)
{
// ignored
}
return new DerivationSchemeSettings(parser.Parse(derivationScheme), network);
}