public async Task RunAsync(IStorageProvider store, ExpressConsensusNode node, bool enableTrace, TextWriter writer, CancellationToken token) { if (IsNodeRunning(node)) { throw new Exception("Node already running"); } var tcs = new TaskCompletionSource <bool>(); _ = Task.Run(() => { try { var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(token); var defaultAccount = node.Wallet.Accounts.Single(a => a.IsDefault); using var mutex = new Mutex(true, GLOBAL_PREFIX + defaultAccount.ScriptHash); var wallet = DevWallet.FromExpressWallet(ProtocolSettings, node.Wallet); var multiSigAccount = wallet.GetMultiSigAccounts().Single(); var logPlugin = new Node.LogPlugin(writer); var storageProviderPlugin = new Node.StorageProviderPlugin(store); var appEngineProvider = enableTrace ? new Node.ApplicationEngineProvider() : null; var dbftPlugin = new Neo.Consensus.DBFTPlugin(GetConsensusSettings(chain)); var persistencePlugin = new Node.PersistencePlugin(store); using var neoSystem = new Neo.NeoSystem(ProtocolSettings, storageProviderPlugin.Name); _ = neoSystem.ActorSystem.ActorOf(EventWrapper <Blockchain.ApplicationExecuted> .Props(OnApplicationExecuted)); var rpcSettings = GetRpcServerSettings(chain, node); var rpcServer = new Neo.Plugins.RpcServer(neoSystem, rpcSettings); var expressRpcMethods = new ExpressRpcMethods(neoSystem, store, multiSigAccount.ScriptHash, linkedToken); rpcServer.RegisterMethods(expressRpcMethods); rpcServer.RegisterMethods(persistencePlugin); rpcServer.StartRpcServer(); neoSystem.StartNode(new Neo.Network.P2P.ChannelsConfig { Tcp = new IPEndPoint(IPAddress.Loopback, node.TcpPort), WebSocket = new IPEndPoint(IPAddress.Loopback, node.WebSocketPort), }); dbftPlugin.Start(wallet); // DevTracker looks for a string that starts with "Neo express is running" to confirm that the instance has started // Do not remove or re-word this console output: writer.WriteLine($"Neo express is running ({store.GetType().Name})"); linkedToken.Token.WaitHandle.WaitOne(); } catch (Exception ex) { tcs.SetException(ex); } finally { tcs.TrySetResult(true); } }); await tcs.Task.ConfigureAwait(false);
static void RunMain(string[] args) { Parser clp = new Parser(); _parsed = clp.ParseArguments <CLSettings>(args); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); XDocument xdoc = null; try { xdoc = XDocument.Load("https://neo.org/client/update.xml"); } catch { } if (xdoc != null) { Version version = Assembly.GetExecutingAssembly().GetName().Version; Version minimum = Version.Parse(xdoc.Element("update").Attribute("minimum").Value); if (version < minimum) { using (UpdateDialog dialog = new UpdateDialog(xdoc)) { dialog.ShowDialog(); } return; } } if (!InstallCertificate()) { return; } using (LevelDBStore store = new LevelDBStore(Settings.Default.Paths.Chain)) using (NeoSystem = new NeoSystem(store)) { Application.Run(MainForm = new MainForm(xdoc)); } }