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 @@ ...@@ -25,6 +25,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="NLog" Version="4.5.6" /> <PackageReference Include="NLog" Version="4.5.6" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0" /> <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" /> <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup> </ItemGroup>
......
...@@ -10,7 +10,7 @@ namespace NBitcoin.Networks ...@@ -10,7 +10,7 @@ namespace NBitcoin.Networks
{ {
public class DeStreamTest : Network public class DeStreamTest : Network
{ {
public DeStreamTest() : base() public DeStreamTest() //: base()
{ {
this.DNSSeeds = new List<DNSSeedData>(); this.DNSSeeds = new List<DNSSeedData>();
this.SeedNodes = new List<NetworkAddress>(); this.SeedNodes = new List<NetworkAddress>();
......
...@@ -13,6 +13,12 @@ namespace Stratis.Bitcoin.Features.Api ...@@ -13,6 +13,12 @@ namespace Stratis.Bitcoin.Features.Api
/// </summary> /// </summary>
public class ApiSettings 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> /// <summary>The default port used by the API when the node runs on the bitcoin network.</summary>
public const int DefaultBitcoinApiPort = 37220; public const int DefaultBitcoinApiPort = 37220;
...@@ -101,11 +107,18 @@ namespace Stratis.Bitcoin.Features.Api ...@@ -101,11 +107,18 @@ namespace Stratis.Bitcoin.Features.Api
private static int GetDefaultPort(Network network) private static int GetDefaultPort(Network network)
{ {
if (network.IsBitcoin()) if (network.IsBitcoin())
{
return network.IsTest() ? TestBitcoinApiPort : DefaultBitcoinApiPort; return network.IsTest() ? TestBitcoinApiPort : DefaultBitcoinApiPort;
}
if (network.IsStratis())
{
return network.IsTest() ? TestStratisApiPort : DefaultStratisApiPort; 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> /// <summary>Prints the help information on how to configure the API settings to the logger.</summary>
/// <param name="network">The network to use.</param> /// <param name="network">The network to use.</param>
public static void PrintHelp(Network network) public static void PrintHelp(Network network)
......
...@@ -74,6 +74,15 @@ namespace Stratis.Bitcoin.Configuration ...@@ -74,6 +74,15 @@ namespace Stratis.Bitcoin.Configuration
/// <summary>Minimum relay transaction fee for network.</summary> /// <summary>Minimum relay transaction fee for network.</summary>
public FeeRate MinRelayTxFeeRate { get; private set; } public FeeRate MinRelayTxFeeRate { get; private set; }
/// <summary>
/// Returns default data root directory name
/// </summary>
protected virtual string DataRootDirName
{
get { return "StratisNode"; }
}
/// <summary> /// <summary>
/// Initializes a new instance of the object. /// Initializes a new instance of the object.
/// </summary> /// </summary>
...@@ -110,7 +119,7 @@ namespace Stratis.Bitcoin.Configuration ...@@ -110,7 +119,7 @@ namespace Stratis.Bitcoin.Configuration
this.Network == null ? "(None)" : this.Network.Name, this.Network == null ? "(None)" : this.Network.Name,
this.ProtocolVersion, this.ProtocolVersion,
this.Agent, 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, // 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. // 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 ...@@ -159,7 +168,7 @@ namespace Stratis.Bitcoin.Configuration
if (this.DataDir == null) if (this.DataDir == null)
{ {
// Create the data directories if they don't exist. // 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 else
{ {
...@@ -320,7 +329,7 @@ namespace Stratis.Bitcoin.Configuration ...@@ -320,7 +329,7 @@ namespace Stratis.Bitcoin.Configuration
{ {
Guard.NotNull(network, nameof(network)); Guard.NotNull(network, nameof(network));
NodeSettings defaults = Default(network:network); NodeSettings defaults = Default(network: network);
string daemonName = Path.GetFileName(Assembly.GetEntryAssembly().Location); string daemonName = Path.GetFileName(Assembly.GetEntryAssembly().Location);
var builder = new StringBuilder(); var builder = new StringBuilder();
...@@ -354,13 +363,13 @@ namespace Stratis.Bitcoin.Configuration ...@@ -354,13 +363,13 @@ namespace Stratis.Bitcoin.Configuration
/// <param name="network">The network to base the defaults off.</param> /// <param name="network">The network to base the defaults off.</param>
public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network) public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network)
{ {
NodeSettings defaults = Default(network:network); NodeSettings defaults = Default(network: network);
builder.AppendLine("####Node Settings####"); builder.AppendLine("####Node Settings####");
builder.AppendLine($"#Test network. Defaults to 0."); 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($"#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($"#Minimum fee rate. Defaults to {network.MinTxFee}.");
builder.AppendLine($"#mintxfee={network.MinTxFee}"); builder.AppendLine($"#mintxfee={network.MinTxFee}");
builder.AppendLine($"#Fallback fee rate. Defaults to {network.FallbackFee}."); builder.AppendLine($"#Fallback fee rate. Defaults to {network.FallbackFee}.");
......
...@@ -30,6 +30,27 @@ namespace Stratis.Bitcoin.Utilities ...@@ -30,6 +30,27 @@ namespace Stratis.Bitcoin.Utilities
return network.Name.ToLowerInvariant().Contains("regtest"); 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> /// <summary>
/// Determines whether this network is a bitcoin network. /// Determines whether this network is a bitcoin network.
/// </summary> /// </summary>
...@@ -37,7 +58,9 @@ namespace Stratis.Bitcoin.Utilities ...@@ -37,7 +58,9 @@ namespace Stratis.Bitcoin.Utilities
/// <returns><c>true</c> if the specified network is bitcoin, <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the specified network is bitcoin, <c>false</c> otherwise.</returns>
public static bool IsBitcoin(this Network network) 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