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>
......
...@@ -40,7 +40,7 @@ namespace DeStream.DeStreamD ...@@ -40,7 +40,7 @@ namespace DeStream.DeStreamD
network = Network.DeStreamMain; network = Network.DeStreamMain;
DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args:args, loadConfiguration:false); DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args:args, loadConfiguration:false);
Console.WriteLine($"current network: {network.Name}"); Console.WriteLine($"current network: {network.Name}");
// NOTES: running BTC and STRAT side by side is not possible yet as the flags for serialization are static // NOTES: running BTC and STRAT side by side is not possible yet as the flags for serialization are static
......
...@@ -42,7 +42,7 @@ namespace NBitcoin ...@@ -42,7 +42,7 @@ namespace NBitcoin
{ {
ScriptSig = new Script(Op.GetPushOp(0), new Op() ScriptSig = new Script(Op.GetPushOp(0), new Op()
{ {
Code = (OpcodeType)0x1, Code = (OpcodeType)0x1,
PushData = new[] { (byte)42 } PushData = new[] { (byte)42 }
}, Op.GetPushOp(Encoders.ASCII.DecodeData(pszTimestamp))) }, Op.GetPushOp(Encoders.ASCII.DecodeData(pszTimestamp)))
}); });
......
...@@ -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,9 +107,16 @@ namespace Stratis.Bitcoin.Features.Api ...@@ -101,9 +107,16 @@ 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;
}
return network.IsTest() ? TestStratisApiPort : DefaultStratisApiPort;
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> /// <summary>Prints the help information on how to configure the API settings to the logger.</summary>
......
...@@ -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>
...@@ -90,7 +99,7 @@ namespace Stratis.Bitcoin.Configuration ...@@ -90,7 +99,7 @@ namespace Stratis.Bitcoin.Configuration
/// - Alternatively, if the file name is not supplied then a network-specific file /// - Alternatively, if the file name is not supplied then a network-specific file
/// name would be determined. In this case we first need to determine the network. /// name would be determined. In this case we first need to determine the network.
/// </remarks> /// </remarks>
public NodeSettings(Network network = null, ProtocolVersion protocolVersion = SupportedProtocolVersion, public NodeSettings(Network network = null, ProtocolVersion protocolVersion = SupportedProtocolVersion,
string agent = "StratisBitcoin", string[] args = null) string agent = "StratisBitcoin", string[] args = null)
{ {
// Create the default logger factory and logger. // Create the default logger factory and logger.
...@@ -106,16 +115,16 @@ namespace Stratis.Bitcoin.Configuration ...@@ -106,16 +115,16 @@ namespace Stratis.Bitcoin.Configuration
this.ConfigReader = new TextFileConfiguration(args ?? new string[] { }); this.ConfigReader = new TextFileConfiguration(args ?? new string[] { });
// Log arguments. // Log arguments.
this.Logger.LogDebug("Arguments: network='{0}', protocolVersion='{1}', agent='{2}', args='{3}'.", this.Logger.LogDebug("Arguments: network='{0}', protocolVersion='{1}', agent='{2}', args='{3}'.",
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.
this.ConfigurationFile = this.ConfigReader.GetOrDefault<string>("conf", null, this.Logger)?.NormalizeDirectorySeparator(); this.ConfigurationFile = this.ConfigReader.GetOrDefault<string>("conf", null, this.Logger)?.NormalizeDirectorySeparator();
this.DataDir = this.ConfigReader.GetOrDefault<string>("datadir", null, this.Logger)?.NormalizeDirectorySeparator(); this.DataDir = this.ConfigReader.GetOrDefault<string>("datadir", null, this.Logger)?.NormalizeDirectorySeparator();
// If the configuration file is relative then assume it is relative to the data folder and combine the paths. // If the configuration file is relative then assume it is relative to the data folder and combine the paths.
if (this.DataDir != null && this.ConfigurationFile != null) if (this.DataDir != null && this.ConfigurationFile != null)
...@@ -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
{ {
...@@ -168,7 +177,7 @@ namespace Stratis.Bitcoin.Configuration ...@@ -168,7 +177,7 @@ namespace Stratis.Bitcoin.Configuration
this.DataDir = Directory.CreateDirectory(directoryPath).FullName; this.DataDir = Directory.CreateDirectory(directoryPath).FullName;
this.Logger.LogDebug("Data directory initialized with path {0}.", this.DataDir); this.Logger.LogDebug("Data directory initialized with path {0}.", this.DataDir);
} }
// Set the data folder. // Set the data folder.
this.DataFolder = new DataFolder(this.DataDir); this.DataFolder = new DataFolder(this.DataDir);
...@@ -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();
...@@ -346,7 +355,7 @@ namespace Stratis.Bitcoin.Configuration ...@@ -346,7 +355,7 @@ namespace Stratis.Bitcoin.Configuration
ConnectionManagerSettings.PrintHelp(network); ConnectionManagerSettings.PrintHelp(network);
} }
/// <summary> /// <summary>
/// Get the default configuration. /// Get the default configuration.
/// </summary> /// </summary>
...@@ -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}.");
......
...@@ -19,7 +19,7 @@ namespace Stratis.Bitcoin.Utilities ...@@ -19,7 +19,7 @@ namespace Stratis.Bitcoin.Utilities
{ {
return network.Name.ToLowerInvariant().Contains("test"); return network.Name.ToLowerInvariant().Contains("test");
} }
/// <summary> /// <summary>
/// Determines whether this network is a regtest network. /// Determines whether this network is a regtest network.
/// </summary> /// </summary>
...@@ -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