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>
......
......@@ -40,7 +40,7 @@ namespace DeStream.DeStreamD
network = Network.DeStreamMain;
DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args:args, loadConfiguration:false);
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
......
......@@ -42,7 +42,7 @@ namespace NBitcoin
{
ScriptSig = new Script(Op.GetPushOp(0), new Op()
{
Code = (OpcodeType)0x1,
Code = (OpcodeType)0x1,
PushData = new[] { (byte)42 }
}, Op.GetPushOp(Encoders.ASCII.DecodeData(pszTimestamp)))
});
......
......@@ -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,9 +107,16 @@ namespace Stratis.Bitcoin.Features.Api
private static int GetDefaultPort(Network network)
{
if (network.IsBitcoin())
{
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>
......
......@@ -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>
......@@ -90,7 +99,7 @@ namespace Stratis.Bitcoin.Configuration
/// - 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.
/// </remarks>
public NodeSettings(Network network = null, ProtocolVersion protocolVersion = SupportedProtocolVersion,
public NodeSettings(Network network = null, ProtocolVersion protocolVersion = SupportedProtocolVersion,
string agent = "StratisBitcoin", string[] args = null)
{
// Create the default logger factory and logger.
......@@ -106,16 +115,16 @@ namespace Stratis.Bitcoin.Configuration
this.ConfigReader = new TextFileConfiguration(args ?? new string[] { });
// 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.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.
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 (this.DataDir != null && this.ConfigurationFile != null)
......@@ -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
{
......@@ -168,7 +177,7 @@ namespace Stratis.Bitcoin.Configuration
this.DataDir = Directory.CreateDirectory(directoryPath).FullName;
this.Logger.LogDebug("Data directory initialized with path {0}.", this.DataDir);
}
// Set the data folder.
this.DataFolder = new DataFolder(this.DataDir);
......@@ -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();
......@@ -346,7 +355,7 @@ namespace Stratis.Bitcoin.Configuration
ConnectionManagerSettings.PrintHelp(network);
}
/// <summary>
/// Get the default configuration.
/// </summary>
......@@ -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}.");
......
......@@ -19,7 +19,7 @@ namespace Stratis.Bitcoin.Utilities
{
return network.Name.ToLowerInvariant().Contains("test");
}
/// <summary>
/// Determines whether this network is a regtest network.
/// </summary>
......@@ -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