private void CreateConfigFile(NodeConfigParameters configParameters = null) { Directory.CreateDirectory(this.runner.DataFolder); configParameters = configParameters ?? new NodeConfigParameters(); configParameters.SetDefaultValueIfUndefined("regtest", "1"); configParameters.SetDefaultValueIfUndefined("rest", "1"); configParameters.SetDefaultValueIfUndefined("server", "1"); configParameters.SetDefaultValueIfUndefined("txindex", "1"); if (!this.CookieAuth) { configParameters.SetDefaultValueIfUndefined("rpcuser", this.creds.UserName); configParameters.SetDefaultValueIfUndefined("rpcpassword", this.creds.Password); } // The debug log is disabled in stratisX when printtoconsole is enabled. // While further integration tests are being developed it makes sense // to always have the debug logs available, as there is minimal other // insight into the stratisd process while it is running. if (this.runner is StratisXRunner) { configParameters.SetDefaultValueIfUndefined("printtoconsole", "0"); configParameters.SetDefaultValueIfUndefined("debug", "1"); } else { configParameters.SetDefaultValueIfUndefined("printtoconsole", "1"); } configParameters.SetDefaultValueIfUndefined("keypool", "10"); configParameters.SetDefaultValueIfUndefined("agentprefix", "node" + this.ProtocolPort); configParameters.Import(this.ConfigParameters); File.WriteAllText(this.Config, configParameters.ToString()); }
public NodeBuilder(string rootFolder) { this.Nodes = new List <CoreNode>(); this.ConfigParameters = new NodeConfigParameters(); this.rootFolder = rootFolder; }
public void Import(NodeConfigParameters configParameters) { foreach (KeyValuePair <string, string> kv in configParameters) { if (!this.ContainsKey(kv.Key)) { this.Add(kv.Key, kv.Value); } } }
public void Import(NodeConfigParameters configParameters) { foreach (var kv in configParameters) { if (!this.ContainsKey(kv.Key)) { this.Add(kv.Key, kv.Value); } } }
public CoreNode CreateMainnetStratisXNode(string version = "2.0.0.5", bool useCookieAuth = false) { var parameters = new NodeConfigParameters(); parameters.Add("regtest", "0"); parameters.Add("server", "0"); string stratisDPath = GetStratisXPath(version); return(this.CreateNode(new StratisXRunner(this.GetNextDataFolderName(), stratisDPath), "stratis.conf", useCookieAuth, parameters)); }
public CoreNode CreateStratisCustomPowNode(Network network, NodeConfigParameters configParameters) { var callback = new Action <IFullNodeBuilder>(builder => builder .UseBlockStore() .UsePowConsensus() .UseMempool() .AddMining() .UseWallet() .AddRPC() .MockIBD()); return(CreateCustomNode(callback, network, ProtocolVersion.PROTOCOL_VERSION, configParameters: configParameters)); }
public void Start() { Directory.CreateDirectory(this.runner.DataFolder); var config = new NodeConfigParameters(); config.Add("regtest", "1"); config.Add("rest", "1"); config.Add("server", "1"); config.Add("txindex", "1"); if (!CookieAuth) { config.Add("rpcuser", creds.UserName); config.Add("rpcpassword", creds.Password); } config.Add("port", this.ports[0].ToString()); config.Add("rpcport", this.ports[1].ToString()); config.Add("apiport", this.ports[2].ToString()); config.Add("printtoconsole", "1"); config.Add("keypool", "10"); config.Add("agentprefix", "node" + this.ports[0].ToString()); config.Import(this.ConfigParameters); File.WriteAllText(this.Config, config.ToString()); lock (this.lockObject) { this.runner.Start(); this.State = CoreNodeState.Starting; } if (this.runner is BitcoinCoreRunner) { StartBitcoinCoreRunner(); } else { StartStratisRunner(); } this.State = CoreNodeState.Running; }
private void CreateConfigFile(NodeConfigParameters configParameters = null) { Directory.CreateDirectory(this.runner.DataFolder); configParameters = configParameters ?? new NodeConfigParameters(); configParameters.SetDefaultValueIfUndefined("regtest", "1"); configParameters.SetDefaultValueIfUndefined("rest", "1"); configParameters.SetDefaultValueIfUndefined("server", "1"); configParameters.SetDefaultValueIfUndefined("txindex", "1"); if (!this.CookieAuth) { configParameters.SetDefaultValueIfUndefined("rpcuser", this.creds.UserName); configParameters.SetDefaultValueIfUndefined("rpcpassword", this.creds.Password); } configParameters.SetDefaultValueIfUndefined("printtoconsole", "1"); configParameters.SetDefaultValueIfUndefined("keypool", "10"); configParameters.SetDefaultValueIfUndefined("agentprefix", "node" + this.ProtocolPort); configParameters.Import(this.ConfigParameters); File.WriteAllText(this.Config, configParameters.ToString()); }
public CoreNode(NodeRunner runner, NodeConfigParameters configParameters, string configfile, bool useCookieAuth = false) { this.runner = runner; this.State = CoreNodeState.Stopped; string pass = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20)); this.creds = new NetworkCredential(pass, pass); this.Config = Path.Combine(this.runner.DataFolder, configfile); this.CookieAuth = useCookieAuth; this.ConfigParameters.Import(configParameters); var randomFoundPorts = new int[3]; IpHelper.FindPorts(randomFoundPorts); this.ConfigParameters.SetDefaultValueIfUndefined("port", randomFoundPorts[0].ToString()); this.ConfigParameters.SetDefaultValueIfUndefined("rpcport", randomFoundPorts[1].ToString()); this.ConfigParameters.SetDefaultValueIfUndefined("apiport", randomFoundPorts[2].ToString()); this.loggerFactory = new ExtendedLoggerFactory(); this.loggerFactory.AddConsoleWithFilters(); CreateConfigFile(this.ConfigParameters); }
protected CoreNode CreateNode(NodeRunner runner, string configFile = "bitcoin.conf", bool useCookieAuth = false, NodeConfigParameters configParameters = null) { var node = new CoreNode(runner, configParameters, configFile, useCookieAuth); this.Nodes.Add(node); return(node); }
/// <summary>A helper method to create a node instance with a non-standard set of features enabled. The node can be PoW or PoS, as long as the appropriate features are provided.</summary> /// <param name="callback">A callback accepting an instance of <see cref="IFullNodeBuilder"/> that constructs a node with a custom feature set.</param> /// <param name="network">The network the node will be running on.</param> /// <param name="protocolVersion">Use <see cref="ProtocolVersion.PROTOCOL_VERSION"/> for BTC PoW-like networks and <see cref="ProtocolVersion.ALT_PROTOCOL_VERSION"/> for Stratis PoS-like networks.</param> /// <param name="agent">A user agent string to distinguish different node versions from each other.</param> /// <param name="configParameters">Use this to pass in any custom configuration parameters used to set up the CoreNode</param> public CoreNode CreateCustomNode(Action <IFullNodeBuilder> callback, Network network, ProtocolVersion protocolVersion = ProtocolVersion.PROTOCOL_VERSION, string agent = "Custom", NodeConfigParameters configParameters = null, ProtocolVersion minProtocolVersion = ProtocolVersion.PROTOCOL_VERSION) { configParameters = configParameters ?? new NodeConfigParameters(); configParameters.SetDefaultValueIfUndefined("conf", "custom.conf"); string configFileName = configParameters["conf"]; configParameters.SetDefaultValueIfUndefined("datadir", this.GetNextDataFolderName(agent)); string dataDir = configParameters["datadir"]; configParameters.ToList().ForEach(p => this.ConfigParameters[p.Key] = p.Value); return(CreateNode(new CustomNodeRunner(dataDir, callback, network, protocolVersion, configParameters, agent, minProtocolVersion), configFileName)); }
/// <summary> /// Creates a Stratis Proof-of-Stake node with the cold staking feature in lieu of the regular wallet. /// <para> /// <see cref="P2P.PeerDiscovery"/> and <see cref="P2P.PeerConnectorDiscovery"/> are disabled by default. /// </para> /// </summary> /// <param name="network">The network the node will run on.</param> /// <param name="agent">Overrides the node's agent prefix.</param> /// <param name="configParameters">Adds to the nodes configuration parameters.</param> /// /// <returns>The constructed PoS node.</returns> public CoreNode CreateStratisColdStakingNode(Network network, string agent = "StratisBitcoin", NodeConfigParameters configParameters = null) { return(CreateNode(new StratisBitcoinColdStakingRunner(this.GetNextDataFolderName(), network, agent), network.DefaultConfigFilename, configParameters: configParameters)); }
/// <summary> /// Creates a Stratis Proof-of-Work node. /// <para> /// <see cref="P2P.PeerDiscovery"/> and <see cref="P2P.PeerConnectorDiscovery"/> are disabled by default. /// </para> /// </summary> /// <param name="network">The network the node will run on.</param> /// <param name="agent">Overrides the node's agent prefix.</param> /// <param name="configParameters">Adds to the nodes configuration parameters.</param> /// <returns>The constructed PoW node.</returns> public CoreNode CreateStratisPowNode(Network network, string agent = null, NodeConfigParameters configParameters = null) { return(CreateNode(new StratisBitcoinPowRunner(this.GetNextDataFolderName(), network, agent), configParameters: configParameters)); }
private void CreateConfigFile(NodeConfigParameters configParameters = null) { Directory.CreateDirectory(this.runner.DataFolder); configParameters = configParameters ?? new NodeConfigParameters(); configParameters.SetDefaultValueIfUndefined("regtest", "1"); configParameters.SetDefaultValueIfUndefined("rest", "1"); configParameters.SetDefaultValueIfUndefined("server", "1"); configParameters.SetDefaultValueIfUndefined("txindex", "1"); if (this.runner is BitcoinCoreRunner) { // TODO: Migrate to using `generatetoaddress` RPC for newer Core versions configParameters.SetDefaultValueIfUndefined("deprecatedrpc", "generate"); } if (!this.CookieAuth) { configParameters.SetDefaultValueIfUndefined("rpcuser", this.creds.UserName); configParameters.SetDefaultValueIfUndefined("rpcpassword", this.creds.Password); } configParameters.SetDefaultValueIfUndefined("printtoconsole", "1"); configParameters.SetDefaultValueIfUndefined("keypool", "10"); configParameters.SetDefaultValueIfUndefined("agentprefix", "node" + this.ProtocolPort); configParameters.Import(this.ConfigParameters); // Need special handling for config files used by newer versions of Bitcoin Core. // These have specialised sections for [regtest], [test] and [main] in which certain options // only have an effect when they appear in their respective section. var builder = new StringBuilder(); // Scan for network setting. These need to be at the top of the config file. bool testnet = configParameters.Any(a => a.Key.Equals("testnet") && a.Value.Equals("1")); bool regtest = configParameters.Any(a => a.Key.Equals("regtest") && a.Value.Equals("1")); bool mainnet = !testnet && !regtest; if (testnet) { builder.AppendLine("testnet=1"); if (this.runner.UseNewConfigStyle) { builder.AppendLine("[test]"); } } if (regtest) { builder.AppendLine("regtest=1"); if (this.runner.UseNewConfigStyle) { builder.AppendLine("[regtest]"); } } if (mainnet) { // Mainnet is implied by the absence of both testnet and regtest. But it should still get its own config section. if (this.runner.UseNewConfigStyle) { builder.AppendLine("[main]"); } } foreach (KeyValuePair <string, string> kv in configParameters) { if (kv.Key.Equals("testnet") || kv.Key.Equals("regtest")) { continue; } builder.AppendLine(kv.Key + "=" + kv.Value); } File.WriteAllText(this.Config, builder.ToString()); }
/// <summary> /// Creates a Stratis Proof-of-Stake node. /// <para> /// <see cref="P2P.PeerDiscovery"/> and <see cref="P2P.PeerConnectorDiscovery"/> are disabled by default. /// </para> /// </summary> /// <param name="network">The network the node will run on.</param> /// <param name="agent">Overrides the node's agent prefix.</param> /// <param name="configParameters">Adds to the nodes configuration parameters.</param> /// <param name="isGateway">Whether the node is a Proven Headers gateway node.</param> /// <returns>The constructed PoS node.</returns> public CoreNode CreateStratisPosNode(Network network, string agent = "StratisBitcoin", NodeConfigParameters configParameters = null, bool isGateway = false) { return(CreateNode(new StratisBitcoinPosRunner(this.GetNextDataFolderName(), network, agent, isGateway), "stratis.conf", configParameters: configParameters)); }
/// <summary> /// Creates a Stratis Proof-of-Stake node. /// <para> /// <see cref="P2P.PeerDiscovery"/> and <see cref="P2P.PeerConnectorDiscovery"/> are disabled by default. /// </para> /// </summary> /// <returns>The constructed PoS node.</returns> public CoreNode CreateRedstonePosNode(Network network, string agent = "Redstone", NodeConfigParameters configParameters = null) { return(CreateNode(new RedstonePosRunner(this.GetNextDataFolderName(), network, agent), "redstone.conf", configParameters: configParameters)); }
public CoreNode CreateStratisXNode(string version = "2.0.0.5", bool useCookieAuth = false, NodeConfigParameters configParameters = null) { string stratisDPath = GetStratisXPath(version); return(this.CreateNode(new StratisXRunner(this.GetNextDataFolderName(), stratisDPath), "stratis.conf", useCookieAuth, configParameters)); }