2017-09-13 08:47:34 +02:00
|
|
|
|
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;
|
2017-09-22 18:31:29 +02:00
|
|
|
|
using StandardConfiguration;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2018-01-07 18:36:41 +01:00
|
|
|
|
using NBXplorer;
|
2018-03-20 18:09:25 +01:00
|
|
|
|
using BTCPayServer.Payments.Lightning;
|
2017-09-13 08:47:34 +02:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Configuration
|
|
|
|
|
{
|
2018-01-12 08:00:31 +01:00
|
|
|
|
public class NBXplorerConnectionSetting
|
|
|
|
|
{
|
|
|
|
|
public string CryptoCode { get; internal set; }
|
|
|
|
|
public Uri ExplorerUri { get; internal set; }
|
|
|
|
|
public string CookieFile { get; internal set; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 10:53:04 +02:00
|
|
|
|
public class BTCPayServerOptions
|
|
|
|
|
{
|
2018-01-11 14:52:28 +01:00
|
|
|
|
public ChainType ChainType
|
2017-10-27 10:53:04 +02:00
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public string ConfigurationFile
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
public string DataDir
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
public List<IPEndPoint> Listen
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2017-09-13 08:47:34 +02:00
|
|
|
|
|
2018-01-12 08:00:31 +01:00
|
|
|
|
public List<NBXplorerConnectionSetting> NBXplorerConnectionSettings
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
} = new List<NBXplorerConnectionSetting>();
|
|
|
|
|
|
2017-10-27 10:53:04 +02:00
|
|
|
|
public void LoadArgs(IConfiguration conf)
|
|
|
|
|
{
|
2018-01-11 14:52:28 +01:00
|
|
|
|
ChainType = DefaultConfiguration.GetChainType(conf);
|
|
|
|
|
var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(ChainType);
|
|
|
|
|
DataDir = conf.GetOrDefault<string>("datadir", defaultSettings.DefaultDataDirectory);
|
|
|
|
|
Logs.Configuration.LogInformation("Network: " + ChainType.ToString());
|
2017-09-13 08:47:34 +02:00
|
|
|
|
|
2018-01-11 14:52:28 +01:00
|
|
|
|
var supportedChains = conf.GetOrDefault<string>("chains", "btc")
|
|
|
|
|
.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
2018-01-12 03:54:57 +01:00
|
|
|
|
.Select(t => t.ToUpperInvariant());
|
2018-02-25 16:48:12 +01:00
|
|
|
|
NetworkProvider = new BTCPayNetworkProvider(ChainType).Filter(supportedChains.ToArray());
|
|
|
|
|
foreach (var chain in supportedChains)
|
|
|
|
|
{
|
|
|
|
|
if (NetworkProvider.GetNetwork(chain) == null)
|
|
|
|
|
throw new ConfigException($"Invalid chains \"{chain}\"");
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 14:52:28 +01:00
|
|
|
|
var validChains = new List<string>();
|
2018-02-25 16:48:12 +01:00
|
|
|
|
foreach (var net in NetworkProvider.GetAll())
|
2018-01-07 18:36:41 +01:00
|
|
|
|
{
|
2018-02-25 16:48:12 +01:00
|
|
|
|
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);
|
2018-03-20 18:09:25 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
2018-01-07 18:36:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 03:54:57 +01:00
|
|
|
|
Logs.Configuration.LogInformation("Supported chains: " + String.Join(',', supportedChains.ToArray()));
|
2018-02-25 16:48:12 +01:00
|
|
|
|
|
2017-10-27 10:53:04 +02:00
|
|
|
|
PostgresConnectionString = conf.GetOrDefault<string>("postgres", null);
|
2018-02-21 07:48:25 +01:00
|
|
|
|
BundleJsCss = conf.GetOrDefault<bool>("bundlejscss", true);
|
2017-12-02 15:22:23 +01:00
|
|
|
|
ExternalUrl = conf.GetOrDefault<Uri>("externalurl", null);
|
2018-04-05 08:50:23 +02:00
|
|
|
|
|
|
|
|
|
RootPath = conf.GetOrDefault<string>("rootpath", "/");
|
|
|
|
|
|
2018-03-20 18:09:25 +01:00
|
|
|
|
var old = conf.GetOrDefault<Uri>("internallightningnode", null);
|
|
|
|
|
if(old != null)
|
|
|
|
|
throw new ConfigException($"internallightningnode should not be used anymore, use btclightning instead");
|
2017-10-27 10:53:04 +02:00
|
|
|
|
}
|
2018-04-05 08:50:23 +02:00
|
|
|
|
public string RootPath { get; set; }
|
2018-03-20 18:09:25 +01:00
|
|
|
|
public Dictionary<string, LightningConnectionString> InternalLightningByCryptoCode { get; set; } = new Dictionary<string, LightningConnectionString>();
|
2018-02-26 10:58:02 +01:00
|
|
|
|
|
2018-02-25 16:48:12 +01:00
|
|
|
|
public BTCPayNetworkProvider NetworkProvider { get; set; }
|
2017-10-27 10:53:04 +02:00
|
|
|
|
public string PostgresConnectionString
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2017-12-02 15:22:23 +01:00
|
|
|
|
public Uri ExternalUrl
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2018-02-21 07:48:25 +01:00
|
|
|
|
public bool BundleJsCss
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
2017-10-27 10:53:04 +02:00
|
|
|
|
}
|
2017-09-13 08:47:34 +02:00
|
|
|
|
}
|