public void saveNetworkConfigurations() { List <NetworkConfiguration> toSerialize = NetworkConfigurations.ToList(); using (StringWriter textWriter = new StringWriter()) { _serializer.Serialize(textWriter, toSerialize); Properties.Settings.Default.NetworkConfigurations = textWriter.ToString(); Properties.Settings.Default.Save(); } }
/// <summary> /// City.Chain daemon can be launched with options to specify coin and network, using the parameters -chain and -testnet. It defaults to City main network. /// </summary> /// <example> /// dotnet city.chain.dll -coin=bitcoin -network=regtest /// dotnet city.chain.dll -coin=city -network=test /// </example> /// <param name="args"></param> /// <returns></returns> public static async Task Main(string[] args) { try { var configReader = new TextFileConfiguration(args ?? new string[] { }); // City Chain daemon supports multiple networks, supply the chain parameter to change it. // Example: -chain=bitcoin var chain = configReader.GetOrDefault <string>("chain", "city"); var networkIdentifier = "main"; if (configReader.GetOrDefault <bool>("testnet", false)) { networkIdentifier = "testnet"; } else if (configReader.GetOrDefault <bool>("regtest", false)) { networkIdentifier = "regtest"; } NetworkConfiguration networkConfiguration = new NetworkConfigurations().GetNetwork(networkIdentifier, chain); if (networkConfiguration == null) { throw new ArgumentException($"The supplied chain ({chain}) and network ({networkIdentifier}) parameters did not result in a valid network."); } var apiPort = configReader.GetOrDefault <string>("apiport", networkConfiguration.ApiPort.ToString()); args = args .Append("-apiport=" + apiPort) .Append("-wsport=" + networkConfiguration.WsPort).ToArray(); var nodeSettings = new NodeSettings(networksSelector: GetNetwork(chain), protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args, agent: "CityChain") { MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION }; var dnsSettings = new DnsSettings(nodeSettings); // Create or read the node info. var nodeInfoManager = new NodeInfoManager(nodeSettings); // Indicates if we should clear the blockchain database. When this is performed, the daemon will exit immediately. if (configReader.GetOrDefault <bool>("reset", false)) { Console.WriteLine("Reset option was supplied, blockchain database is being reset."); nodeInfoManager.ClearBlockchainDatabase(); Console.WriteLine("Blockchain database was successfully reset. Exiting."); return; } var nodeInfo = nodeInfoManager.CreateOrReadNodeInfo(); // Perform any migrations if there is any waiting. nodeInfoManager.PerformMigration(nodeInfo); IFullNode node; if (dnsSettings.DnsFullNode) { node = new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseBlockStore() .UseBlockExplorer() .UsePosConsensus() .UseMempool() .UseWallet() .AddPowPosMining() .UseApi() .UseDns() .AddRPC() .Build(); } else { node = new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseBlockStore() .UseBlockExplorer() .UsePosConsensus() .UseMempool() //.UseColdStakingWallet() .UseWallet() .AddPowPosMining() .UseApi() .UseApps() .AddRPC() .Build(); } if (node != null) { await node.RunAsync(); } } catch (Exception ex) { Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message); } }
/// <summary> /// City.Chain daemon can be launched with options to specify coin and network, using the parameters -chain and -testnet. It defaults to City main network. /// </summary> /// <example> /// dotnet city.chain.dll -coin bitcoin -network regtest /// dotnet city.chain.dll -coin city -network test /// </example> /// <param name="args"></param> /// <returns></returns> public static async Task Main(string[] args) { try { // Temporary enforce testnet if anyone launces without -testnet parameter. TODO: Remove before mainnet launch. args = args.Append("-testnet").ToArray(); // To avoid modifying Stratis source, we'll parse the arguments and set some hard-coded defaults for City Chain, like the ports. var configReader = new TextFileConfiguration(args ?? new string[] { }); var networkIdentifier = "main"; if (configReader.GetOrDefault <bool>("testnet", false)) { networkIdentifier = "testnet"; } else if (configReader.GetOrDefault <bool>("regtest", false)) { networkIdentifier = "regtest"; } // City Chain daemon supports multiple networks, supply the chain parameter to change it. // Example: -chain=bitcoin var chain = configReader.GetOrDefault <string>("chain", "city"); var networkConfiguration = new NetworkConfigurations().GetNetwork(networkIdentifier, chain); if (networkConfiguration == null) { throw new ArgumentException($"The supplied chain ({chain}) and network ({networkIdentifier}) parameters did not result in a valid network."); } var network = GetNetwork(networkConfiguration.Identifier, networkConfiguration.Chain); // Register the network found. NetworkRegistration.Register(network); if (args.Contains("-generate")) { GenerateAddressKeyPair(network); return; } args = args .Append("-apiport=" + networkConfiguration.ApiPort) .Append("-txindex=1") // Required for History (Block) explorer. .Append("-wsport=" + networkConfiguration.WsPort).ToArray(); var nodeSettings = new NodeSettings( args: args, protocolVersion: ProtocolVersion.ALT_PROTOCOL_VERSION, network: network, agent: "CityChain"); // Write the schema version, if not already exists. var infoPath = System.IO.Path.Combine(nodeSettings.DataDir, "city.info"); if (!System.IO.File.Exists(infoPath)) { // For clients earlier than this version, the database already existed so we'll // write that it is currently version 100. var infoBuilder = new System.Text.StringBuilder(); // If the chain exists from before, but we did not have .info file, the database is old version. if (System.IO.Directory.Exists(Path.Combine(nodeSettings.DataDir, "chain"))) { infoBuilder.AppendLine("dbversion=100"); } else { infoBuilder.AppendLine("dbversion=110"); } File.WriteAllText(infoPath, infoBuilder.ToString()); } else { var fileConfig = new TextFileConfiguration(File.ReadAllText(infoPath)); var dbversion = fileConfig.GetOrDefault <int>("dbversion", 110); } IFullNode node = new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseBlockStore() .UsePosConsensus() .UseMempool() .UseWallet() .AddPowPosMining() //.UseBlockNotification() //.UseTransactionNotification() //.AddSimpleWallet() .UseApi() //.UseApps() //.UseDns() .AddRPC() .Build(); if (node != null) { await node.RunAsync(); } } catch (Exception ex) { Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message); } }
public void AddNetworkConfiguration(NetworkConfiguration netConf) { NetworkConfigurations.Add(netConf); saveNetworkConfigurations(); }