mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
Expose ExplorerClientProvider to plugins via interface
This commit is contained in:
parent
78dd1b0476
commit
d5019f61ce
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using NBitcoin;
|
||||
using NBXplorer.DerivationStrategy;
|
||||
|
||||
namespace BTCPayServer
|
||||
{
|
||||
@ -11,5 +13,23 @@ namespace BTCPayServer
|
||||
hashSet.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
BTCPayServer.Common/IExplorerClientProvider.cs
Normal file
10
BTCPayServer.Common/IExplorerClientProvider.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using NBXplorer;
|
||||
|
||||
namespace BTCPayServer.Common
|
||||
{
|
||||
public interface IExplorerClientProvider
|
||||
{
|
||||
ExplorerClient GetExplorerClient(string cryptoCode);
|
||||
ExplorerClient GetExplorerClient(BTCPayNetworkBase network);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using BTCPayServer.Common;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.HostedServices;
|
||||
using BTCPayServer.Logging;
|
||||
@ -11,7 +12,7 @@ using NBXplorer;
|
||||
|
||||
namespace BTCPayServer
|
||||
{
|
||||
public class ExplorerClientProvider
|
||||
public class ExplorerClientProvider : IExplorerClientProvider
|
||||
{
|
||||
readonly BTCPayNetworkProvider _NetworkProviders;
|
||||
|
||||
|
@ -204,27 +204,6 @@ namespace BTCPayServer
|
||||
resp.Headers[name] = value;
|
||||
}
|
||||
|
||||
public static bool IsSegwit(this DerivationStrategyBase derivationStrategyBase)
|
||||
{
|
||||
return ScriptPubKeyType(derivationStrategyBase) != NBitcoin.ScriptPubKeyType.Legacy;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public static bool IsLocalNetwork(string server)
|
||||
{
|
||||
if (server == null)
|
||||
|
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Abstractions.Extensions;
|
||||
using BTCPayServer.Abstractions.Models;
|
||||
using BTCPayServer.Common;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Controllers;
|
||||
using BTCPayServer.Data;
|
||||
@ -19,7 +18,6 @@ using BTCPayServer.Payments.Bitcoin;
|
||||
using BTCPayServer.Payments.Lightning;
|
||||
using BTCPayServer.Payments.PayJoin;
|
||||
using BTCPayServer.Plugins;
|
||||
using BTCPayServer.Plugins.Shopify;
|
||||
using BTCPayServer.Security;
|
||||
using BTCPayServer.Security.Bitpay;
|
||||
using BTCPayServer.Security.GreenField;
|
||||
@ -363,6 +361,8 @@ namespace BTCPayServer.Hosting
|
||||
services.AddSingleton<INotificationHandler, JunkNotification.Handler>();
|
||||
#endif
|
||||
services.TryAddSingleton<ExplorerClientProvider>();
|
||||
services.AddSingleton<IExplorerClientProvider, ExplorerClientProvider>(x =>
|
||||
x.GetRequiredService<ExplorerClientProvider>());
|
||||
services.TryAddSingleton<Bitpay>(o =>
|
||||
{
|
||||
if (o.GetRequiredService<BTCPayServerOptions>().NetworkType == ChainName.Mainnet)
|
||||
|
Loading…
Reference in New Issue
Block a user