2019-05-24 11:42:22 +02:00
|
|
|
using System.Collections.Generic;
|
2021-07-12 14:17:25 +02:00
|
|
|
using NBitcoin;
|
|
|
|
using NBXplorer.DerivationStrategy;
|
2019-05-24 11:42:22 +02:00
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
{
|
|
|
|
public static class UtilitiesExtensions
|
|
|
|
{
|
|
|
|
public static void AddRange<T>(this HashSet<T> hashSet, IEnumerable<T> items)
|
|
|
|
{
|
|
|
|
foreach (var item in items)
|
|
|
|
{
|
|
|
|
hashSet.Add(item);
|
|
|
|
}
|
|
|
|
}
|
2021-07-12 14:17:25 +02:00
|
|
|
|
|
|
|
public static ScriptPubKeyType ScriptPubKeyType(this DerivationStrategyBase derivationStrategyBase)
|
|
|
|
{
|
|
|
|
if (IsSegwitCore(derivationStrategyBase))
|
|
|
|
{
|
|
|
|
return NBitcoin.ScriptPubKeyType.Segwit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (derivationStrategyBase is P2SHDerivationStrategy p2shStrat && IsSegwitCore(p2shStrat.Inner))
|
|
|
|
? NBitcoin.ScriptPubKeyType.SegwitP2SH
|
|
|
|
: NBitcoin.ScriptPubKeyType.Legacy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsSegwitCore(DerivationStrategyBase derivationStrategyBase)
|
|
|
|
{
|
|
|
|
return (derivationStrategyBase is P2WSHDerivationStrategy) ||
|
|
|
|
(derivationStrategyBase is DirectDerivationStrategy direct) && direct.Segwit;
|
|
|
|
}
|
2019-05-24 11:42:22 +02:00
|
|
|
}
|
|
|
|
}
|