Commit 9e7f819a authored by Alexey's avatar Alexey

Automerge side effects fixed.

Data root directory name changed to "DeStreamNode".
parent 9d48dd0e
using System;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using Microsoft.CodeAnalysis.CSharp;
using NBitcoin;
using NBitcoin.Protocol;
......@@ -14,6 +15,8 @@ using Stratis.Bitcoin.Features.Miner;
using Stratis.Bitcoin.Features.RPC;
using Stratis.Bitcoin.Features.Wallet;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Utilities.Extensions;
using DeStream.Stratis.Bitcoin.Configuration;
......@@ -35,6 +38,7 @@ namespace DeStream.DeStreamD
network = Network.DeStreamTest;
else
network = Network.DeStreamMain;
DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args:args, loadConfiguration:false);
Console.WriteLine($"current network: {network.Name}");
......
......@@ -17,6 +17,14 @@ namespace DeStream.Stratis.Bitcoin.Configuration
/// </summary>
public class DeStreamNodeSettings : NodeSettings
{
/// <summary>
/// Returns default data root directory name
/// </summary>
protected override string DataRootDirName
{
get { return "DeStreamNode"; }
}
/// <summary>
/// Initializes a new instance of the object.
/// </summary>
......@@ -28,77 +36,5 @@ namespace DeStream.Stratis.Bitcoin.Configuration
: base (innerNetwork, protocolVersion, agent, args, loadConfiguration)
{
}
/// <summary>
/// Loads the configuration file.
/// </summary>
/// <returns>Initialized node configuration.</returns>
/// <exception cref="ConfigurationException">Thrown in case of any problems with the configuration file or command line arguments.</exception>
public override NodeSettings LoadConfiguration(List<IFeatureRegistration> features = null)
{
// Configuration already loaded?
if (this.ConfigReader != null)
return this;
// Get the arguments set previously
var args = this.LoadArgs;
// Setting the data directory.
if (this.LoadArgs.GetValueOf("-datadir") == null || this.DataDir == null)
{
this.DataDir = this.CreateDefaultDataDirectories(Path.Combine("DeStreamNode", this.Network.RootFolderName), this.Network);
}
else
{
// Create the data directories if they don't exist.
string directoryPath = Path.Combine(this.DataDir, this.Network.RootFolderName, this.Network.Name);
Directory.CreateDirectory(directoryPath);
this.DataDir = directoryPath;
this.Logger.LogDebug("Data directory initialized with path {0}.", directoryPath);
}
// If no configuration file path is passed in the args, load the default file.
if (this.ConfigurationFile == null)
{
this.ConfigurationFile = this.CreateDefaultConfigurationFile();
}
var consoleConfig = new TextFileConfiguration(args);
var config = new TextFileConfiguration(File.ReadAllText(this.ConfigurationFile));
this.ConfigReader = config;
consoleConfig.MergeInto(config);
this.DataFolder = new DataFolder(this.DataDir);
if (!Directory.Exists(this.DataFolder.CoinViewPath))
Directory.CreateDirectory(this.DataFolder.CoinViewPath);
// Set the configuration filter and file path.
this.Log.Load(config);
this.LoggerFactory.AddFilters(this.Log, this.DataFolder);
this.LoggerFactory.ConfigureConsoleFilters(this.LoggerFactory.GetConsoleSettings(), this.Log);
this.Logger.LogDebug("Data directory set to '{0}'.", this.DataDir);
this.Logger.LogDebug("Configuration file set to '{0}'.", this.ConfigurationFile);
this.RequireStandard = config.GetOrDefault("acceptnonstdtxn", !(this.Network.IsTest()));
this.MaxTipAge = config.GetOrDefault("maxtipage", this.Network.MaxTipAge);
this.Logger.LogDebug("Network: IsTest='{0}', IsBitcoin='{1}'.", this.Network.IsTest(), this.Network.IsBitcoin());
this.MinTxFeeRate = new FeeRate(config.GetOrDefault("mintxfee", this.Network.MinTxFee));
this.Logger.LogDebug("MinTxFeeRate set to {0}.", this.MinTxFeeRate);
this.FallbackTxFeeRate = new FeeRate(config.GetOrDefault("fallbackfee", this.Network.FallbackFee));
this.Logger.LogDebug("FallbackTxFeeRate set to {0}.", this.FallbackTxFeeRate);
this.MinRelayTxFeeRate = new FeeRate(config.GetOrDefault("minrelaytxfee", this.Network.MinRelayTxFee));
this.Logger.LogDebug("MinRelayTxFeeRate set to {0}.", this.MinRelayTxFeeRate);
this.SyncTimeEnabled = config.GetOrDefault<bool>("synctime", true);
this.Logger.LogDebug("Time synchronization with peers is {0}.", this.SyncTimeEnabled ? "enabled" : "disabled");
// Add a prefix set by the user to the agent. This will allow people running nodes to
// identify themselves if they wish. The prefix is limited to 10 characters.
string agentPrefix = config.GetOrDefault("agentprefix", string.Empty);
agentPrefix = agentPrefix.Substring(0, Math.Min(10, agentPrefix.Length));
this.Agent = string.IsNullOrEmpty(agentPrefix) ? this.Agent : $"{agentPrefix}-{this.Agent}";
return this;
}
}
}
\ No newline at end of file
......@@ -38,6 +38,14 @@ namespace Stratis.Bitcoin.Configuration
/// <summary>Version of the protocol the current implementation supports.</summary>
public const ProtocolVersion SupportedProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION;
/// <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 +118,7 @@ namespace Stratis.Bitcoin.Configuration
// Setting the data directory.
if (this.DataDir == null)
{
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
{
......@@ -183,7 +191,7 @@ namespace Stratis.Bitcoin.Configuration
/// <summary>Minimum relay transaction fee for network.</summary>
public FeeRate MinRelayTxFeeRate { get; set; }
public TextFileConfiguration ConfigReader { get; protected set; }
public TextFileConfiguration ConfigReader { get; private set; }
/// <summary><c>true</c> to sync time with other peers and calculate adjusted time, <c>false</c> to use our system clock only.</summary>
public bool SyncTimeEnabled { get; set; }
......@@ -205,7 +213,7 @@ namespace Stratis.Bitcoin.Configuration
/// <param name="features">The features to include in the configuration file if a default file has to be created.</param>
/// <returns>Initialized node configuration.</returns>
/// <exception cref="ConfigurationException">Thrown in case of any problems with the configuration file or command line arguments.</exception>
public virtual NodeSettings LoadConfiguration(List<IFeatureRegistration> features = null)
public NodeSettings LoadConfiguration(List<IFeatureRegistration> features = null)
{
// Configuration already loaded?
if (this.ConfigReader != null)
......
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