using BTCPayServer.Logging; using System.Linq; using Microsoft.Extensions.Logging; using NBitcoin; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; using StandardConfiguration; using Microsoft.Extensions.Configuration; using NBXplorer; namespace BTCPayServer.Configuration { public class NBXplorerConnectionSetting { public string CryptoCode { get; internal set; } public Uri ExplorerUri { get; internal set; } public string CookieFile { get; internal set; } } public class BTCPayServerOptions { public ChainType ChainType { get; set; } public string ConfigurationFile { get; private set; } public string DataDir { get; private set; } public List Listen { get; set; } public List NBXplorerConnectionSettings { get; set; } = new List(); public void LoadArgs(IConfiguration conf) { ChainType = DefaultConfiguration.GetChainType(conf); var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainType); DataDir = conf.GetOrDefault("datadir", defaultSettings.DefaultDataDirectory); Logs.Configuration.LogInformation("Network: " + ChainType.ToString()); var supportedChains = conf.GetOrDefault("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(); foreach (var net in NetworkProvider.GetAll()) { NBXplorerConnectionSetting setting = new NBXplorerConnectionSetting(); setting.CryptoCode = net.CryptoCode; setting.ExplorerUri = conf.GetOrDefault($"{net.CryptoCode}.explorer.url", net.NBXplorerNetwork.DefaultSettings.DefaultUrl); setting.CookieFile = conf.GetOrDefault($"{net.CryptoCode}.explorer.cookiefile", net.NBXplorerNetwork.DefaultSettings.DefaultCookieFile); NBXplorerConnectionSettings.Add(setting); } Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray())); PostgresConnectionString = conf.GetOrDefault("postgres", null); BundleJsCss = conf.GetOrDefault("bundlejscss", true); ExternalUrl = conf.GetOrDefault("externalurl", null); InternalLightningNode = conf.GetOrDefault("internallightningnode", null); } public Uri InternalLightningNode { get; set; } public BTCPayNetworkProvider NetworkProvider { get; set; } public string PostgresConnectionString { get; set; } public Uri ExternalUrl { get; set; } public bool BundleJsCss { get; set; } } }