Commit 2a918bb7 authored by Pavel Pavlov's avatar Pavel Pavlov

Modify ApiSettings

- added DefaultDeStreamApiPort, TestDeStreamApiPort
Restorer of modify NetworkExtensions
parent 2333fc6b
......@@ -25,6 +25,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="NLog" Version="4.5.6" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0" />
<PackageReference Include="NUnit.Runners" Version="3.8.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
......
......@@ -10,7 +10,7 @@ namespace NBitcoin.Networks
{
public class DeStreamTest : Network
{
public DeStreamTest() : base()
public DeStreamTest() //: base()
{
this.DNSSeeds = new List<DNSSeedData>();
this.SeedNodes = new List<NetworkAddress>();
......
......@@ -13,6 +13,12 @@ namespace Stratis.Bitcoin.Features.Api
/// </summary>
public class ApiSettings
{
/// <summary>The default port used by the API when the node runs on the DeStream network.</summary>
public const int DefaultDeStreamApiPort = 0xDE20;
/// <summary>The default port used by the API when the node runs on the DeStream Test network.</summary>
public const int TestDeStreamApiPort = 0xDE21;
/// <summary>The default port used by the API when the node runs on the bitcoin network.</summary>
public const int DefaultBitcoinApiPort = 37220;
......@@ -101,11 +107,18 @@ namespace Stratis.Bitcoin.Features.Api
private static int GetDefaultPort(Network network)
{
if (network.IsBitcoin())
{
return network.IsTest() ? TestBitcoinApiPort : DefaultBitcoinApiPort;
}
if (network.IsStratis())
{
return network.IsTest() ? TestStratisApiPort : DefaultStratisApiPort;
}
return network.IsTest() ? TestDeStreamApiPort: DefaultDeStreamApiPort;
}
/// <summary>Prints the help information on how to configure the API settings to the logger.</summary>
/// <param name="network">The network to use.</param>
public static void PrintHelp(Network network)
......
......@@ -74,6 +74,15 @@ namespace Stratis.Bitcoin.Configuration
/// <summary>Minimum relay transaction fee for network.</summary>
public FeeRate MinRelayTxFeeRate { get; private set; }
/// <summary>
/// Returns default data root directory name
/// </summary>
protected virtual string DataRootDirName
{
get { return "StratisNode"; }
}
/// <summary>
/// Initializes a new instance of the object.
/// </summary>
......@@ -110,7 +119,7 @@ namespace Stratis.Bitcoin.Configuration
this.Network == null ? "(None)" : this.Network.Name,
this.ProtocolVersion,
this.Agent,
args == null?"(None)":string.Join(" ", args));
args == null ? "(None)" : string.Join(" ", args));
// By default, we look for a file named '<network>.conf' in the network's data directory,
// but both the data directory and the configuration file path may be changed using the -datadir and -conf command-line arguments.
......@@ -159,7 +168,7 @@ namespace Stratis.Bitcoin.Configuration
if (this.DataDir == null)
{
// Create the data directories if they don't exist.
this.DataDir = this.CreateDefaultDataDirectories(Path.Combine("StratisNode", this.Network.RootFolderName), this.Network);
this.DataDir = this.CreateDefaultDataDirectories(Path.Combine(this.DataRootDirName, this.Network.RootFolderName), this.Network);
}
else
{
......@@ -320,7 +329,7 @@ namespace Stratis.Bitcoin.Configuration
{
Guard.NotNull(network, nameof(network));
NodeSettings defaults = Default(network:network);
NodeSettings defaults = Default(network: network);
string daemonName = Path.GetFileName(Assembly.GetEntryAssembly().Location);
var builder = new StringBuilder();
......@@ -354,13 +363,13 @@ namespace Stratis.Bitcoin.Configuration
/// <param name="network">The network to base the defaults off.</param>
public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network)
{
NodeSettings defaults = Default(network:network);
NodeSettings defaults = Default(network: network);
builder.AppendLine("####Node Settings####");
builder.AppendLine($"#Test network. Defaults to 0.");
builder.AppendLine($"testnet={((network.IsTest() && !network.IsRegTest())?1:0)}");
builder.AppendLine($"testnet={((network.IsTest() && !network.IsRegTest()) ? 1 : 0)}");
builder.AppendLine($"#Regression test network. Defaults to 0.");
builder.AppendLine($"regtest={(network.IsRegTest()?1:0)}");
builder.AppendLine($"regtest={(network.IsRegTest() ? 1 : 0)}");
builder.AppendLine($"#Minimum fee rate. Defaults to {network.MinTxFee}.");
builder.AppendLine($"#mintxfee={network.MinTxFee}");
builder.AppendLine($"#Fallback fee rate. Defaults to {network.FallbackFee}.");
......
......@@ -30,6 +30,27 @@ namespace Stratis.Bitcoin.Utilities
return network.Name.ToLowerInvariant().Contains("regtest");
}
/// <summary>
/// Determines whether this network is a Stratis-network.
/// </summary>
/// <param name="network">The network.</param>
/// <returns><c>true</c> if the specified network is Stratis, <c>false</c> otherwise.</returns>
public static bool IsStratis(this Network network)
{
return network.Name.ToLowerInvariant().Contains("stratis");
}
/// <summary>
/// Determines whether this network is a DeStream-network.
/// </summary>
/// <param name="network">The network.</param>
/// <returns><c>true</c> if the specified network is DeStream, <c>false</c> otherwise.</returns>
public static bool IsDeStream(this Network network)
{
return network.Name.ToLowerInvariant().Contains("destream");
}
/// <summary>
/// Determines whether this network is a bitcoin network.
/// </summary>
......@@ -37,7 +58,9 @@ namespace Stratis.Bitcoin.Utilities
/// <returns><c>true</c> if the specified network is bitcoin, <c>false</c> otherwise.</returns>
public static bool IsBitcoin(this Network network)
{
return !network.Name.ToLowerInvariant().Contains("stratis");
//return !(new string[] { "stratis", "destream" }.Any(s => network.Name.ToLowerInvariant().Contains(s)));
return !IsStratis(network) && !IsDeStream(network);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment