2020-06-28 21:44:35 -05:00
using System ;
2021-01-02 13:44:28 +01:00
using System.Linq ;
2022-08-01 16:14:50 +02:00
using System.Net.Http ;
2017-09-27 23:56:43 +09:00
using System.Threading ;
2020-11-17 13:46:23 +01:00
using BTCPayServer.Abstractions.Contracts ;
using BTCPayServer.Abstractions.Extensions ;
using BTCPayServer.Abstractions.Models ;
2021-10-25 08:18:02 +02:00
using BTCPayServer.Abstractions.Services ;
2021-07-27 14:11:47 +02:00
using BTCPayServer.Client ;
2021-12-31 16:59:02 +09:00
using BTCPayServer.Common ;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Configuration ;
using BTCPayServer.Controllers ;
2022-01-14 13:05:23 +09:00
using BTCPayServer.Controllers.Greenfield ;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Data ;
2021-10-18 05:37:59 +02:00
using BTCPayServer.Data.Payouts.LightningLike ;
2022-11-25 02:42:55 +01:00
using BTCPayServer.Forms ;
2018-01-08 02:36:41 +09:00
using BTCPayServer.HostedServices ;
2023-12-01 10:50:05 +01:00
using BTCPayServer.HostedServices.Webhooks ;
2021-01-06 15:51:13 +01:00
using BTCPayServer.Lightning ;
2023-11-21 10:55:02 +01:00
using BTCPayServer.Lightning.Charge ;
using BTCPayServer.Lightning.CLightning ;
using BTCPayServer.Lightning.Eclair ;
using BTCPayServer.Lightning.LNbank ;
using BTCPayServer.Lightning.LND ;
using BTCPayServer.Lightning.LNDhub ;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Logging ;
2019-01-14 22:43:29 +01:00
using BTCPayServer.PaymentRequest ;
2019-05-24 06:11:38 +00:00
using BTCPayServer.Payments ;
using BTCPayServer.Payments.Bitcoin ;
2019-01-07 09:52:27 +01:00
using BTCPayServer.Payments.Lightning ;
2020-01-06 13:57:32 +01:00
using BTCPayServer.Payments.PayJoin ;
2022-04-24 05:19:34 +02:00
using BTCPayServer.PayoutProcessors ;
2020-10-21 14:02:20 +02:00
using BTCPayServer.Plugins ;
2023-04-10 11:07:03 +09:00
using BTCPayServer.Rating ;
using BTCPayServer.Rating.Providers ;
2018-04-30 02:33:42 +09:00
using BTCPayServer.Security ;
2019-10-12 20:35:30 +09:00
using BTCPayServer.Security.Bitpay ;
2022-01-14 13:05:23 +09:00
using BTCPayServer.Security.Greenfield ;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Services ;
using BTCPayServer.Services.Apps ;
using BTCPayServer.Services.Fees ;
using BTCPayServer.Services.Invoices ;
2020-04-28 09:53:34 +02:00
using BTCPayServer.Services.Labels ;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Services.Mails ;
2020-06-14 23:47:11 -05:00
using BTCPayServer.Services.Notifications ;
2020-06-16 23:29:25 +09:00
using BTCPayServer.Services.Notifications.Blobs ;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Services.PaymentRequests ;
using BTCPayServer.Services.Rates ;
using BTCPayServer.Services.Stores ;
using BTCPayServer.Services.Wallets ;
2023-04-10 11:07:03 +09:00
using ExchangeSharp ;
2020-06-28 17:55:27 +09:00
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc.ModelBinding ;
2020-12-28 21:59:01 +09:00
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation ;
2020-06-28 17:55:27 +09:00
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.DependencyInjection.Extensions ;
using Microsoft.Extensions.Hosting ;
using Microsoft.Extensions.Logging ;
using Microsoft.Extensions.Options ;
using NBitcoin ;
using NBitpayClient ;
using NBXplorer.DerivationStrategy ;
2020-06-24 10:34:09 +09:00
using Newtonsoft.Json ;
2020-06-28 17:55:27 +09:00
using Serilog ;
2023-07-24 09:24:32 +09:00
using BTCPayServer.Services.Reporting ;
2024-01-17 10:08:39 +01:00
using BTCPayServer.Services.WalletFileParsing ;
2024-04-04 16:31:04 +09:00
using BTCPayServer.Payments.LNURLPay ;
using System.Collections.Generic ;
2024-05-01 10:22:07 +09:00
using BTCPayServer.Payouts ;
2024-04-04 16:31:04 +09:00
2024-01-17 10:08:39 +01:00
2020-07-29 18:55:28 +09:00
#if ALTCOINS
2020-07-28 22:48:51 +02:00
using BTCPayServer.Services.Altcoins.Monero ;
2022-02-14 16:04:34 +08:00
using BTCPayServer.Services.Altcoins.Zcash ;
2020-07-28 22:48:51 +02:00
#endif
2017-09-13 15:47:34 +09:00
namespace BTCPayServer.Hosting
{
2017-10-27 17:53:04 +09:00
public static class BTCPayServerServices
{
2020-06-24 10:34:09 +09:00
public static IServiceCollection RegisterJsonConverter ( this IServiceCollection services , Func < BTCPayNetwork , JsonConverter > create )
{
services . AddSingleton < IJsonConverterRegistration , JsonConverterRegistration > ( ( s ) = > new JsonConverterRegistration ( create ) ) ;
return services ;
}
2021-11-22 17:16:08 +09:00
public static IServiceCollection AddBTCPayServer ( this IServiceCollection services , IConfiguration configuration , Logs logs )
2017-10-27 17:53:04 +09:00
{
2020-06-28 17:55:27 +09:00
services . AddSingleton < MvcNewtonsoftJsonOptions > ( o = > o . GetRequiredService < IOptions < MvcNewtonsoftJsonOptions > > ( ) . Value ) ;
2022-06-13 06:36:47 +02:00
services . AddSingleton < JsonSerializerSettings > ( o = > o . GetRequiredService < IOptions < MvcNewtonsoftJsonOptions > > ( ) . Value . SerializerSettings ) ;
2017-10-27 17:53:04 +09:00
services . AddDbContext < ApplicationDbContext > ( ( provider , o ) = >
{
var factory = provider . GetRequiredService < ApplicationDbContextFactory > ( ) ;
factory . ConfigureBuilder ( o ) ;
} ) ;
2018-08-21 14:33:13 +09:00
services . AddHttpClient ( ) ;
2019-06-18 13:37:24 +09:00
services . AddHttpClient ( nameof ( ExplorerClientProvider ) , httpClient = >
{
httpClient . Timeout = Timeout . InfiniteTimeSpan ;
} ) ;
2022-11-21 10:23:25 +09:00
services . AddHttpClient < PluginBuilderClient > ( ( prov , httpClient ) = >
{
var p = prov . GetRequiredService < PoliciesSettings > ( ) ;
var pluginSource = p . PluginSource ? ? PoliciesSettings . DefaultPluginSource ;
if ( pluginSource . EndsWith ( '/' ) )
pluginSource = pluginSource . Substring ( 0 , pluginSource . Length - 1 ) ;
if ( ! Uri . TryCreate ( pluginSource , UriKind . Absolute , out var r ) | | ( r . Scheme ! = "https" & & r . Scheme ! = "http" ) )
r = new Uri ( PoliciesSettings . DefaultPluginSource , UriKind . Absolute ) ;
httpClient . BaseAddress = r ;
} ) ;
2020-06-24 10:34:09 +09:00
2024-04-04 16:31:04 +09:00
services . AddSingleton < PrettyNameProvider > ( ) ;
2021-11-22 17:16:08 +09:00
services . AddSingleton < Logs > ( logs ) ;
2020-06-24 10:34:09 +09:00
services . AddSingleton < BTCPayNetworkJsonSerializerSettings > ( ) ;
2020-01-06 13:57:32 +01:00
services . AddPayJoinServices ( ) ;
2022-06-29 16:18:02 +02:00
services . AddScoped < IScopeProvider , ScopeProvider > ( ) ;
2017-10-27 17:53:04 +09:00
services . TryAddSingleton < SettingsRepository > ( ) ;
2020-10-21 14:02:20 +02:00
services . TryAddSingleton < ISettingsRepository > ( provider = > provider . GetService < SettingsRepository > ( ) ) ;
2022-06-13 06:36:47 +02:00
services . TryAddSingleton < IStoreRepository > ( provider = > provider . GetService < StoreRepository > ( ) ) ;
2019-03-17 12:57:18 +09:00
services . TryAddSingleton < TorServices > ( ) ;
2021-04-18 11:26:06 +09:00
services . AddSingleton < IHostedService > ( provider = > provider . GetRequiredService < TorServices > ( ) ) ;
2022-03-29 20:29:27 +02:00
services . AddSingleton < ISwaggerProvider , DefaultSwaggerProvider > ( ) ;
2019-03-18 00:03:02 +09:00
services . TryAddSingleton < SocketFactory > ( ) ;
2024-01-17 10:08:39 +01:00
2023-11-21 10:55:02 +01:00
services . AddSingleton < Func < HttpClient , ILightningConnectionStringHandler > > ( client = >
new ChargeLightningConnectionStringHandler ( client ) ) ;
services . AddSingleton < Func < HttpClient , ILightningConnectionStringHandler > > ( _ = >
new CLightningConnectionStringHandler ( ) ) ;
services . AddSingleton < Func < HttpClient , ILightningConnectionStringHandler > > ( client = >
new EclairConnectionStringHandler ( client ) ) ;
services . AddSingleton < Func < HttpClient , ILightningConnectionStringHandler > > ( client = >
new LndConnectionStringHandler ( client ) ) ;
services . AddSingleton < Func < HttpClient , ILightningConnectionStringHandler > > ( client = >
new LndHubConnectionStringHandler ( client ) ) ;
services . AddSingleton < Func < HttpClient , ILightningConnectionStringHandler > > ( client = >
new LNbankConnectionStringHandler ( client ) ) ;
2019-04-11 01:10:29 +09:00
services . TryAddSingleton < LightningClientFactoryService > ( ) ;
2022-06-13 09:22:26 +02:00
services . AddHttpClient ( LightningClientFactoryService . OnionNamedClient )
. ConfigurePrimaryHttpMessageHandler < Socks5HttpClientHandler > ( ) ;
2024-01-17 10:08:39 +01:00
2017-10-27 17:53:04 +09:00
services . TryAddSingleton < InvoicePaymentNotification > ( ) ;
2019-05-14 15:46:43 +00:00
services . TryAddSingleton < BTCPayServerOptions > ( o = >
o . GetRequiredService < IOptions < BTCPayServerOptions > > ( ) . Value ) ;
2024-04-15 19:08:25 +09:00
2019-07-08 12:12:39 +09:00
services . AddStartupTask < MigrationStartupTask > ( ) ;
2023-02-10 11:43:46 +09:00
2022-05-24 13:18:16 +09:00
//
AddSettingsAccessor < PoliciesSettings > ( services ) ;
AddSettingsAccessor < ThemeSettings > ( services ) ;
//
2024-01-17 10:08:39 +01:00
AddOnchainWalletParsers ( services ) ;
2024-04-04 16:31:04 +09:00
services . AddSingleton < IUIExtension > ( new UIExtension ( "Bitcoin/ViewBitcoinLikePaymentData" , "store-invoices-payments" ) ) ;
services . AddSingleton < IUIExtension > ( new UIExtension ( "Lightning/ViewLightningLikePaymentData" , "store-invoices-payments" ) ) ;
2024-01-17 10:08:39 +01:00
2020-10-21 09:53:05 +02:00
services . AddStartupTask < BlockExplorerLinkStartupTask > ( ) ;
2021-10-05 11:10:41 +02:00
services . TryAddSingleton < InvoiceRepository > ( ) ;
services . AddSingleton < PaymentService > ( ) ;
2017-10-27 17:53:04 +09:00
services . AddSingleton < BTCPayServerEnvironment > ( ) ;
services . TryAddSingleton < TokenRepository > ( ) ;
2019-08-03 00:42:30 +09:00
services . TryAddSingleton < WalletRepository > ( ) ;
2017-12-17 14:17:42 +09:00
services . TryAddSingleton < EventAggregator > ( ) ;
2019-01-14 22:43:29 +01:00
services . TryAddSingleton < PaymentRequestService > ( ) ;
2021-03-14 12:24:32 -07:00
services . TryAddSingleton < UserService > ( ) ;
2022-04-12 09:55:10 +02:00
services . TryAddSingleton < WalletHistogramService > ( ) ;
2021-01-06 15:51:13 +01:00
services . AddSingleton < ApplicationDbContextFactory > ( ) ;
services . AddOptions < BTCPayServerOptions > ( ) . Configure (
( options ) = >
{
2021-11-22 17:16:08 +09:00
options . LoadArgs ( configuration , logs ) ;
2021-01-06 15:51:13 +01:00
} ) ;
services . AddOptions < DataDirectories > ( ) . Configure (
( options ) = >
{
options . Configure ( configuration ) ;
} ) ;
services . AddOptions < DatabaseOptions > ( ) . Configure < IOptions < DataDirectories > > (
( options , datadirs ) = >
2017-12-17 01:04:20 +09:00
{
2021-01-06 15:51:13 +01:00
var postgresConnectionString = configuration [ "postgres" ] ;
if ( ! string . IsNullOrEmpty ( postgresConnectionString ) )
2020-12-27 22:06:00 +09:00
{
2021-01-06 15:51:13 +01:00
options . ConnectionString = postgresConnectionString ;
2020-12-27 22:06:00 +09:00
}
2021-01-06 15:51:13 +01:00
else
{
throw new InvalidOperationException ( "No database option was configured." ) ;
}
} ) ;
2021-01-02 13:44:28 +01:00
services . AddOptions < NBXplorerOptions > ( ) . Configure < BTCPayNetworkProvider > (
( options , btcPayNetworkProvider ) = >
{
2021-01-06 15:51:13 +01:00
foreach ( BTCPayNetwork btcPayNetwork in btcPayNetworkProvider . GetAll ( ) . OfType < BTCPayNetwork > ( ) )
{
NBXplorerConnectionSetting setting =
new NBXplorerConnectionSetting
{
CryptoCode = btcPayNetwork . CryptoCode ,
ExplorerUri = configuration . GetOrDefault < Uri > (
$"{btcPayNetwork.CryptoCode}.explorer.url" ,
btcPayNetwork . NBXplorerNetwork . DefaultSettings . DefaultUrl ) ,
CookieFile = configuration . GetOrDefault < string > (
$"{btcPayNetwork.CryptoCode}.explorer.cookiefile" ,
btcPayNetwork . NBXplorerNetwork . DefaultSettings . DefaultCookieFile )
} ;
options . NBXplorerConnectionSettings . Add ( setting ) ;
2022-04-12 09:55:10 +02:00
options . ConnectionString = configuration . GetOrDefault < string > ( "explorer.postgres" , null ) ;
2021-01-06 15:51:13 +01:00
}
2021-01-02 13:44:28 +01:00
} ) ;
2023-11-21 10:55:02 +01:00
services . AddOptions < LightningNetworkOptions > ( ) . Configure < BTCPayNetworkProvider , LightningClientFactoryService > (
( options , btcPayNetworkProvider , lightningClientFactoryService ) = >
2021-01-02 13:44:28 +01:00
{
2021-01-06 15:51:13 +01:00
foreach ( var net in btcPayNetworkProvider . GetAll ( ) . OfType < BTCPayNetwork > ( ) )
{
var lightning = configuration . GetOrDefault < string > ( $"{net.CryptoCode}.lightning" , string . Empty ) ;
if ( lightning . Length ! = 0 )
{
2023-11-21 10:55:02 +01:00
string error = null ;
ILightningClient lightningClient = null ;
try
{
lightningClient = lightningClientFactoryService . Create ( lightning , net ) ;
}
catch ( Exception e )
{
error = e . Message ;
}
2024-01-17 10:08:39 +01:00
2023-11-21 10:55:02 +01:00
if ( error is not null )
2021-01-06 15:51:13 +01:00
{
2021-11-22 17:16:08 +09:00
logs . Configuration . LogWarning ( $"Invalid setting {net.CryptoCode}.lightning, " +
2021-01-06 15:51:13 +01:00
Environment . NewLine +
$"If you have a c-lightning server use: 'type=clightning;server=/root/.lightning/lightning-rpc', " +
Environment . NewLine +
$"If you have a lightning charge server: 'type=charge;server=https://charge.example.com;api-token=yourapitoken'" +
Environment . NewLine +
$"If you have a lnd server: 'type=lnd-rest;server=https://lnd:lnd@lnd.example.com;macaroon=abf239...;certthumbprint=2abdf302...'" +
Environment . NewLine +
$" lnd server: 'type=lnd-rest;server=https://lnd:lnd@lnd.example.com;macaroonfilepath=/root/.lnd/admin.macaroon;certthumbprint=2abdf302...'" +
Environment . NewLine +
$"If you have an eclair server: 'type=eclair;server=http://eclair.com:4570;password=eclairpassword;bitcoin-host=bitcoind:37393;bitcoin-auth=bitcoinrpcuser:bitcoinrpcpassword" +
Environment . NewLine +
$" eclair server: 'type=eclair;server=http://eclair.com:4570;password=eclairpassword;bitcoin-host=bitcoind:37393" +
Environment . NewLine +
$"Error: {error}" + Environment . NewLine +
"This service will not be exposed through BTCPay Server" ) ;
}
else
{
2023-11-21 10:55:02 +01:00
if ( lightningClient . ToString ( ) ! = lightning )
2021-01-06 15:51:13 +01:00
{
2021-11-22 17:16:08 +09:00
logs . Configuration . LogWarning (
2023-12-01 10:55:05 +01:00
$"Setting {net.CryptoCode}.lightning is a deprecated format ({lightning}), it will work now, but please replace it for future versions with '{lightningClient}'" ) ;
2021-01-06 15:51:13 +01:00
}
2023-11-21 10:55:02 +01:00
options . InternalLightningByCryptoCode . Add ( net . CryptoCode , lightningClient ) ;
2021-01-06 15:51:13 +01:00
}
}
}
2021-01-02 13:44:28 +01:00
} ) ;
services . AddOptions < ExternalServicesOptions > ( ) . Configure < BTCPayNetworkProvider > (
( options , btcPayNetworkProvider ) = >
{
2021-01-06 15:51:13 +01:00
foreach ( var net in btcPayNetworkProvider . GetAll ( ) . OfType < BTCPayNetwork > ( ) )
{
options . ExternalServices . Load ( net . CryptoCode , configuration ) ;
}
options . ExternalServices . LoadNonCryptoServices ( configuration ) ;
var services = configuration . GetOrDefault < string > ( "externalservices" , null ) ;
if ( services ! = null )
{
2021-12-31 16:59:02 +09:00
foreach ( var service in services . Split ( new [ ] { ';' , ',' } , StringSplitOptions . RemoveEmptyEntries )
2021-01-06 15:51:13 +01:00
. Select ( p = > ( p , SeparatorIndex : p . IndexOf ( ':' , StringComparison . OrdinalIgnoreCase ) ) )
. Where ( p = > p . SeparatorIndex ! = - 1 )
. Select ( p = > ( Name : p . p . Substring ( 0 , p . SeparatorIndex ) ,
Link : p . p . Substring ( p . SeparatorIndex + 1 ) ) ) )
{
if ( Uri . TryCreate ( service . Link , UriKind . RelativeOrAbsolute , out var uri ) )
options . OtherExternalServices . AddOrReplace ( service . Name , uri ) ;
}
}
2021-01-02 13:44:28 +01:00
} ) ;
2023-11-29 18:51:40 +09:00
services . TryAddSingleton < BTCPayNetworkProvider > ( ) ;
2017-12-21 15:52:04 +09:00
2019-02-19 13:04:58 +09:00
services . TryAddSingleton < AppService > ( ) ;
2022-11-21 10:23:25 +09:00
services . AddTransient < PluginService > ( ) ;
2023-07-20 15:05:14 +02:00
services . AddSingleton < PluginHookService > ( ) ;
services . AddSingleton < IPluginHookService , PluginHookService > ( provider = > provider . GetService < PluginHookService > ( ) ) ;
2019-08-10 14:05:11 +09:00
services . TryAddTransient < Safe > ( ) ;
2023-03-13 02:12:58 +01:00
services . TryAddTransient < DisplayFormatter > ( ) ;
2023-10-18 19:33:43 +09:00
services . TryAddSingleton < Ganss . Xss . HtmlSanitizer > ( o = >
2019-02-17 16:53:41 +09:00
{
2023-10-18 19:33:43 +09:00
var htmlSanitizer = new Ganss . Xss . HtmlSanitizer ( ) ;
2019-02-17 16:53:41 +09:00
htmlSanitizer . RemovingAtRule + = ( sender , args ) = >
{
} ;
htmlSanitizer . RemovingTag + = ( sender , args ) = >
{
if ( args . Tag . TagName . Equals ( "img" , StringComparison . InvariantCultureIgnoreCase ) )
{
if ( ! args . Tag . ClassList . Contains ( "img-fluid" ) )
{
args . Tag . ClassList . Add ( "img-fluid" ) ;
}
args . Cancel = true ;
}
} ;
htmlSanitizer . RemovingAttribute + = ( sender , args ) = >
{
if ( args . Tag . TagName . Equals ( "img" , StringComparison . InvariantCultureIgnoreCase ) & &
args . Attribute . Name . Equals ( "src" , StringComparison . InvariantCultureIgnoreCase ) & &
2023-10-18 19:33:43 +09:00
args . Reason = = Ganss . Xss . RemoveReason . NotAllowedUrlValue )
2019-02-17 16:53:41 +09:00
{
args . Cancel = true ;
}
} ;
htmlSanitizer . RemovingStyle + = ( sender , args ) = > { args . Cancel = true ; } ;
htmlSanitizer . AllowedAttributes . Add ( "class" ) ;
htmlSanitizer . AllowedTags . Add ( "iframe" ) ;
2020-07-30 11:36:33 +09:00
htmlSanitizer . AllowedTags . Add ( "style" ) ;
2019-02-17 16:53:41 +09:00
htmlSanitizer . AllowedTags . Remove ( "img" ) ;
htmlSanitizer . AllowedAttributes . Add ( "webkitallowfullscreen" ) ;
htmlSanitizer . AllowedAttributes . Add ( "allowfullscreen" ) ;
2024-02-21 20:53:24 +01:00
htmlSanitizer . AllowedSchemes . Add ( "mailto" ) ;
2019-02-17 16:53:41 +09:00
return htmlSanitizer ;
} ) ;
2018-08-30 13:16:24 -05:00
2023-11-29 18:51:40 +09:00
services . AddSingleton < TransactionLinkProviders > ( ) ;
2018-07-22 18:38:14 +09:00
services . TryAddSingleton < LightningConfigurationProvider > ( ) ;
2018-03-23 17:27:48 +09:00
services . TryAddSingleton < LanguageService > ( ) ;
2023-07-24 09:24:32 +09:00
services . TryAddSingleton < ReportService > ( ) ;
2018-01-08 04:14:35 +09:00
services . TryAddSingleton < NBXplorerDashboard > ( ) ;
2020-12-02 07:19:48 +01:00
services . AddSingleton < ISyncSummaryProvider , NBXSyncSummaryProvider > ( ) ;
2017-10-27 17:53:04 +09:00
services . TryAddSingleton < StoreRepository > ( ) ;
2019-01-14 22:43:29 +01:00
services . TryAddSingleton < PaymentRequestRepository > ( ) ;
2018-01-11 14:36:12 +09:00
services . TryAddSingleton < BTCPayWalletProvider > ( ) ;
2021-03-11 13:34:52 +01:00
services . TryAddSingleton < WalletReceiveService > ( ) ;
2021-12-31 16:59:02 +09:00
services . AddSingleton < IHostedService > ( provider = > provider . GetService < WalletReceiveService > ( ) ) ;
2020-05-31 12:18:29 +02:00
services . TryAddSingleton < CurrencyNameTable > ( CurrencyNameTable . Instance ) ;
2024-01-18 17:16:57 +09:00
services . AddScheduledTask < FeeProviderFactory > ( TimeSpan . FromMinutes ( 3.0 ) ) ;
services . AddSingleton < IFeeProviderFactory , FeeProviderFactory > ( f = > f . GetRequiredService < FeeProviderFactory > ( ) ) ;
2017-12-17 01:04:20 +09:00
2020-06-28 17:55:27 +09:00
services . Configure < MvcOptions > ( ( o ) = >
{
2018-07-26 22:32:24 +09:00
o . ModelMetadataDetailsProviders . Add ( new SuppressChildValidationMetadataProvider ( typeof ( WalletId ) ) ) ;
o . ModelMetadataDetailsProviders . Add ( new SuppressChildValidationMetadataProvider ( typeof ( DerivationStrategyBase ) ) ) ;
} ) ;
2018-04-23 17:42:03 -05:00
2022-04-12 09:55:10 +02:00
services . AddSingleton < Services . NBXplorerConnectionFactory > ( ) ;
services . AddSingleton < IHostedService , Services . NBXplorerConnectionFactory > ( o = > o . GetRequiredService < Services . NBXplorerConnectionFactory > ( ) ) ;
2019-08-27 23:30:25 +09:00
services . AddSingleton < HostedServices . CheckConfigurationHostedService > ( ) ;
services . AddSingleton < IHostedService , HostedServices . CheckConfigurationHostedService > ( o = > o . GetRequiredService < CheckConfigurationHostedService > ( ) ) ;
2022-06-22 05:05:32 +02:00
services . AddSingleton < IHostedService , StoreEmailRuleProcessorSender > ( ) ;
2023-05-28 23:44:10 +09:00
services . AddSingleton < IHostedService , PeriodicTaskLauncherHostedService > ( ) ;
2023-11-30 10:12:44 +01:00
services . AddScheduledTask < GithubVersionFetcher > ( TimeSpan . FromDays ( 1 ) ) ;
services . AddScheduledTask < PluginUpdateFetcher > ( TimeSpan . FromDays ( 1 ) ) ;
2023-05-28 23:44:10 +09:00
2023-07-24 09:24:32 +09:00
services . AddReportProvider < PaymentsReportProvider > ( ) ;
services . AddReportProvider < OnChainWalletReportProvider > ( ) ;
services . AddReportProvider < ProductsReportProvider > ( ) ;
2023-09-19 02:55:15 +02:00
services . AddReportProvider < PayoutsReportProvider > ( ) ;
2024-02-21 14:44:49 +01:00
services . AddReportProvider < LegacyInvoiceExportReportProvider > ( ) ;
2024-05-06 18:44:16 +09:00
services . AddReportProvider < RefundsReportProvider > ( ) ;
2023-12-01 10:50:05 +01:00
services . AddWebhooks ( ) ;
2021-12-31 16:59:02 +09:00
2024-04-04 16:31:04 +09:00
services . AddSingleton < Dictionary < PaymentMethodId , IPaymentMethodBitpayAPIExtension > > ( o = >
o . GetRequiredService < IEnumerable < IPaymentMethodBitpayAPIExtension > > ( ) . ToDictionary ( o = > o . PaymentMethodId , o = > o ) ) ;
services . AddSingleton < Dictionary < PaymentMethodId , IPaymentLinkExtension > > ( o = >
o . GetRequiredService < IEnumerable < IPaymentLinkExtension > > ( ) . ToDictionary ( o = > o . PaymentMethodId , o = > o ) ) ;
services . AddSingleton < Dictionary < PaymentMethodId , IPaymentModelExtension > > ( o = >
o . GetRequiredService < IEnumerable < IPaymentModelExtension > > ( ) . ToDictionary ( o = > o . PaymentMethodId , o = > o ) ) ;
2021-10-18 05:37:59 +02:00
services . AddHttpClient ( LightningLikePayoutHandler . LightningLikePayoutHandlerOnionNamedClient )
. ConfigurePrimaryHttpMessageHandler < Socks5HttpClientHandler > ( ) ;
2020-06-24 10:34:09 +09:00
services . AddSingleton < HostedServices . PullPaymentHostedService > ( ) ;
services . AddSingleton < IHostedService , HostedServices . PullPaymentHostedService > ( o = > o . GetRequiredService < PullPaymentHostedService > ( ) ) ;
2024-04-04 16:31:04 +09:00
2019-05-24 06:11:38 +00:00
services . AddSingleton < IHostedService , NBXplorerListener > ( ) ;
2018-08-12 21:38:45 +09:00
2024-04-04 16:31:04 +09:00
2021-12-31 08:36:38 +01:00
services . AddSingleton < IUIExtension > ( new UIExtension ( "LNURL/LightningAddressNav" ,
"store-integrations-nav" ) ) ;
2019-05-24 06:11:38 +00:00
services . AddSingleton < IHostedService , LightningListener > ( ) ;
2022-08-17 09:45:51 +02:00
services . AddSingleton < IHostedService , LightningPendingPayoutListener > ( ) ;
2019-05-24 06:11:38 +00:00
2019-05-29 14:33:31 +00:00
services . AddSingleton < PaymentMethodHandlerDictionary > ( ) ;
2024-04-04 16:31:04 +09:00
services . AddSingleton < PaymentMethodViewProvider > ( ) ;
2024-05-01 10:22:07 +09:00
services . AddSingleton < PayoutMethodHandlerDictionary > ( ) ;
2020-06-12 00:01:45 -05:00
services . AddSingleton < NotificationManager > ( ) ;
2020-06-11 23:52:46 -05:00
services . AddScoped < NotificationSender > ( ) ;
2024-01-17 10:08:39 +01:00
2018-01-08 02:36:41 +09:00
services . AddSingleton < IHostedService , NBXplorerWaiters > ( ) ;
2020-11-06 22:23:10 +09:00
services . AddSingleton < IHostedService , InvoiceEventSaverService > ( ) ;
2022-01-11 13:14:10 +09:00
services . AddSingleton < IHostedService , BitpayIPNSender > ( ) ;
2018-01-08 02:36:41 +09:00
services . AddSingleton < IHostedService , InvoiceWatcher > ( ) ;
2018-04-14 22:35:52 +09:00
services . AddSingleton < IHostedService , RatesHostedService > ( ) ;
2019-01-16 19:14:45 +09:00
services . AddSingleton < IHostedService , BackgroundJobSchedulerHostedService > ( ) ;
2019-02-19 13:18:30 +09:00
services . AddSingleton < IHostedService , AppHubStreamer > ( ) ;
2019-09-02 15:37:52 +02:00
services . AddSingleton < IHostedService , AppInventoryUpdaterHostedService > ( ) ;
2020-04-28 08:06:28 +02:00
services . AddSingleton < IHostedService , TransactionLabelMarkerHostedService > ( ) ;
2020-03-13 11:47:22 +01:00
services . AddSingleton < IHostedService , UserEventHostedService > ( ) ;
2019-07-24 17:59:30 +09:00
services . AddSingleton < IHostedService , DynamicDnsHostedService > ( ) ;
2019-01-14 22:43:29 +01:00
services . AddSingleton < IHostedService , PaymentRequestStreamer > ( ) ;
2019-01-16 19:14:45 +09:00
services . AddSingleton < IBackgroundJobClient , BackgroundJobClient > ( ) ;
2019-10-12 20:35:30 +09:00
services . AddScoped < IAuthorizationHandler , CookieAuthorizationHandler > ( ) ;
services . AddScoped < IAuthorizationHandler , BitpayAuthorizationHandler > ( ) ;
2020-07-30 19:12:14 -05:00
2020-06-16 23:29:25 +09:00
services . AddSingleton < INotificationHandler , NewVersionNotification . Handler > ( ) ;
2024-01-31 06:45:54 +01:00
services . AddSingleton < INotificationHandler , NewUserRequiresApprovalNotification . Handler > ( ) ;
2024-03-19 14:58:33 +01:00
services . AddSingleton < INotificationHandler , InviteAcceptedNotification . Handler > ( ) ;
2023-11-30 10:12:44 +01:00
services . AddSingleton < INotificationHandler , PluginUpdateNotification . Handler > ( ) ;
2020-06-22 09:32:51 +02:00
services . AddSingleton < INotificationHandler , InvoiceEventNotification . Handler > ( ) ;
2020-06-24 10:34:09 +09:00
services . AddSingleton < INotificationHandler , PayoutNotification . Handler > ( ) ;
2021-07-16 09:57:37 +02:00
services . AddSingleton < INotificationHandler , ExternalPayoutTransactionNotification . Handler > ( ) ;
2020-12-28 11:10:53 +01:00
services . AddSingleton < IHostedService , DbMigrationsHostedService > ( ) ;
2023-09-18 10:55:05 +09:00
2018-01-08 02:36:41 +09:00
services . TryAddSingleton < ExplorerClientProvider > ( ) ;
2021-07-12 14:17:25 +02:00
services . AddSingleton < IExplorerClientProvider , ExplorerClientProvider > ( x = >
x . GetRequiredService < ExplorerClientProvider > ( ) ) ;
2017-10-27 17:53:04 +09:00
services . TryAddSingleton < Bitpay > ( o = >
{
2021-01-27 14:39:38 +09:00
if ( o . GetRequiredService < BTCPayServerOptions > ( ) . NetworkType = = ChainName . Mainnet )
2017-10-27 17:53:04 +09:00
return new Bitpay ( new Key ( ) , new Uri ( "https://bitpay.com/" ) ) ;
else
return new Bitpay ( new Key ( ) , new Uri ( "https://test.bitpay.com/" ) ) ;
} ) ;
2023-01-30 09:46:12 +09:00
RegisterRateSources ( services ) ;
2018-08-22 16:53:40 +09:00
services . TryAddSingleton < RateProviderFactory > ( ) ;
services . TryAddSingleton < RateFetcher > ( ) ;
2017-12-17 01:04:20 +09:00
2017-10-27 17:53:04 +09:00
services . TryAddScoped < IHttpContextAccessor , HttpContextAccessor > ( ) ;
2022-01-07 12:08:28 +09:00
services . AddTransient < BitpayAccessTokenController > ( ) ;
2022-01-07 12:32:00 +09:00
services . AddTransient < UIInvoiceController > ( ) ;
services . AddTransient < UIPaymentRequestController > ( ) ;
2023-03-30 19:54:11 +02:00
services . AddSingleton < LabelService > ( ) ;
2017-10-27 17:53:04 +09:00
// Add application services.
2019-01-06 15:53:37 +01:00
services . AddSingleton < EmailSenderFactory > ( ) ;
2022-12-08 13:16:18 +09:00
services . AddSingleton < InvoiceActivator > ( ) ;
2021-12-31 16:59:02 +09:00
2021-07-27 14:11:47 +02:00
//create a simple client which hooks up to the http scope
services . AddScoped < BTCPayServerClient , LocalBTCPayServerClient > ( ) ;
//also provide a factory that can impersonate user/store id
services . AddSingleton < IBTCPayServerClientFactory , BTCPayServerClientFactory > ( ) ;
2022-04-24 05:19:34 +02:00
services . AddPayoutProcesors ( ) ;
2022-11-25 02:42:55 +01:00
services . AddForms ( ) ;
2020-06-28 17:55:27 +09:00
2020-02-24 14:36:15 +01:00
services . AddAPIKeyAuthentication ( ) ;
services . AddBtcPayServerAuthenticationSchemes ( ) ;
2019-10-12 20:35:30 +09:00
services . AddAuthorization ( o = > o . AddBTCPayPolicies ( ) ) ;
2017-09-15 19:25:02 +09:00
2019-05-14 15:46:43 +00:00
services . AddCors ( options = >
2018-08-06 12:04:36 +09:00
{
2019-05-14 15:46:43 +00:00
options . AddPolicy ( CorsPolicies . All , p = > p . AllowAnyHeader ( ) . AllowAnyMethod ( ) . AllowAnyOrigin ( ) ) ;
2018-08-06 12:04:36 +09:00
} ) ;
2022-06-21 12:33:20 +09:00
services . AddRateLimits ( ) ;
2019-11-16 14:06:37 +09:00
services . AddLogging ( logBuilder = >
{
var debugLogFile = BTCPayServerOptions . GetDebugLog ( configuration ) ;
if ( ! string . IsNullOrEmpty ( debugLogFile ) )
{
Serilog . Log . Logger = new LoggerConfiguration ( )
. Enrich . FromLogContext ( )
. MinimumLevel . Is ( BTCPayServerOptions . GetDebugLogLevel ( configuration ) )
. WriteTo . File ( debugLogFile , rollingInterval : RollingInterval . Day , fileSizeLimitBytes : MAX_DEBUG_LOG_FILE_SIZE , rollOnFileSizeLimit : true , retainedFileCountLimit : 1 )
. CreateLogger ( ) ;
2020-01-16 14:00:31 +09:00
logBuilder . AddProvider ( new Serilog . Extensions . Logging . SerilogLoggerProvider ( Log . Logger ) ) ;
2019-11-16 14:06:37 +09:00
}
} ) ;
2020-12-28 21:59:01 +09:00
services . AddSingleton < IObjectModelValidator , SkippableObjectValidatorProvider > ( ) ;
services . SkipModelValidation < RootedKeyPath > ( ) ;
2022-10-26 13:34:09 +09:00
services . SkipModelValidation < NodeInfo > ( ) ;
2021-10-11 12:32:09 +09:00
if ( configuration . GetOrDefault < bool > ( "cheatmode" , false ) )
{
services . AddSingleton < Cheater > ( ) ;
2021-10-11 17:49:04 +09:00
services . AddSingleton < IHostedService , Cheater > ( o = > o . GetRequiredService < Cheater > ( ) ) ;
2021-10-11 12:32:09 +09:00
}
2023-04-19 21:13:31 +09:00
var userAgent = new System . Net . Http . Headers . ProductInfoHeaderValue ( "BTCPayServer" , BTCPayServerEnvironment . GetInformationalVersion ( ) ) ;
foreach ( var clientName in WebhookSender . AllClients . Concat ( new [ ] { BitpayIPNSender . NamedClient } ) )
{
services . AddHttpClient ( clientName )
. ConfigureHttpClient ( client = >
{
client . DefaultRequestHeaders . UserAgent . Add ( userAgent ) ;
} ) ;
}
2017-10-27 17:53:04 +09:00
return services ;
}
2020-12-28 21:59:01 +09:00
2024-01-17 10:08:39 +01:00
public static void AddOnchainWalletParsers ( IServiceCollection services )
{
services . AddSingleton < WalletFileParsers > ( ) ;
services . AddSingleton < IWalletFileParser , BSMSWalletFileParser > ( ) ;
services . AddSingleton < IWalletFileParser , NBXDerivGenericWalletFileParser > ( ) ;
services . AddSingleton < IWalletFileParser , ElectrumWalletFileParser > ( ) ;
services . AddSingleton < IWalletFileParser , OutputDescriptorWalletFileParser > ( provider = > provider . GetService < OutputDescriptorWalletFileParser > ( ) ) ;
services . AddSingleton < OutputDescriptorWalletFileParser > ( ) ;
services . AddSingleton < IWalletFileParser , SpecterWalletFileParser > ( ) ;
services . AddSingleton < IWalletFileParser , OutputDescriptorJsonWalletFileParser > ( ) ;
services . AddSingleton < IWalletFileParser , WasabiWalletFileParser > ( ) ;
}
2023-01-30 09:46:12 +09:00
internal static void RegisterRateSources ( IServiceCollection services )
{
// We need to be careful to only add exchanges which OnGetTickers implementation make only 1 request
services . AddRateProviderExchangeSharp < ExchangeBinanceAPI > ( new ( "binance" , "Binance" , "https://api.binance.com/api/v1/ticker/24hr" ) ) ;
2023-10-06 09:08:50 +02:00
services . AddRateProviderExchangeSharp < ExchangePoloniexAPI > ( new ( "poloniex" , "Poloniex" , " https://api.poloniex.com/markets/price" ) ) ;
2023-01-30 09:46:12 +09:00
services . AddRateProviderExchangeSharp < ExchangeNDAXAPI > ( new ( "ndax" , "NDAX" , "https://ndax.io/api/returnTicker" ) ) ;
services . AddRateProviderExchangeSharp < ExchangeBitfinexAPI > ( new ( "bitfinex" , "Bitfinex" , "https://api.bitfinex.com/v2/tickers?symbols=tBTCUSD,tLTCUSD,tLTCBTC,tETHUSD,tETHBTC,tETCBTC,tETCUSD,tRRTUSD,tRRTBTC,tZECUSD,tZECBTC,tXMRUSD,tXMRBTC,tDSHUSD,tDSHBTC,tBTCEUR,tBTCJPY,tXRPUSD,tXRPBTC,tIOTUSD,tIOTBTC,tIOTETH,tEOSUSD,tEOSBTC,tEOSETH,tSANUSD,tSANBTC,tSANETH,tOMGUSD,tOMGBTC,tOMGETH,tNEOUSD,tNEOBTC,tNEOETH,tETPUSD,tETPBTC,tETPETH,tQTMUSD,tQTMBTC,tQTMETH,tAVTUSD,tAVTBTC,tAVTETH,tEDOUSD,tEDOBTC,tEDOETH,tBTGUSD,tBTGBTC,tDATUSD,tDATBTC,tDATETH,tQSHUSD,tQSHBTC,tQSHETH,tYYWUSD,tYYWBTC,tYYWETH,tGNTUSD,tGNTBTC,tGNTETH,tSNTUSD,tSNTBTC,tSNTETH,tIOTEUR,tBATUSD,tBATBTC,tBATETH,tMNAUSD,tMNABTC,tMNAETH,tFUNUSD,tFUNBTC,tFUNETH,tZRXUSD,tZRXBTC,tZRXETH,tTNBUSD,tTNBBTC,tTNBETH,tSPKUSD,tSPKBTC,tSPKETH,tTRXUSD,tTRXBTC,tTRXETH,tRCNUSD,tRCNBTC,tRCNETH,tRLCUSD,tRLCBTC,tRLCETH,tAIDUSD,tAIDBTC,tAIDETH,tSNGUSD,tSNGBTC,tSNGETH,tREPUSD,tREPBTC,tREPETH,tELFUSD,tELFBTC,tELFETH,tNECUSD,tNECBTC,tNECETH,tBTCGBP,tETHEUR,tETHJPY,tETHGBP,tNEOEUR,tNEOJPY,tNEOGBP,tEOSEUR,tEOSJPY,tEOSGBP,tIOTJPY,tIOTGBP,tIOSUSD,tIOSBTC,tIOSETH,tAIOUSD,tAIOBTC,tAIOETH,tREQUSD,tREQBTC,tREQETH,tRDNUSD,tRDNBTC,tRDNETH,tLRCUSD,tLRCBTC,tLRCETH,tWAXUSD,tWAXBTC,tWAXETH,tDAIUSD,tDAIBTC,tDAIETH,tAGIUSD,tAGIBTC,tAGIETH,tBFTUSD,tBFTBTC,tBFTETH,tMTNUSD,tMTNBTC,tMTNETH,tODEUSD,tODEBTC,tODEETH,tANTUSD,tANTBTC,tANTETH,tDTHUSD,tDTHBTC,tDTHETH,tMITUSD,tMITBTC,tMITETH,tSTJUSD,tSTJBTC,tSTJETH,tXLMUSD,tXLMEUR,tXLMJPY,tXLMGBP,tXLMBTC,tXLMETH,tXVGUSD,tXVGEUR,tXVGJPY,tXVGGBP,tXVGBTC,tXVGETH,tBCIUSD,tBCIBTC,tMKRUSD,tMKRBTC,tMKRETH,tKNCUSD,tKNCBTC,tKNCETH,tPOAUSD,tPOABTC,tPOAETH,tEVTUSD,tLYMUSD,tLYMBTC,tLYMETH,tUTKUSD,tUTKBTC,tUTKETH,tVEEUSD,tVEEBTC,tVEEETH,tDADUSD,tDADBTC,tDADETH,tORSUSD,tORSBTC,tORSETH,tAUCUSD,tAUCBTC,tAUCETH,tPOYUSD,tPOYBTC,tPOYETH,tFSNUSD,tFSNBTC,tFSNETH,tCBTUSD,tCBTBTC,tCBTETH,tZCNUSD,tZCNBTC,tZCNETH,tSENUSD,tSENBTC,tSENETH,tNCAUSD,tNCABTC,tNCAETH,tCNDUSD,tCNDBTC,tCNDETH,tCTXUSD,tCTXBTC,tCTXETH,tPAIUSD,tPAIBTC,tSEEUSD,tSEEBTC,tSEEETH,tESSUSD,tESSBTC,tESSETH,tATMUSD,tATMBTC,tATMETH,tHOTUSD,tHOTBTC,tHOTETH,tDTAUSD,tDTABTC,tDTAETH,tIQXUSD,tIQXBTC,tIQXEOS,tWPRUSD,tWPRBTC,tWPRETH,tZILUSD,tZILBTC,tZILETH,tBNTUSD,tBNTBTC,tBNTETH,tABSUSD,tABSETH,tXRAUSD,tXRAETH,tMANUSD,tMANETH,tBBNUSD,tBBNETH,tNIOUSD,tNIOETH,tDGXUSD,tDGXETH,tVETUSD,tVETBTC,tVETETH,tUTNUSD,tUTNETH,tTKNUSD,tTKNETH,tGOTUSD,tGOTEUR,tGOTETH,tXTZUSD,tXTZBTC,tCNNUSD,tCNNETH,tBOXUSD,tBOXETH,tTRXEUR,tTRXGBP,tTRXJPY,tMGOUSD,tMGOETH,tRTEUSD,tRTEETH,tYGGUSD,tYGGETH,tMLNUSD,tMLNETH,tWTCUSD,tWTCETH,tCSXUSD,tCSXETH,tOMNUSD,tOMNBTC,tINTUSD,tINTETH,tDRNUSD,tDRNETH,tPNKUSD,tPNKETH,tDGBUSD,tDGBBTC,tBSVUSD,tBSVBTC,tBABUSD,tBABBTC,tWLOUSD,tWLOXLM,tVLDUSD,tVLDETH,tENJUSD,tENJETH,tONLUSD,tONLETH,tRBTUSD,tRBTBTC,tUSTUSD,tEUTEUR,tEUTUSD,tGSDUSD,tUDCUSD,tTSDUSD,tPAXUSD,tRIFUSD,tRIFBTC,tPASUSD,tPASETH,tVSYUSD,tVSYBTC,tZRXDAI,tMKRDAI,tOMGDAI,tBTTUSD,tBTTBTC,tBTCUST,tETHUST,tCLOUSD,tCLOBTC,tIMPUSD,tIMPETH,tLTCUST,tEOSUST,tBABUST,tSCRUSD,tSCRETH,tGNOUSD,tGNOETH,tGENUSD,tGENETH,tATOUSD,tATOBTC,tATOETH,tWBTUSD,tXCHUSD,tEUSUSD,tWBTETH,tXCHETH,tEUSETH,tLEOUSD,tLEOBTC,tLEOUST,tLEOEOS,tLEOETH,tASTUSD,tASTETH,tFOAUSD,tFOAETH,tUFRUSD,tUFRETH,tZBTUSD,tZBTUST,tOKBUSD,tUSKUSD,tGTXUSD,tKANUSD,tOKBUST,tOKBETH,tOKBBTC,tUSKUST,tUSKETH,tUSKBTC,tUSKEOS,tGTXUST,tKANUST,tAMPUSD,tALGUSD,tALGBTC,tALGUST,tBTCXCH,tSWMUSD,tSWMETH,tTRIUSD,tTRIETH,tLOOUSD,tLOOETH,tAMPUST,tDUSK:USD,tDUSK:BTC,tUOSUSD,tUOSBTC,tRRBUSD,tRRBUST,tDTXUSD,tDTXUST,tAMPBTC,tFTTUSD,tFTTUST,tPAXUST,tUDCUST,tTSDUST,tBTC:CNHT,tUST:CNHT,tCNH:CNHT,tCHZUSD,tCHZUST,tBTCF0:USTF0,tETHF0:USTF0" ) ) ;
services . AddRateProviderExchangeSharp < ExchangeOKExAPI > ( new ( "okex" , "OKEx" , "https://www.okex.com/api/futures/v3/instruments/ticker" ) ) ;
services . AddRateProviderExchangeSharp < ExchangeCoinbaseAPI > ( new ( "coinbasepro" , "Coinbase Pro" , "https://api.pro.coinbase.com/products" ) ) ;
// Handmade providers
services . AddRateProvider < HitBTCRateProvider > ( ) ;
services . AddRateProvider < CoinGeckoRateProvider > ( ) ;
services . AddRateProvider < KrakenExchangeRateProvider > ( ) ;
services . AddRateProvider < ByllsRateProvider > ( ) ;
services . AddRateProvider < BudaRateProvider > ( ) ;
services . AddRateProvider < BitbankRateProvider > ( ) ;
2024-01-30 02:18:42 +01:00
services . AddRateProvider < BitnobRateProvider > ( ) ;
2023-01-30 09:46:12 +09:00
services . AddRateProvider < BitpayRateProvider > ( ) ;
services . AddRateProvider < RipioExchangeProvider > ( ) ;
services . AddRateProvider < CryptoMarketExchangeRateProvider > ( ) ;
services . AddRateProvider < BitflyerRateProvider > ( ) ;
services . AddRateProvider < YadioRateProvider > ( ) ;
services . AddRateProvider < BtcTurkRateProvider > ( ) ;
2023-07-10 10:31:48 +02:00
services . AddRateProvider < FreeCurrencyRatesRateProvider > ( ) ;
2023-01-30 09:46:12 +09:00
2024-04-04 16:31:04 +09:00
services . AddSingleton < InvoiceBlobMigratorHostedService > ( ) ;
services . AddSingleton < IHostedService , InvoiceBlobMigratorHostedService > ( o = > o . GetRequiredService < InvoiceBlobMigratorHostedService > ( ) ) ;
2023-01-30 09:46:12 +09:00
// Broken
// Providers.Add("argoneum", new ArgoneumRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_ARGONEUM")));
// Those exchanges make too many requests, exchange sharp do not parallelize so it is too slow...
//AddExchangeSharpProviders<ExchangeGeminiAPI>("gemini");
//AddExchangeSharpProviders<ExchangeBitstampAPI>("bitstamp");
//AddExchangeSharpProviders<ExchangeBitMEXAPI>("bitmex");
}
public static void AddRateProvider < T > ( this IServiceCollection services ) where T : class , IRateProvider
{
services . AddSingleton < IRateProvider , T > ( ) ;
}
2023-11-29 18:51:40 +09:00
public static IServiceCollection AddBTCPayNetwork ( this IServiceCollection services , BTCPayNetworkBase network )
{
services . AddSingleton < BTCPayNetworkBase > ( network ) ;
return services ;
}
2024-04-04 16:31:04 +09:00
public static IServiceCollection AddBTCPayNetwork ( this IServiceCollection services , BTCPayNetwork network )
{
// BTC
{
var pmi = PaymentTypes . CHAIN . GetPaymentMethodId ( network . CryptoCode ) ;
services . AddSingleton < BTCPayNetworkBase > ( network ) ;
services . AddSingleton < IPaymentMethodHandler > ( provider = >
( BitcoinLikePaymentHandler ) ActivatorUtilities . CreateInstance ( provider , typeof ( BitcoinLikePaymentHandler ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentLinkExtension > ( provider = >
( IPaymentLinkExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( BitcoinPaymentLinkExtension ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentModelExtension > ( provider = >
( BitcoinPaymentModelExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( BitcoinPaymentModelExtension ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentMethodBitpayAPIExtension > ( provider = >
( IPaymentMethodBitpayAPIExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( BitcoinPaymentMethodBitpayAPIExtension ) , new object [ ] { pmi } ) ) ;
services . AddSingleton < IPaymentMethodViewExtension > ( provider = >
( IPaymentMethodViewExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( BitcoinPaymentMethodViewExtension ) , new object [ ] { pmi } ) ) ;
2024-05-01 10:22:07 +09:00
if ( ! network . ReadonlyWallet & & network . WalletSupported )
{
var payoutMethodId = PayoutTypes . CHAIN . GetPayoutMethodId ( network . CryptoCode ) ;
services . AddSingleton < IPayoutHandler > ( provider = >
( IPayoutHandler ) ActivatorUtilities . CreateInstance ( provider , typeof ( BitcoinLikePayoutHandler ) , new object [ ] { payoutMethodId , network } ) ) ;
}
2024-04-04 16:31:04 +09:00
}
if ( network . NBitcoinNetwork . Consensus . SupportSegwit & & network . SupportLightning )
{
// LN
{
var pmi = PaymentTypes . LN . GetPaymentMethodId ( network . CryptoCode ) ;
services . AddSingleton < IPaymentMethodHandler > ( provider = >
( LightningLikePaymentHandler ) ActivatorUtilities . CreateInstance ( provider , typeof ( LightningLikePaymentHandler ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentLinkExtension > ( provider = >
( IPaymentLinkExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LightningPaymentLinkExtension ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentModelExtension > ( provider = >
( IPaymentModelExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LightningPaymentModelExtension ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentMethodViewExtension > ( provider = >
( IPaymentMethodViewExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LightningPaymentMethodViewExtension ) , new object [ ] { pmi } ) ) ;
services . AddSingleton < IPaymentMethodBitpayAPIExtension > ( provider = >
( IPaymentMethodBitpayAPIExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LightningPaymentMethodBitpayAPIExtension ) , new object [ ] { pmi } ) ) ;
2024-05-01 10:22:07 +09:00
var payoutMethodId = PayoutTypes . LN . GetPayoutMethodId ( network . CryptoCode ) ;
services . AddSingleton < IPayoutHandler > ( provider = >
( IPayoutHandler ) ActivatorUtilities . CreateInstance ( provider , typeof ( LightningLikePayoutHandler ) , new object [ ] { payoutMethodId , network } ) ) ;
2024-04-04 16:31:04 +09:00
}
// LNURL
{
var pmi = PaymentTypes . LNURL . GetPaymentMethodId ( network . CryptoCode ) ;
services . AddSingleton < IPaymentMethodHandler > ( provider = >
( LNURLPayPaymentHandler ) ActivatorUtilities . CreateInstance ( provider , typeof ( LNURLPayPaymentHandler ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentLinkExtension > ( provider = >
( IPaymentLinkExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LNURLPayPaymentLinkExtension ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentModelExtension > ( provider = >
( IPaymentModelExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LNURLPayPaymentModelExtension ) , new object [ ] { network , pmi } ) ) ;
services . AddSingleton < IPaymentMethodViewExtension > ( provider = >
( IPaymentMethodViewExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LNURLPaymentMethodViewExtension ) , new object [ ] { pmi } ) ) ;
services . AddSingleton < IPaymentMethodBitpayAPIExtension > ( provider = >
( IPaymentMethodBitpayAPIExtension ) ActivatorUtilities . CreateInstance ( provider , typeof ( LNURLPayPaymentMethodBitpayAPIExtension ) , new object [ ] { pmi } ) ) ;
}
}
return services ;
}
public static void AddTransactionLinkProvider ( this IServiceCollection services , string cryptoCode , TransactionLinkProvider provider )
2023-11-29 18:51:40 +09:00
{
2024-04-04 16:31:04 +09:00
services . AddSingleton < TransactionLinkProviders . Entry > ( new TransactionLinkProviders . Entry ( cryptoCode , provider ) ) ;
2023-11-29 18:51:40 +09:00
}
2023-01-30 09:46:12 +09:00
public static void AddRateProviderExchangeSharp < T > ( this IServiceCollection services , RateSourceInfo rateInfo ) where T : ExchangeAPI
{
services . AddSingleton < IRateProvider , ExchangeSharpRateProvider < T > > ( o = >
{
var instance = ActivatorUtilities . CreateInstance < ExchangeSharpRateProvider < T > > ( o ) ;
instance . RateSourceInfo = rateInfo ;
return instance ;
} ) ;
}
2022-05-24 13:18:16 +09:00
private static void AddSettingsAccessor < T > ( IServiceCollection services ) where T : class , new ( )
{
services . TryAddSingleton < ISettingsAccessor < T > , SettingsAccessor < T > > ( ) ;
services . AddSingleton < IHostedService > ( provider = > ( SettingsAccessor < T > ) provider . GetRequiredService < ISettingsAccessor < T > > ( ) ) ;
services . AddSingleton < IStartupTask > ( provider = > ( SettingsAccessor < T > ) provider . GetRequiredService < ISettingsAccessor < T > > ( ) ) ;
// Singletons shouldn't reference the settings directly, but ISettingsAccessor<T>, since singletons won't have refreshed values of the setting
services . AddTransient < T > ( provider = > provider . GetRequiredService < ISettingsAccessor < T > > ( ) . Settings ) ;
}
2020-12-28 21:59:01 +09:00
public static void SkipModelValidation < T > ( this IServiceCollection services )
{
services . AddSingleton < SkippableObjectValidatorProvider . ISkipValidation , SkippableObjectValidatorProvider . SkipValidationType < T > > ( ) ;
}
2019-11-16 14:06:37 +09:00
private const long MAX_DEBUG_LOG_FILE_SIZE = 2000000 ; // If debug log is in use roll it every N MB.
2020-02-24 14:36:15 +01:00
private static void AddBtcPayServerAuthenticationSchemes ( this IServiceCollection services )
2019-05-14 15:46:43 +00:00
{
services . AddAuthentication ( )
2020-02-24 14:36:15 +01:00
. AddBitpayAuthentication ( )
. AddAPIKeyAuthentication ( ) ;
2019-05-14 15:46:43 +00:00
}
2017-09-13 15:47:34 +09:00
2017-10-27 17:53:04 +09:00
public static IApplicationBuilder UsePayServer ( this IApplicationBuilder app )
{
2021-12-16 15:04:06 +01:00
app . UseMiddleware < GreenfieldMiddleware > ( ) ;
2017-10-27 17:53:04 +09:00
app . UseMiddleware < BTCPayMiddleware > ( ) ;
2020-06-28 17:55:27 +09:00
return app ;
2017-10-27 17:53:04 +09:00
}
2019-10-09 22:26:54 +09:00
public static IApplicationBuilder UseHeadersOverride ( this IApplicationBuilder app )
{
app . UseMiddleware < HeadersOverrideMiddleware > ( ) ;
return app ;
}
2017-10-27 17:53:04 +09:00
}
2017-09-13 15:47:34 +09:00
}