public static async Task <SynchronizerViewModel> Startup(BlockChainIdentity activeNetwork, string walletAppDataDir,
                                                                 bool searchPath, string extraArgs)
        {
            if (activeNetwork == null)
            {
                throw new ArgumentNullException(nameof(activeNetwork));
            }
            if (walletAppDataDir == null)
            {
                throw new ArgumentNullException(nameof(walletAppDataDir));
            }
            if (extraArgs == null)
            {
                throw new ArgumentNullException(nameof(extraArgs));
            }

            // Begin the asynchronous reading of the certificate before starting the wallet
            // process.  This uses filesystem events to know when to begin reading the certificate,
            // and if there is too much delay between wallet writing the cert and this process
            // beginning to observe the change, the event may never fire and the cert won't be read.
            var rootCertificateTask = TransportSecurity.ReadModifiedCertificateAsync(walletAppDataDir);

            string walletProcessPath = null;

            if (!searchPath)
            {
                walletProcessPath = Portability.ExecutableInstallationPath(
                    Environment.OSVersion.Platform, AssemblyResources.Organization, WalletProcess.ProcessName);
            }
            KillLeftoverWalletProcess(activeNetwork);
            var walletProcess = WalletProcess.Start(activeNetwork, walletAppDataDir, walletProcessPath, extraArgs);

            WalletClient walletClient;

            try
            {
                var listenAddress   = WalletProcess.RpcListenAddress("localhost", activeNetwork);
                var rootCertificate = await rootCertificateTask;
                walletClient = await WalletClient.ConnectAsync(listenAddress, rootCertificate);
            }
            catch (Exception)
            {
                if (walletProcess.HasExited)
                {
                    throw new Exception("Wallet process closed unexpectedly");
                }
                walletProcess.KillIfExecuting();
                throw;
            }

            return(new SynchronizerViewModel(walletProcess, walletClient));
        }
Esempio n. 2
0
        public void LaunchPaymetheus()
        {
            if (Interlocked.Exchange(ref _paymetheusProcessStarted, 1) != 0)
            {
                throw new InvalidOperationException("Paymetheus already started");
            }

            const string processName = "Paymetheus";
            var          fileName    = processName;

            if (!parsedArguments.SearchPathForProcesses)
            {
                fileName = Portability.ExecutableInstallationPath(Environment.OSVersion.Platform, "Decred", processName);
            }

            var procInfo = new ProcessStartInfo
            {
                FileName        = fileName,
                Arguments       = string.Join(" ", arguments), // pass arguments vertabim
                UseShellExecute = false,
            };

            _paymetheusProcess = Process.Start(procInfo);

            // For now only hide the launcher when running on mainnet.
            if (parsedArguments.IntendedNetwork == BlockChainIdentity.MainNet)
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    App.Current.MainWindow.Hide();
                });
            }

            Task.Run(async() =>
            {
                await _paymetheusProcess.WaitForExitAsync();
                if (parsedArguments.IntendedNetwork == BlockChainIdentity.MainNet)
                {
                    await App.Current.Dispatcher.InvokeAsync(() =>
                    {
                        App.Current.MainWindow.Show();
                    });
                }
                SignalConsensusServerShutdown();
            });
        }
Esempio n. 3
0
        public void LaunchConcensusServer(out AnonymousPipeServerStream rx, out AnonymousPipeServerStream tx)
        {
            if (Interlocked.Exchange(ref _consensusServerStarted, 1) != 0)
            {
                throw new InvalidOperationException("Consensus server already started");
            }

            const string processName = "dcrd";
            var          fileName    = processName;

            if (!parsedArguments.SearchPathForProcesses)
            {
                fileName = Portability.ExecutableInstallationPath(Environment.OSVersion.Platform, "Decred", processName);
            }

            var procInfo = new ProcessStartInfo
            {
                FileName        = fileName,
                Arguments       = $"--piperx {_outPipe.GetClientHandleAsString()} --pipetx {_inPipe.GetClientHandleAsString()} --lifetimeevents",
                CreateNoWindow  = parsedArguments.IntendedNetwork == BlockChainIdentity.MainNet, // only hide on mainnet
                UseShellExecute = false,
            };

            if (parsedArguments.IntendedNetwork != BlockChainIdentity.MainNet)
            {
                procInfo.Arguments += $" --{parsedArguments.IntendedNetwork.Name}";
            }

            _consensusServerProcess = Process.Start(procInfo);

            rx = _inPipe;
            tx = _outPipe;

            Task.Run(async() =>
            {
                var exitCode = await _consensusServerProcess.WaitForExitAsync();
                if (exitCode != 0)
                {
                    MessageBox.Show($"Consensus server exited with code {exitCode}");
                }
                await Application.Current.Dispatcher.InvokeAsync(Application.Current.Shutdown);
            });
        }