mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 10:40:29 +01:00
7e714f1ef8
* Refactor how we handle and validate LN ConnectionStrings * Migrate existing connection string to Internal Node if they are the same. Cleanup some obsolete fields * Fix typos, remove duplicated method * Add a InternalNodeRef to LightningSupportedPaymentMethod
92 lines
3.0 KiB
C#
92 lines
3.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Hosting;
|
|
using NBitcoin;
|
|
|
|
namespace BTCPayServer.Services
|
|
{
|
|
public class BTCPayServerEnvironment
|
|
{
|
|
readonly IHttpContextAccessor httpContext;
|
|
readonly TorServices torServices;
|
|
public BTCPayServerEnvironment(IWebHostEnvironment env, BTCPayNetworkProvider provider, IHttpContextAccessor httpContext, TorServices torServices)
|
|
{
|
|
this.httpContext = httpContext;
|
|
Version = typeof(BTCPayServerEnvironment).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
|
|
#if DEBUG
|
|
Build = "Debug";
|
|
#else
|
|
Build = "Release";
|
|
#endif
|
|
#if ALTCOINS
|
|
AltcoinsVersion = true;
|
|
#else
|
|
AltcoinsVersion = false;
|
|
#endif
|
|
|
|
Environment = env;
|
|
NetworkType = provider.NetworkType;
|
|
this.torServices = torServices;
|
|
}
|
|
public IWebHostEnvironment Environment
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public string ExpectedDomain => httpContext.HttpContext.Request.Host.Host;
|
|
public string ExpectedHost => httpContext.HttpContext.Request.Host.Value;
|
|
public string ExpectedProtocol => httpContext.HttpContext.Request.Scheme;
|
|
public string OnionUrl => this.torServices.Services.Where(s => s.ServiceType == TorServiceType.BTCPayServer)
|
|
.Select(s => $"http://{s.OnionHost}").FirstOrDefault();
|
|
|
|
public ChainName NetworkType { get; set; }
|
|
public string Version
|
|
{
|
|
get; set;
|
|
}
|
|
public string Build
|
|
{
|
|
get; set;
|
|
}
|
|
public bool AltcoinsVersion { get; set; }
|
|
|
|
public bool IsDeveloping
|
|
{
|
|
get
|
|
{
|
|
return NetworkType == ChainName.Regtest && Environment.IsDevelopment();
|
|
}
|
|
}
|
|
|
|
public bool IsSecure
|
|
{
|
|
get
|
|
{
|
|
return NetworkType != ChainName.Mainnet ||
|
|
httpContext.HttpContext.Request.Scheme == "https" ||
|
|
httpContext.HttpContext.Request.Host.Host.EndsWith(".onion", StringComparison.OrdinalIgnoreCase) ||
|
|
Extensions.IsLocalNetwork(httpContext.HttpContext.Request.Host.Host);
|
|
}
|
|
}
|
|
|
|
public HttpContext Context => httpContext.HttpContext;
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder txt = new StringBuilder();
|
|
txt.Append($"@Copyright BTCPayServer v{Version}");
|
|
if (AltcoinsVersion)
|
|
txt.Append($" (altcoins)");
|
|
if (!Environment.IsProduction() || !Build.Equals("Release", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
txt.Append($" Environment: {Environment.EnvironmentName} Build: {Build}");
|
|
}
|
|
return txt.ToString();
|
|
}
|
|
}
|
|
}
|