public IActionResult GetStoreEthereumLikePaymentMethods()
        {
            var eth = StoreData.GetSupportedPaymentMethods(_btcPayNetworkProvider)
                      .OfType <EthereumSupportedPaymentMethod>();

            var excludeFilters = StoreData.GetStoreBlob().GetExcludedPaymentMethods();
            var ethNetworks    = _btcPayNetworkProvider.GetAll().OfType <EthereumBTCPayNetwork>()
                                 .GroupBy(network => network.ChainId);

            var vm = new ViewEthereumStoreOptionsViewModel();

            foreach (var chainId in ethNetworks)
            {
                var items = new List <ViewEthereumStoreOptionItemViewModel>();
                foreach (var network in chainId)
                {
                    var paymentMethodId      = new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance);
                    var matchedPaymentMethod = eth.SingleOrDefault(method =>
                                                                   method.PaymentId == paymentMethodId);
                    items.Add(new ViewEthereumStoreOptionItemViewModel()
                    {
                        CryptoCode  = network.CryptoCode,
                        Enabled     = matchedPaymentMethod != null && !excludeFilters.Match(paymentMethodId),
                        IsToken     = network is ERC20BTCPayNetwork,
                        RootAddress = matchedPaymentMethod?.GetWalletDerivator()?.Invoke(0) ?? "not configured"
                    });
                }

                vm.Items.Add(chainId.Key, items);
            }

            return(View(vm));
        }
Esempio n. 2
0
        private void AddPaymentMethods(StoreData store, StoreViewModel vm)
        {
            var derivationByCryptoCode =
                store
                .GetSupportedPaymentMethods(_NetworkProvider)
                .OfType <DerivationStrategy>()
                .ToDictionary(c => c.Network.CryptoCode);

            foreach (var network in _NetworkProvider.GetAll())
            {
                var strategy = derivationByCryptoCode.TryGet(network.CryptoCode);
                vm.DerivationSchemes.Add(new StoreViewModel.DerivationScheme()
                {
                    Crypto = network.CryptoCode,
                    Value  = strategy?.DerivationStrategyBase?.ToString() ?? string.Empty
                });
            }

            var lightningByCryptoCode = store
                                        .GetSupportedPaymentMethods(_NetworkProvider)
                                        .OfType <Payments.Lightning.LightningSupportedPaymentMethod>()
                                        .ToDictionary(c => c.CryptoCode);

            foreach (var network in _NetworkProvider.GetAll())
            {
                var lightning = lightningByCryptoCode.TryGet(network.CryptoCode);
                vm.LightningNodes.Add(new StoreViewModel.LightningNode()
                {
                    CryptoCode = network.CryptoCode,
                    Address    = lightning?.GetLightningUrl()?.BaseUri.AbsoluteUri ?? string.Empty
                });
            }
        }
        protected override CommandLineApplication CreateCommandLineApplicationCore()
        {
            var provider = new BTCPayNetworkProvider(NetworkType.Mainnet);
            var chains   = string.Join(",", provider.GetAll().Select(n => n.CryptoCode.ToLowerInvariant()).ToArray());
            CommandLineApplication app = new CommandLineApplication(true)
            {
                FullName = "BTCPay\r\nOpen source, self-hosted payment processor.",
                Name     = "BTCPay"
            };

            app.HelpOption("-? | -h | --help");
            app.Option("-n | --network", $"Set the network among (mainnet,testnet,regtest) (default: mainnet)", CommandOptionType.SingleValue);
            app.Option("--testnet | -testnet", $"Use testnet (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--regtest | -regtest", $"Use regtest (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--chains | -c", $"Chains to support as a comma separated (default: btc; available: {chains})", CommandOptionType.SingleValue);
            app.Option("--postgres", $"Connection string to a PostgreSQL database (default: SQLite)", CommandOptionType.SingleValue);
            app.Option("--externalurl", $"The expected external URL of this service, to use if BTCPay is behind a reverse proxy (default: empty, use the incoming HTTP request to figure out)", CommandOptionType.SingleValue);
            app.Option("--bundlejscss", $"Bundle JavaScript and CSS files for better performance (default: true)", CommandOptionType.SingleValue);
            app.Option("--rootpath", "The root path in the URL to access BTCPay (default: /)", CommandOptionType.SingleValue);
            app.Option("--sshconnection", "SSH server to manage BTCPay under the form user@server:port (default: root@externalhost or empty)", CommandOptionType.SingleValue);
            app.Option("--sshpassword", "SSH password to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshkeyfile", "SSH private key file to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshkeyfilepassword", "Password of the SSH keyfile (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue);
            foreach (var network in provider.GetAll())
            {
                var crypto = network.CryptoCode.ToLowerInvariant();
                app.Option($"--{crypto}explorerurl", $"URL of the NBXplorer for {network.CryptoCode} (default: {network.NBXplorerNetwork.DefaultSettings.DefaultUrl})", CommandOptionType.SingleValue);
                app.Option($"--{crypto}explorercookiefile", $"Path to the cookie file (default: {network.NBXplorerNetwork.DefaultSettings.DefaultCookieFile})", CommandOptionType.SingleValue);
                app.Option($"--{crypto}lightning", $"Easy configuration of lightning for the server administrator: Must be a UNIX socket of c-lightning (lightning-rpc) or URL to a charge server (default: empty)", CommandOptionType.SingleValue);
                app.Option($"--{crypto}externallndgrpc", $"The LND gRPC configuration BTCPay will expose to easily connect to the internal lnd wallet from Zap wallet (default: empty)", CommandOptionType.SingleValue);
            }
            return(app);
        }
Esempio n. 4
0
        protected override CommandLineApplication CreateCommandLineApplicationCore()
        {
            var provider = new BTCPayNetworkProvider(ChainType.Main);
            var chains   = string.Join(",", provider.GetAll().Select(n => n.CryptoCode.ToLowerInvariant()).ToArray());
            CommandLineApplication app = new CommandLineApplication(true)
            {
                FullName = "BTCPay\r\nOpen source, self-hosted payment processor.",
                Name     = "BTCPay"
            };

            app.HelpOption("-? | -h | --help");
            app.Option("-n | --network", $"Set the network among (mainnet,testnet,regtest) (default: mainnet)", CommandOptionType.SingleValue);
            app.Option("--testnet | -testnet", $"Use testnet (Deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--regtest | -regtest", $"Use regtest (Deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--chains | -c", $"Chains to support comma separated (default: btc, available: {chains})", CommandOptionType.SingleValue);
            app.Option("--postgres", $"Connection string to postgres database (default: sqlite is used)", CommandOptionType.SingleValue);
            foreach (var network in provider.GetAll())
            {
                var crypto = network.CryptoCode.ToLowerInvariant();
                app.Option($"--{crypto}explorerurl", $"Url of the NBxplorer for {network.CryptoCode} (default: {network.NBXplorerNetwork.DefaultSettings.DefaultUrl})", CommandOptionType.SingleValue);
                app.Option($"--{crypto}explorercookiefile", $"Path to the cookie file (default: {network.NBXplorerNetwork.DefaultSettings.DefaultCookieFile})", CommandOptionType.SingleValue);
            }
            app.Option("--externalurl", $"The expected external url of this service, to use if BTCPay is behind a reverse proxy (default: empty, use the incoming HTTP request to figure out)", CommandOptionType.SingleValue);
            return(app);
        }
Esempio n. 5
0
        protected override CommandLineApplication CreateCommandLineApplicationCore()
        {
            var provider = new BTCPayNetworkProvider(ChainName.Mainnet);
            var chains   = string.Join(",", provider.GetAll().Select(n => n.CryptoCode.ToLowerInvariant()).ToArray());
            CommandLineApplication app = new CommandLineApplication(true)
            {
                FullName = "BTCPay\r\nOpen source, self-hosted payment processor.",
                Name     = "BTCPay"
            };

            app.HelpOption("-? | -h | --help");
            app.Option("-n | --network", $"Set the network among (mainnet,testnet,regtest) (default: mainnet)", CommandOptionType.SingleValue);
            app.Option("--testnet | -testnet", $"Use testnet (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--regtest | -regtest", $"Use regtest (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--signet | -signet", $"Use signet (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--chains | -c", $"Chains to support as a comma separated (default: btc; available: {chains})", CommandOptionType.SingleValue);
            app.Option("--postgres", $"Connection string to a PostgreSQL database", CommandOptionType.SingleValue);
            app.Option("--mysql", $"Connection string to a MySQL database", CommandOptionType.SingleValue);
            app.Option("--nocsp", $"Disable CSP (default false)", CommandOptionType.BoolValue);
            app.Option("--sqlitefile", $"File name to an SQLite database file inside the data directory", CommandOptionType.SingleValue);
            app.Option("--externalservices", $"Links added to external services inside Server Settings / Services under the format service1:path2;service2:path2.(default: empty)", CommandOptionType.SingleValue);
            app.Option("--bundlejscss", $"Bundle JavaScript and CSS files for better performance (default: true)", CommandOptionType.SingleValue);
            app.Option("--rootpath", "The root path in the URL to access BTCPay (default: /)", CommandOptionType.SingleValue);
            app.Option("--sshconnection", "SSH server to manage BTCPay under the form user@server:port (default: root@externalhost or empty)", CommandOptionType.SingleValue);
            app.Option("--sshpassword", "SSH password to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshkeyfile", "SSH private key file to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshkeyfilepassword", "Password of the SSH keyfile (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshauthorizedkeys", "Path to a authorized_keys file that BTCPayServer can modify from the website (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue);
            app.Option("--torrcfile", "Path to torrc file containing hidden services directories (default: empty)", CommandOptionType.SingleValue);
            app.Option("--torservices", "Tor hostnames of available services added to Server Settings (and sets onion header for btcpay). Format: btcpayserver:host.onion:80;btc-p2p:host2.onion:81,BTC-RPC:host3.onion:82,UNKNOWN:host4.onion:83. (default: empty)", CommandOptionType.SingleValue);
            app.Option("--socksendpoint", "Socks endpoint to connect to onion urls (default: empty)", CommandOptionType.SingleValue);
            app.Option("--updateurl", $"Url used for once a day new release version check. Check performed only if value is not empty (default: empty)", CommandOptionType.SingleValue);
            app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue);
            app.Option("--debugloglevel", "The severity you log (default:information)", CommandOptionType.SingleValue);
            app.Option("--disable-registration", "Disables new user registrations (default:true)", CommandOptionType.SingleValue);
            app.Option("--plugin-remote", "Which github repository to fetch the available plugins list (default:btcpayserver/btcpayserver-plugins)", CommandOptionType.SingleValue);
            app.Option("--recommended-plugins", "Plugins which would be marked as recommended to be installed. Separated by newline or space", CommandOptionType.MultipleValue);
            app.Option("--xforwardedproto", "If specified, set X-Forwarded-Proto to the specified value, this may be useful if your reverse proxy handle https but is not configured to add X-Forwarded-Proto (example: --xforwardedproto https)", CommandOptionType.SingleValue);
            app.Option("--cheatmode", "Add some helper UI to facilitate dev-time testing (Default false)", CommandOptionType.BoolValue);

            app.Option("--explorerpostgres", $"Connection string to the postgres database of NBXplorer. (optional, used for dashboard and reporting features)", CommandOptionType.SingleValue);
            foreach (var network in provider.GetAll().OfType <BTCPayNetwork>())
            {
                var crypto = network.CryptoCode.ToLowerInvariant();
                app.Option($"--{crypto}explorerurl", $"URL of the NBXplorer for {network.CryptoCode} (default: {network.NBXplorerNetwork.DefaultSettings.DefaultUrl})", CommandOptionType.SingleValue);
                app.Option($"--{crypto}explorercookiefile", $"Path to the cookie file (default: {network.NBXplorerNetwork.DefaultSettings.DefaultCookieFile})", CommandOptionType.SingleValue);
                app.Option($"--{crypto}lightning", $"Easy configuration of lightning for the server administrator: Must be a UNIX socket of c-lightning (lightning-rpc) or URL to a charge server (default: empty)", CommandOptionType.SingleValue);
                if (network.SupportLightning)
                {
                    app.Option($"--{crypto}externallndgrpc", $"The LND gRPC configuration BTCPay will expose to easily connect to the internal lnd wallet from an external wallet (default: empty)", CommandOptionType.SingleValue);
                    app.Option($"--{crypto}externallndrest", $"The LND REST configuration BTCPay will expose to easily connect to the internal lnd wallet from an external wallet (default: empty)", CommandOptionType.SingleValue);
                    app.Option($"--{crypto}externalrtl", $"The Ride the Lightning configuration so BTCPay will expose to easily open it in server settings (default: empty)", CommandOptionType.SingleValue);
                    app.Option($"--{crypto}externalspark", $"Show spark information in Server settings / Server. The connection string to spark server (default: empty)", CommandOptionType.SingleValue);
                    app.Option($"--{crypto}externalcharge", $"Show lightning charge information in Server settings/Server. The connection string to charge server (default: empty)", CommandOptionType.SingleValue);
                }
            }
            return(app);
        }
Esempio n. 6
0
        private void AddPaymentMethods(StoreData store, StoreBlob storeBlob, StoreViewModel vm)
        {
            var excludeFilters         = storeBlob.GetExcludedPaymentMethods();
            var derivationByCryptoCode =
                store
                .GetSupportedPaymentMethods(_NetworkProvider)
                .OfType <DerivationStrategy>()
                .ToDictionary(c => c.Network.CryptoCode);

            foreach (var network in _NetworkProvider.GetAll())
            {
                var strategy = derivationByCryptoCode.TryGet(network.CryptoCode);
                vm.DerivationSchemes.Add(new StoreViewModel.DerivationScheme()
                {
                    Crypto   = network.CryptoCode,
                    Value    = strategy?.DerivationStrategyBase?.ToString() ?? string.Empty,
                    WalletId = new WalletId(store.Id, network.CryptoCode),
                    Enabled  = !excludeFilters.Match(new Payments.PaymentMethodId(network.CryptoCode, Payments.PaymentTypes.BTCLike))
                });
            }

            var lightningByCryptoCode = store
                                        .GetSupportedPaymentMethods(_NetworkProvider)
                                        .OfType <Payments.Lightning.LightningSupportedPaymentMethod>()
                                        .ToDictionary(c => c.CryptoCode);

            foreach (var network in _NetworkProvider.GetAll())
            {
                var lightning = lightningByCryptoCode.TryGet(network.CryptoCode);
                var paymentId = new Payments.PaymentMethodId(network.CryptoCode, Payments.PaymentTypes.LightningLike);
                vm.LightningNodes.Add(new StoreViewModel.LightningNode()
                {
                    CryptoCode = network.CryptoCode,
                    Address    = lightning?.GetLightningUrl()?.BaseUri.AbsoluteUri ?? string.Empty,
                    Enabled    = !excludeFilters.Match(paymentId)
                });
            }


            var changellyEnabled = storeBlob.ChangellySettings != null && storeBlob.ChangellySettings.Enabled;

            vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.ThirdPartyPaymentMethod()
            {
                Enabled  = changellyEnabled,
                Action   = nameof(UpdateChangellySettings),
                Provider = "Changelly"
            });

            var coinSwitchEnabled = storeBlob.CoinSwitchSettings != null && storeBlob.CoinSwitchSettings.Enabled;

            vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.ThirdPartyPaymentMethod()
            {
                Enabled  = coinSwitchEnabled,
                Action   = nameof(UpdateCoinSwitchSettings),
                Provider = "CoinSwitch"
            });
        }
Esempio n. 7
0
        public RateRules GetDefaultRateRules(BTCPayNetworkProvider networkProvider)
        {
            StringBuilder builder = new StringBuilder();

            foreach (var network in networkProvider.GetAll())
            {
                if (network.DefaultRateRules.Length != 0)
                {
                    builder.AppendLine($"// Default rate rules for {network.CryptoCode}");
                    foreach (var line in network.DefaultRateRules)
                    {
                        builder.AppendLine(line);
                    }
                    builder.AppendLine($"////////");
                    builder.AppendLine();
                }
            }

            var preferredExchange = string.IsNullOrEmpty(PreferredExchange) ? CoinGeckoRateProvider.CoinGeckoName : PreferredExchange;

            builder.AppendLine($"X_X = {preferredExchange}(X_X);");

            BTCPayServer.Rating.RateRules.TryParse(builder.ToString(), out var rules);
            rules.Spread = Spread;
            return(rules);
        }
 public IEnumerable <PaymentMethodId> GetSupportedPaymentMethods()
 {
     return(_btcPayNetworkProvider.GetAll().OfType <BTCPayNetwork>()
            .Where(network => network.SupportLightning)
            .Select(network =>
                    new PaymentMethodId(network.CryptoCode, LightningPaymentType.Instance)));
 }
Esempio n. 9
0
 public IEnumerable <PaymentMethodId> GetSupportedPaymentMethods()
 {
     return(_btcPayNetworkProvider.GetAll().OfType <BTCPayNetwork>()
            .Where(network => !network.ReadonlyWallet && network.WalletSupported)
            .Select(network =>
                    new PaymentMethodId(network.CryptoCode, BitcoinPaymentType.Instance)));
 }
Esempio n. 10
0
        public void Configure(IConfiguration configuration, BTCPayNetworkProvider btcPayNetworkProvider)
        {
            foreach (var net in btcPayNetworkProvider.GetAll().OfType <BTCPayNetwork>())
            {
                ExternalServices.Load(net.CryptoCode, configuration);
            }

            ExternalServices.LoadNonCryptoServices(configuration);

            var services = configuration.GetOrDefault <string>("externalservices", null);

            if (services != null)
            {
                foreach (var service in services.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)
                         .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))
                    {
                        OtherExternalServices.AddOrReplace(service.Name, uri);
                    }
                }
            }
        }
 public override IEnumerable <PaymentMethodId> GetSupportedPaymentMethods()
 {
     return(_networkProvider
            .GetAll()
            .OfType <BTCPayNetwork>()
            .Select(network => new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike)));
 }
        protected override CommandLineApplication CreateCommandLineApplicationCore()
        {
            var provider = new BTCPayNetworkProvider(NetworkType.Mainnet);
            var chains   = string.Join(",", provider.GetAll().Select(n => n.bitcoinCode.ToLowerInvariant()).ToArray());
            CommandLineApplication app = new CommandLineApplication(true)
            {
                FullName = "BTCPay\r\nOpen source, self-hosted payment processor.",
                Name     = "BTCPay"
            };

            app.HelpOption("-? | -h | --help");
            app.Option("-n | --network", $"Set the network among (mainnet,testnet,regtest) (default: mainnet)", CommandOptionType.SingleValue);
            app.Option("--testnet | -testnet", $"Use testnet (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--regtest | -regtest", $"Use regtest (deprecated, use --network instead)", CommandOptionType.BoolValue);
            app.Option("--allow-admin-registration", $"For debug only, will show a checkbox when a new user register to add himself as admin. (default: false)", CommandOptionType.BoolValue);
            app.Option("--chains | -c", $"Chains to support as a comma separated (default: btc; available: {chains})", CommandOptionType.SingleValue);
            app.Option("--postgres", $"Connection string to a PostgreSQL database (default: SQLite)", CommandOptionType.SingleValue);
            app.Option("--mysql", $"Connection string to a MySQL database (default: SQLite)", CommandOptionType.SingleValue);
            app.Option("--externalservices", $"Links added to external services inside Server Settings / Services under the format service1:path2;service2:path2.(default: empty)", CommandOptionType.SingleValue);
            app.Option("--bundlejscss", $"Bundle JavaScript and CSS files for better performance (default: true)", CommandOptionType.SingleValue);
            app.Option("--rootpath", "The root path in the URL to access BTCPay (default: /)", CommandOptionType.SingleValue);
            app.Option("--sshconnection", "SSH server to manage BTCPay under the form user@server:port (default: root@externalhost or empty)", CommandOptionType.SingleValue);
            app.Option("--sshpassword", "SSH password to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshkeyfile", "SSH private key file to manage BTCPay (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshkeyfilepassword", "Password of the SSH keyfile (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshauthorizedkeys", "Path to a authorized_keys file that BTCPayServer can modify from the website (default: empty)", CommandOptionType.SingleValue);
            app.Option("--sshtrustedfingerprints", "SSH Host public key fingerprint or sha256 (default: empty, it will allow untrusted connections)", CommandOptionType.SingleValue);
            app.Option("--torrcfile", "Path to torrc file containing hidden services directories (default: empty)", CommandOptionType.SingleValue);
            app.Option("--socksendpoint", "Socks endpoint to connect to onion urls (default: empty)", CommandOptionType.SingleValue);
            app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue);
            app.Option("--debugloglevel", "The severity you log (default:information)", CommandOptionType.SingleValue);
            app.Option("--disable-registration", "Disables new user registrations (default:true)", CommandOptionType.SingleValue);
            app.Option("--xforwardedproto", "If specified, set X-Forwarded-Proto to the specified value, this may be useful if your reverse proxy handle https but is not configured to add X-Forwarded-Proto (example: --xforwardedproto https)", CommandOptionType.SingleValue);
            foreach (var network in provider.GetAll().OfType <BTCPayNetwork>())
            {
                var bitcoin = network.bitcoinCode.ToLowerInvariant();
                app.Option($"--{bitcoin}explorerurl", $"URL of the NBXplorer for {network.bitcoinCode} (default: {network.NBXplorerNetwork.DefaultSettings.DefaultUrl})", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}explorercookiefile", $"Path to the cookie file (default: {network.NBXplorerNetwork.DefaultSettings.DefaultCookieFile})", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}lightning", $"Easy configuration of lightning for the server administrator: Must be a UNIX socket of c-lightning (lightning-rpc) or URL to a charge server (default: empty)", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}externallndgrpc", $"The LND gRPC configuration BTCPay will expose to easily connect to the internal lnd wallet from an external wallet (default: empty)", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}externallndrest", $"The LND REST configuration BTCPay will expose to easily connect to the internal lnd wallet from an external wallet (default: empty)", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}externalrtl", $"The Ride the Lightning configuration so BTCPay will expose to easily open it in server settings (default: empty)", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}externalspark", $"Show spark information in Server settings / Server. The connection string to spark server (default: empty)", CommandOptionType.SingleValue);
                app.Option($"--{bitcoin}externalcharge", $"Show lightning charge information in Server settings/Server. The connection string to charge server (default: empty)", CommandOptionType.SingleValue);
            }
            return(app);
        }
 public override IEnumerable <PaymentMethodId> GetSupportedPaymentMethods()
 {
     return(_networkProvider
            .GetAll()
            .OfType <BTCPayNetwork>()
            .Where(network => network.NBitcoinNetwork.Consensus.SupportSegwit)
            .Select(network => new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike)));
 }
        public void LoadArgs(IConfiguration conf)
        {
            NetworkType = DefaultConfiguration.GetNetworkType(conf);
            var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType);

            DataDir = conf.GetOrDefault <string>("datadir", defaultSettings.DefaultDataDirectory);
            Logs.Configuration.LogInformation("Network: " + NetworkType.ToString());

            var supportedChains = conf.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());

            NetworkProvider = new BTCPayNetworkProvider(NetworkType).Filter(supportedChains.ToArray());
            foreach (var chain in supportedChains)
            {
                if (NetworkProvider.GetNetwork(chain) == null)
                {
                    throw new ConfigException($"Invalid chains \"{chain}\"");
                }
            }

            var validChains = new List <string>();

            foreach (var net in NetworkProvider.GetAll())
            {
                NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
                setting.CryptoCode  = net.CryptoCode;
                setting.ExplorerUri = conf.GetOrDefault <Uri>($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl);
                setting.CookieFile  = conf.GetOrDefault <string>($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
                NBXplorerConnectionSettings.Add(setting);

                {
                    var lightning = conf.GetOrDefault <string>($"{net.CryptoCode}.lightning", string.Empty);
                    if (lightning.Length != 0)
                    {
                        if (!LightningConnectionString.TryParse(lightning, true, out var connectionString, out var error))
                        {
                            Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.lightning, " + 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:[email protected];macaroon=abf239...;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                          $"              lnd server: 'type=lnd-rest;server=https://lnd:[email protected];macaroonfilepath=/root/.lnd/admin.macaroon;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                          $"Error: {error}" + Environment.NewLine +
                                                          "This service will not be exposed through BTCPay Server");
                        }
                        else
                        {
                            if (connectionString.IsLegacy)
                            {
                                Logs.Configuration.LogWarning($"Setting {net.CryptoCode}.lightning is a deprecated format, it will work now, but please replace it for future versions with '{connectionString.ToString()}'");
                            }
                            InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString);
                        }
                    }
                }

                ExternalServices.Load(net.CryptoCode, conf);
            }
        public void LoadArgs(IConfiguration conf)
        {
            ChainType = DefaultConfiguration.GetChainType(conf);
            var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainType);

            DataDir = conf.GetOrDefault <string>("datadir", defaultSettings.DefaultDataDirectory);
            Logs.Configuration.LogInformation("Network: " + ChainType.ToString());

            var supportedChains = conf.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());

            NetworkProvider = new BTCPayNetworkProvider(ChainType).Filter(supportedChains.ToArray());
            foreach (var chain in supportedChains)
            {
                if (NetworkProvider.GetNetwork(chain) == null)
                {
                    throw new ConfigException($"Invalid chains \"{chain}\"");
                }
            }

            var validChains = new List <string>();

            foreach (var net in NetworkProvider.GetAll())
            {
                NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
                setting.CryptoCode  = net.CryptoCode;
                setting.ExplorerUri = conf.GetOrDefault <Uri>($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl);
                setting.CookieFile  = conf.GetOrDefault <string>($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
                NBXplorerConnectionSettings.Add(setting);
                var lightning = conf.GetOrDefault <string>($"{net.CryptoCode}.lightning", string.Empty);
                if (lightning.Length != 0)
                {
                    if (!LightningConnectionString.TryParse(lightning, out var connectionString, out var error))
                    {
                        throw new ConfigException($"Invalid setting {net.CryptoCode}.lightning, you need to pass either " +
                                                  $"the absolute path to the unix socket of a running CLightning instance (eg. /root/.lightning/lightning-rpc), " +
                                                  $"or the url to a charge server with crendetials (eg. https://apitoken@API_TOKEN_SECRET:charge.example.com/)");
                    }
                    InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString);
                }
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));

            PostgresConnectionString = conf.GetOrDefault <string>("postgres", null);
            BundleJsCss = conf.GetOrDefault <bool>("bundlejscss", true);
            ExternalUrl = conf.GetOrDefault <Uri>("externalurl", null);
            var old = conf.GetOrDefault <Uri>("internallightningnode", null);

            if (old != null)
            {
                throw new ConfigException($"internallightningnode should not be used anymore, use btclightning instead");
            }
        }
Esempio n. 16
0
        public override async Task StartAsync(CancellationToken cancellationToken)
        {
            var chainIds = _btcPayNetworkProvider.GetAll().OfType <EthereumBTCPayNetwork>()
                           .Select(network => network.ChainId).Distinct().ToList();

            if (!chainIds.Any())
            {
                return;
            }

            await base.StartAsync(cancellationToken);

            _ = Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    _eventAggregator.Publish(new CheckWatchers());
                    await Task.Delay(IsAllAvailable()? TimeSpan.FromDays(1): TimeSpan.FromSeconds(5), cancellationToken);
                }
            }, cancellationToken);
        }
Esempio n. 17
0
        public static void SetLinkOnNetworks(List <PoliciesSettings.BlockExplorerOverrideItem> links,
                                             BTCPayNetworkProvider networkProvider)
        {
            var networks = networkProvider.GetAll();

            foreach (var network in networks)
            {
                var overrideLink = links.SingleOrDefault(item =>
                                                         item.CryptoCode.Equals(network.CryptoCode, StringComparison.InvariantCultureIgnoreCase));
                network.BlockExplorerLink = overrideLink?.Link ?? network.BlockExplorerLinkDefault;
            }
        }
        public void SetCryptoCurrencies(BTCPayNetworkProvider networkProvider, string selectedScheme)
        {
            var choices = networkProvider.GetAll()
                          .Where(n => n.CLightningNetworkName != null)
                          .Select(o => new Format()
            {
                Name = o.CryptoCode, Value = o.CryptoCode
            }).ToArray();
            var chosen = choices.FirstOrDefault(f => f.Name == selectedScheme) ?? choices.FirstOrDefault();

            CryptoCurrencies = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Name), chosen);
            CryptoCurrency   = chosen.Name;
        }
 public void Configure(IConfiguration conf, BTCPayNetworkProvider provider)
 {
     foreach (BTCPayNetwork btcPayNetwork in provider.GetAll().OfType <BTCPayNetwork>())
     {
         NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
         setting.CryptoCode  = btcPayNetwork.CryptoCode;
         setting.ExplorerUri = conf.GetOrDefault <Uri>($"{btcPayNetwork.CryptoCode}.explorer.url",
                                                       btcPayNetwork.NBXplorerNetwork.DefaultSettings.DefaultUrl);
         setting.CookieFile = conf.GetOrDefault <string>($"{btcPayNetwork.CryptoCode}.explorer.cookiefile",
                                                         btcPayNetwork.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
         NBXplorerConnectionSettings.Add(setting);
     }
 }
Esempio n. 20
0
 public BTCPayNetworkJsonSerializerSettings(BTCPayNetworkProvider networkProvider, IEnumerable <IJsonConverterRegistration> jsonSerializers)
 {
     foreach (var network in networkProvider.GetAll().OfType <BTCPayNetwork>())
     {
         var serializer = new JsonSerializerSettings();
         foreach (var jsonSerializer in jsonSerializers)
         {
             serializer.Converters.Add(jsonSerializer.CreateJsonConverter(network));
         }
         foreach (var converter in network.NBXplorerNetwork.JsonSerializerSettings.Converters)
         {
             serializer.Converters.Add(converter);
         }
         _Serializers.Add(network.CryptoCode, serializer);
     }
 }
Esempio n. 21
0
        public BitcoinLikePaymentHandler(ExplorerClientProvider provider,
                                         BTCPayNetworkProvider networkProvider,
                                         IFeeProviderFactory feeRateProviderFactory,
                                         NBXplorerDashboard dashboard,
                                         Services.Wallets.BTCPayWalletProvider walletProvider)
        {
            _ExplorerProvider       = provider;
            _networkProvider        = networkProvider;
            _FeeRateProviderFactory = feeRateProviderFactory;
            _dashboard      = dashboard;
            _WalletProvider = walletProvider;

            _bech32Prefix = networkProvider.GetAll().OfType <BTCPayNetwork>()
                            .Where(network => network.NBitcoinNetwork?.Consensus?.SupportSegwit is true).ToDictionary(network => network.CryptoCode,
                                                                                                                      network => Encoders.ASCII.EncodeData(
                                                                                                                          network.NBitcoinNetwork.GetBech32Encoder(Bech32Type.WITNESS_PUBKEY_ADDRESS, false)
                                                                                                                          .HumanReadablePart));
        }
Esempio n. 22
0
        public BTCPayWalletProvider(ExplorerClientProvider client,
                                    IOptions <MemoryCacheOptions> memoryCacheOption,
                                    BTCPayNetworkProvider networkProvider)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            _Client          = client;
            _NetworkProvider = networkProvider;
            _Options         = memoryCacheOption;

            foreach (var network in networkProvider.GetAll())
            {
                var explorerClient = _Client.GetExplorerClient(network.CryptoCode);
                if (explorerClient == null)
                {
                    continue;
                }
                _Wallets.Add(network.CryptoCode, new BTCPayWallet(explorerClient, new MemoryCache(_Options), network));
            }
        }
        public void LoadArgs(IConfiguration conf)
        {
            ChainType = DefaultConfiguration.GetChainType(conf);
            var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainType);

            DataDir = conf.GetOrDefault <string>("datadir", defaultSettings.DefaultDataDirectory);
            Logs.Configuration.LogInformation("Network: " + ChainType.ToString());

            var supportedChains = conf.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());

            NetworkProvider = new BTCPayNetworkProvider(ChainType).Filter(supportedChains.ToArray());
            foreach (var chain in supportedChains)
            {
                if (NetworkProvider.GetNetwork(chain) == null)
                {
                    throw new ConfigException($"Invalid chains \"{chain}\"");
                }
            }

            var validChains = new List <string>();

            foreach (var net in NetworkProvider.GetAll())
            {
                NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
                setting.CryptoCode  = net.CryptoCode;
                setting.ExplorerUri = conf.GetOrDefault <Uri>($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl);
                setting.CookieFile  = conf.GetOrDefault <string>($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
                NBXplorerConnectionSettings.Add(setting);
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));

            PostgresConnectionString = conf.GetOrDefault <string>("postgres", null);
            BundleJsCss           = conf.GetOrDefault <bool>("bundlejscss", true);
            ExternalUrl           = conf.GetOrDefault <Uri>("externalurl", null);
            InternalLightningNode = conf.GetOrDefault <Uri>("internallightningnode", null);
        }
        public BTCPayWalletProvider(ExplorerClientProvider client,
                                    IOptions <MemoryCacheOptions> memoryCacheOption,
                                    Data.ApplicationDbContextFactory dbContextFactory,
                                    BTCPayNetworkProvider networkProvider,
                                    Logs logs)
        {
            ArgumentNullException.ThrowIfNull(client);
            this.Logs        = logs;
            _Client          = client;
            _NetworkProvider = networkProvider;
            _Options         = memoryCacheOption;

            foreach (var network in networkProvider.GetAll().OfType <BTCPayNetwork>())
            {
                var explorerClient = _Client.GetExplorerClient(network.CryptoCode);
                if (explorerClient == null)
                {
                    continue;
                }
                _Wallets.Add(network.CryptoCode.ToUpperInvariant(), new BTCPayWallet(explorerClient, new MemoryCache(_Options), network, dbContextFactory, Logs));
            }
        }
Esempio n. 25
0
        public void Configure(IConfiguration conf, BTCPayNetworkProvider networkProvider)
        {
            foreach (var net in networkProvider.GetAll().OfType <BTCPayNetwork>())
            {
                var lightning = conf.GetOrDefault <string>($"{net.CryptoCode}.lightning", string.Empty);
                if (lightning.Length != 0)
                {
                    if (!LightningConnectionString.TryParse(lightning, true, out var connectionString,
                                                            out var error))
                    {
                        Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.lightning, " +
                                                      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:[email protected];macaroon=abf239...;certthumbprint=2abdf302...'" +
                                                      Environment.NewLine +
                                                      $"              lnd server: 'type=lnd-rest;server=https://lnd:[email protected];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
                    {
                        if (connectionString.IsLegacy)
                        {
                            Logs.Configuration.LogWarning(
                                $"Setting {net.CryptoCode}.lightning is a deprecated format, it will work now, but please replace it for future versions with '{connectionString.ToString()}'");
                        }

                        InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString);
                    }
                }
            }
Esempio n. 26
0
        public BTCPayWalletProvider(ExplorerClientProvider client,
                                    IOptions <MemoryCacheOptions> memoryCacheOption,
                                    Data.ApplicationDbContextFactory dbContextFactory,
                                    BTCPayNetworkProvider networkProvider)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            _Client          = client;
            _NetworkProvider = networkProvider;
            _Options         = memoryCacheOption;

            foreach (var network in networkProvider.GetAll().OfType <BTCPayNetwork>())
            {
                var explorerClient = _Client.GetExplorerClient(network.bitcoinCode);
                if (explorerClient == null)
                {
                    continue;
                }
                _Wallets.Add(network.bitcoinCode.ToUpperInvariant(), new BTCPayWallet(explorerClient, new MemoryCache(_Options), network, dbContextFactory));
            }
        }
        public void LoadArgs(IConfiguration conf)
        {
            NetworkType = DefaultConfiguration.GetNetworkType(conf);
            var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType);

            DataDir = conf.GetOrDefault <string>("datadir", defaultSettings.DefaultDataDirectory);
            Logs.Configuration.LogInformation("Network: " + NetworkType.ToString());

            var supportedChains = conf.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());

            NetworkProvider = new BTCPayNetworkProvider(NetworkType).Filter(supportedChains.ToArray());
            foreach (var chain in supportedChains)
            {
                if (NetworkProvider.GetNetwork(chain) == null)
                {
                    throw new ConfigException($"Invalid chains \"{chain}\"");
                }
            }

            var validChains = new List <string>();

            foreach (var net in NetworkProvider.GetAll())
            {
                NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
                setting.CryptoCode  = net.CryptoCode;
                setting.ExplorerUri = conf.GetOrDefault <Uri>($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl);
                setting.CookieFile  = conf.GetOrDefault <string>($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
                NBXplorerConnectionSettings.Add(setting);
                var lightning = conf.GetOrDefault <string>($"{net.CryptoCode}.lightning", string.Empty);
                if (lightning.Length != 0)
                {
                    if (!LightningConnectionString.TryParse(lightning, true, out var connectionString, out var error))
                    {
                        throw new ConfigException($"Invalid setting {net.CryptoCode}.lightning, " + Environment.NewLine +
                                                  $"If you have a 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:[email protected];macaron=abf239...;certthumbprint=2abdf302...'");
                    }
                    if (connectionString.IsLegacy)
                    {
                        Logs.Configuration.LogWarning($"Setting {net.CryptoCode}.lightning will work but use an deprecated format, please replace it by '{connectionString.ToString()}'");
                    }
                    InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString);
                }
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));

            PostgresConnectionString = conf.GetOrDefault <string>("postgres", null);
            BundleJsCss = conf.GetOrDefault <bool>("bundlejscss", true);
            ExternalUrl = conf.GetOrDefault <Uri>("externalurl", null);

            RootPath = conf.GetOrDefault <string>("rootpath", "/");
            if (!RootPath.StartsWith("/", StringComparison.InvariantCultureIgnoreCase))
            {
                RootPath = "/" + RootPath;
            }
            var old = conf.GetOrDefault <Uri>("internallightningnode", null);

            if (old != null)
            {
                throw new ConfigException($"internallightningnode should not be used anymore, use btclightning instead");
            }
        }
        public void LoadArgs(IConfiguration conf)
        {
            NetworkType = DefaultConfiguration.GetNetworkType(conf);
            var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType);

            DataDir = conf.GetOrDefault <string>("datadir", defaultSettings.DefaultDataDirectory);
            Logs.Configuration.LogInformation("Network: " + NetworkType.ToString());

            var supportedChains = conf.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant());

            NetworkProvider = new BTCPayNetworkProvider(NetworkType).Filter(supportedChains.ToArray());
            foreach (var chain in supportedChains)
            {
                if (NetworkProvider.GetNetwork(chain) == null)
                {
                    throw new ConfigException($"Invalid chains \"{chain}\"");
                }
            }

            var validChains = new List <string>();

            foreach (var net in NetworkProvider.GetAll())
            {
                NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
                setting.CryptoCode  = net.CryptoCode;
                setting.ExplorerUri = conf.GetOrDefault <Uri>($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl);
                setting.CookieFile  = conf.GetOrDefault <string>($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
                NBXplorerConnectionSettings.Add(setting);

                {
                    var lightning = conf.GetOrDefault <string>($"{net.CryptoCode}.lightning", string.Empty);
                    if (lightning.Length != 0)
                    {
                        if (!LightningConnectionString.TryParse(lightning, true, out var connectionString, out var error))
                        {
                            throw new ConfigException($"Invalid setting {net.CryptoCode}.lightning, " + Environment.NewLine +
                                                      $"If you have a 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:[email protected];macaroon=abf239...;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                      $"              lnd server: 'type=lnd-rest;server=https://lnd:[email protected];macaroonfilepath=/root/.lnd/admin.macaroon;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                      error);
                        }
                        if (connectionString.IsLegacy)
                        {
                            Logs.Configuration.LogWarning($"Setting {net.CryptoCode}.lightning will work but use an deprecated format, please replace it by '{connectionString.ToString()}'");
                        }
                        InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString);
                    }
                }

                void externalLnd <T>(string code, string lndType)
                {
                    var lightning = conf.GetOrDefault <string>(code, string.Empty);

                    if (lightning.Length != 0)
                    {
                        if (!LightningConnectionString.TryParse(lightning, false, out var connectionString, out var error))
                        {
                            throw new ConfigException($"Invalid setting {code}, " + Environment.NewLine +
                                                      $"lnd server: 'type={lndType};server=https://lnd.example.com;macaroon=abf239...;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                      $"lnd server: 'type={lndType};server=https://lnd.example.com;macaroonfilepath=/root/.lnd/admin.macaroon;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                      error);
                        }
                        var instanceType = typeof(T);
                        ExternalServicesByCryptoCode.Add(net.CryptoCode, (ExternalService)Activator.CreateInstance(instanceType, connectionString));
                    }
                };

                externalLnd <ExternalLndGrpc>($"{net.CryptoCode}.external.lnd.grpc", "lnd-grpc");
                externalLnd <ExternalLndRest>($"{net.CryptoCode}.external.lnd.rest", "lnd-rest");
            }

            Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));

            PostgresConnectionString = conf.GetOrDefault <string>("postgres", null);
            MySQLConnectionString    = conf.GetOrDefault <string>("mysql", null);
            BundleJsCss = conf.GetOrDefault <bool>("bundlejscss", true);
            ExternalUrl = conf.GetOrDefault <Uri>("externalurl", null);

            var sshSettings = ParseSSHConfiguration(conf);

            if ((!string.IsNullOrEmpty(sshSettings.Password) || !string.IsNullOrEmpty(sshSettings.KeyFile)) && !string.IsNullOrEmpty(sshSettings.Server))
            {
                int waitTime = 0;
                while (!string.IsNullOrEmpty(sshSettings.KeyFile) && !File.Exists(sshSettings.KeyFile))
                {
                    if (waitTime++ < 5)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                    else
                    {
                        throw new ConfigException($"sshkeyfile does not exist");
                    }
                }

                if (sshSettings.Port > ushort.MaxValue ||
                    sshSettings.Port < ushort.MinValue)
                {
                    throw new ConfigException($"ssh port is invalid");
                }
                if (!string.IsNullOrEmpty(sshSettings.Password) && !string.IsNullOrEmpty(sshSettings.KeyFile))
                {
                    throw new ConfigException($"sshpassword or sshkeyfile should be provided, but not both");
                }
                try
                {
                    sshSettings.CreateConnectionInfo();
                }
                catch
                {
                    throw new ConfigException($"sshkeyfilepassword is invalid");
                }
                SSHSettings = sshSettings;
            }

            var fingerPrints = conf.GetOrDefault <string>("sshtrustedfingerprints", "");

            if (!string.IsNullOrEmpty(fingerPrints))
            {
                foreach (var fingerprint in fingerPrints.Split(';', StringSplitOptions.RemoveEmptyEntries))
                {
                    if (!SSHFingerprint.TryParse(fingerprint, out var f))
                    {
                        throw new ConfigException($"Invalid ssh fingerprint format {fingerprint}");
                    }
                    TrustedFingerprints.Add(f);
                }
            }

            RootPath = conf.GetOrDefault <string>("rootpath", "/");
            if (!RootPath.StartsWith("/", StringComparison.InvariantCultureIgnoreCase))
            {
                RootPath = "/" + RootPath;
            }
            var old = conf.GetOrDefault <Uri>("internallightningnode", null);

            if (old != null)
            {
                throw new ConfigException($"internallightningnode should not be used anymore, use btclightning instead");
            }

            LogFile = GetDebugLog(conf);
            if (!string.IsNullOrEmpty(LogFile))
            {
                Logs.Configuration.LogInformation("LogFile: " + LogFile);
                Logs.Configuration.LogInformation("Log Level: " + GetDebugLogLevel(conf));
            }
        }
 public override IEnumerable <PaymentMethodId> GetSupportedPaymentMethods()
 {
     return(_networkProvider.GetAll()
            .Where(network => network is MoneroLikeSpecificBtcPayNetwork)
            .Select(network => new PaymentMethodId(network.CryptoCode, PaymentType)));
 }
        public void LoadArgs(IConfiguration conf)
        {
            NetworkType = DefaultConfiguration.GetNetworkType(conf);
            DataDir     = conf.GetDataDir(NetworkType);
            Logs.Configuration.LogInformation("Network: " + NetworkType.ToString());

            if (conf.GetOrDefault <bool>("launchsettings", false) && NetworkType != NetworkType.Regtest)
            {
                throw new ConfigException($"You need to run BTCPayServer with the run.sh or run.ps1 script");
            }

            var supportedChains = conf.GetOrDefault <string>("chains", "btc")
                                  .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                  .Select(t => t.ToUpperInvariant()).ToHashSet();

            var networkProvider = new BTCPayNetworkProvider(NetworkType);
            var filtered        = networkProvider.Filter(supportedChains.ToArray());
            var elementsBased   = filtered.GetAll().OfType <ElementsBTCPayNetwork>();
            var parentChains    = elementsBased.Select(network => network.NetworkCryptoCode.ToUpperInvariant()).Distinct();
            var allSubChains    = networkProvider.GetAll().OfType <ElementsBTCPayNetwork>()
                                  .Where(network => parentChains.Contains(network.NetworkCryptoCode)).Select(network => network.CryptoCode.ToUpperInvariant());

            supportedChains.AddRange(allSubChains);
            NetworkProvider = networkProvider.Filter(supportedChains.ToArray());
            foreach (var chain in supportedChains)
            {
                if (NetworkProvider.GetNetwork <BTCPayNetworkBase>(chain) == null)
                {
                    throw new ConfigException($"Invalid chains \"{chain}\"");
                }
            }

            var validChains = new List <string>();

            foreach (var net in NetworkProvider.GetAll().OfType <BTCPayNetwork>())
            {
                NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting();
                setting.CryptoCode  = net.CryptoCode;
                setting.ExplorerUri = conf.GetOrDefault <Uri>($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl);
                setting.CookieFile  = conf.GetOrDefault <string>($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile);
                NBXplorerConnectionSettings.Add(setting);

                {
                    var lightning = conf.GetOrDefault <string>($"{net.CryptoCode}.lightning", string.Empty);
                    if (lightning.Length != 0)
                    {
                        if (!LightningConnectionString.TryParse(lightning, true, out var connectionString, out var error))
                        {
                            Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.lightning, " + 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:[email protected];macaroon=abf239...;certthumbprint=2abdf302...'" + Environment.NewLine +
                                                          $"              lnd server: 'type=lnd-rest;server=https://lnd:[email protected];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
                        {
                            if (connectionString.IsLegacy)
                            {
                                Logs.Configuration.LogWarning($"Setting {net.CryptoCode}.lightning is a deprecated format, it will work now, but please replace it for future versions with '{connectionString.ToString()}'");
                            }
                            InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString);
                        }
                    }
                }

                ExternalServices.Load(net.CryptoCode, conf);
            }