/// <summary> /// Builds a node with POS miner and RPC enabled. /// </summary> /// <param name="dir">Data directory that the node should use.</param> /// <returns>Interface to the newly built node.</returns> /// <remarks>Currently the node built here does not actually stake as it has no coins in the wallet, /// but all the features required for it are enabled.</remarks> public static IFullNode BuildStakingNode(string dir, bool staking = true) { NodeSettings nodeSettings = new NodeSettings().LoadArguments(new string[] { $"-datadir={dir}", $"-stake={(staking ? 1 : 0)}", "-walletname=dummy", "-walletpassword=dummy" }); var fullNodeBuilder = new FullNodeBuilder(nodeSettings); IFullNode fullNode = fullNodeBuilder .UseStratisConsensus() .UseBlockStore() .UseMempool() .UseWallet() .AddPowPosMining() .AddRPC() .Build(); return(fullNode); }
public static async Task MainAsync(string[] args) { try { // Get the API uri. var apiUri = args.GetValueOf("apiuri"); var isTestNet = args.Contains("-testnet"); var isStratis = args.Contains("stratis"); var agent = "Breeze"; // This setting is not in NodeSettings yet, so get it directly from the args ConfigurationOptionWrapper <string> registrationStoreDirectory = new ConfigurationOptionWrapper <string>("RegistrationStoreDirectory", args.GetValueOf("-storedir")); NodeSettings nodeSettings; if (isStratis) { if (NodeSettings.PrintHelp(args, Network.StratisMain)) { return; } Network network = isTestNet ? Network.StratisTest : Network.StratisMain; if (isTestNet) { args = args.Append("-addnode=51.141.28.47").ToArray(); // TODO: fix this temp hack } nodeSettings = new NodeSettings("stratis", network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent).LoadArguments(args); nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultStratisUri : apiUri); } else { nodeSettings = new NodeSettings(agent: agent).LoadArguments(args); nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultBitcoinUri : apiUri); } IFullNodeBuilder fullNodeBuilder = null; if (args.Contains("light")) { fullNodeBuilder = new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseLightWallet() .UseWatchOnlyWallet() .UseBlockNotification() .UseTransactionNotification() .UseApi(); } else { fullNodeBuilder = new FullNodeBuilder() .UseNodeSettings(nodeSettings); if (args.Contains("stratis")) { fullNodeBuilder.UseStratisConsensus(); } else { fullNodeBuilder.UseConsensus(); } fullNodeBuilder.UseBlockStore() .UseMempool() .UseBlockNotification() .UseTransactionNotification() .UseWallet() .UseWatchOnlyWallet() .AddMining() .AddRPC() .UseApi(); } if (args.Contains("registration")) { //fullNodeBuilder.UseInterNodeCommunication(); fullNodeBuilder.UseRegistration(); } // Need this to happen for both TB and non-TB daemon Logs.Configure(new FuncLoggerFactory(i => new DualLogger(i, (a, b) => true, false))); // Start NTumbleBit logging to the console SetupTumbleBitConsoleLogs(nodeSettings); // Add logging to NLog //SetupTumbleBitNLogs(nodeSettings); // Currently TumbleBit is bitcoin only if (args.Contains("-tumblebit")) { // We no longer pass the URI in via the command line, the registration feature selects a random one fullNodeBuilder.UseTumbleBit(registrationStoreDirectory); } IFullNode node = fullNodeBuilder.Build(); // Start Full Node - this will also start the API. await node.RunAsync(); } catch (Exception ex) { Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message); } }