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);
public async Task RunAsync(IExpressStore store, ExpressConsensusNode node, uint secondsPerBlock, bool enableTrace, TextWriter writer, CancellationToken token) { if (IsRunning(node)) { throw new Exception("Node already running"); } chain.InitalizeProtocolSettings(secondsPerBlock); await writer.WriteLineAsync(store.GetType().Name).ConfigureAwait(false); var tcs = new TaskCompletionSource <bool>(); _ = Task.Run(() => { try { var defaultAccount = node.Wallet.Accounts.Single(a => a.IsDefault); using var mutex = new Mutex(true, GLOBAL_PREFIX + defaultAccount.ScriptHash); var wallet = DevWallet.FromExpressWallet(node.Wallet); var multiSigAccount = node.Wallet.Accounts.Single(a => a.IsMultiSigContract()); var dbftPlugin = new Neo.Consensus.DBFTPlugin(); var logPlugin = new Node.LogPlugin(writer); var storageProvider = new Node.ExpressStorageProvider((IStore)store); var appEngineProvider = enableTrace ? new Node.ExpressApplicationEngineProvider() : null; var appLogsPlugin = new Node.ExpressAppLogsPlugin(store); using var system = new Neo.NeoSystem(storageProvider.Name); var rpcSettings = new Neo.Plugins.RpcServerSettings(port: node.RpcPort); var rpcServer = new Neo.Plugins.RpcServer(system, rpcSettings); var expressRpcServer = new ExpressRpcServer(store, multiSigAccount); rpcServer.RegisterMethods(expressRpcServer); rpcServer.RegisterMethods(appLogsPlugin); rpcServer.StartRpcServer(); system.StartNode(new Neo.Network.P2P.ChannelsConfig { Tcp = new IPEndPoint(IPAddress.Loopback, node.TcpPort), WebSocket = new IPEndPoint(IPAddress.Loopback, node.WebSocketPort), }); dbftPlugin.Start(wallet); token.WaitHandle.WaitOne(); } catch (Exception ex) { tcs.SetException(ex); } finally { tcs.TrySetResult(true); } }); await tcs.Task.ConfigureAwait(false); }
public static Task RunAsync(Store store, ExpressConsensusNode node, TextWriter writer, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <bool>(); Task.Run(() => { try { var wallet = DevWallet.FromExpressWallet(node.Wallet); using (var system = new NeoSystem(store)) { var logPlugin = new LogPlugin(writer); var rpcPlugin = new ExpressNodeRpcPlugin(store); system.StartNode(node.TcpPort, node.WebSocketPort); system.StartConsensus(wallet); system.StartRpc(IPAddress.Loopback, node.RpcPort, wallet); { using var snapshot = Blockchain.Singleton.GetSnapshot(); var validators = snapshot.GetValidators(); ; } cancellationToken.WaitHandle.WaitOne(); } } catch (Exception ex) { tcs.SetException(ex); } finally { if (store is IDisposable disposable) { disposable.Dispose(); } tcs.TrySetResult(true); } }); return(tcs.Task); }