private void Application_Startup(object sender, StartupEventArgs e) { var args = ProcessArguments.ParseArguments(e.Args); var activeNetwork = args.IntendedNetwork; WalletClient.Initialize(); var appDataDir = Portability.LocalAppData(Environment.OSVersion.Platform, AssemblyResources.Organization, AssemblyResources.ProductName); Directory.CreateDirectory(appDataDir); var startupTask = Task.Run(async() => { // 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(appDataDir); var walletProcess = WalletProcess.Start(activeNetwork, appDataDir); 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(Tuple.Create(walletProcess, walletClient)); }); startupTask.Wait(); var startupResult = startupTask.Result; ActiveNetwork = activeNetwork; WalletRpcProcess = startupResult.Item1; WalletRpcClient = startupResult.Item2; Application.Current.Exit += Application_Exit; }
private async void Connect() { try { ConnectCommand.Executable = false; if (string.IsNullOrWhiteSpace(ConsensusServerNetworkAddress)) { MessageBox.Show("Network address is required"); return; } if (string.IsNullOrWhiteSpace(ConsensusServerRpcUsername)) { MessageBox.Show("RPC username is required"); return; } if (ConsensusServerRpcPassword.Length == 0) { MessageBox.Show("RPC password may not be empty"); return; } if (!File.Exists(ConsensusServerCertificateFile)) { MessageBox.Show("Certificate file not found"); return; } var rpcOptions = new ConsensusServerRpcOptions(ConsensusServerNetworkAddress, ConsensusServerRpcUsername, ConsensusServerRpcPassword, ConsensusServerCertificateFile); try { await App.Current.Synchronizer.WalletRpcClient.StartConsensusRpc(rpcOptions); } catch (Exception ex) when(ErrorHandling.IsTransient(ex) || ErrorHandling.IsClientError(ex)) { MessageBox.Show($"Unable to start {ConsensusServerRpcOptions.ApplicationName} RPC.\n\nCheck connection settings and try again.", "Error"); return; } await Task.Run(() => { // save defaults to a file so that the user doesn't have to type this information again var ini = new IniData(); ini.Sections.AddSection("Application Options"); ini["Application Options"]["rpcuser"] = ConsensusServerRpcUsername; ini["Application Options"]["rpcpass"] = ConsensusServerRpcPassword; ini["Application Options"]["rpclisten"] = ConsensusServerNetworkAddress; var appDataDir = Portability.LocalAppData(Environment.OSVersion.Platform, AssemblyResources.Organization, AssemblyResources.ProductName); var parser = new FileIniDataParser(); parser.WriteFile(Path.Combine(appDataDir, "defaults.ini"), ini); }); var walletExists = await App.Current.Synchronizer.WalletRpcClient.WalletExistsAsync(); if (!walletExists) { _wizard.CurrentDialog = new CreateOrImportSeedDialog(Wizard); } else { // TODO: Determine whether the public encryption is enabled and a prompt for the // public passphrase prompt is needed before the wallet can be opened. If it // does not, then the wallet can be opened directly here instead of creating // another dialog. _wizard.CurrentDialog = new PromptPublicPassphraseDialog(Wizard); //await _walletClient.OpenWallet("public"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { ConnectCommand.Executable = true; } }
private void Application_Startup(object sender, StartupEventArgs e) { // WPF defaults to using the en-US culture for all formatted bindings. // Override this with the system's current culture. FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); var args = ProcessArguments.ParseArguments(e.Args); var activeNetwork = args.IntendedNetwork; WalletClient.Initialize(); Directory.CreateDirectory(AppDataDir); // try to obtain some default rpc settings to autofill the startup dialogs with. // try paymetheus defaults first, and if that fails, look for a dcrd config. try { var iniParser = new FileIniDataParser(); IniData config = null; string defaultsFile = Path.Combine(AppDataDir, "defaults.ini"); if (File.Exists(defaultsFile)) { config = iniParser.ReadFile(defaultsFile); } else { var consensusRpcAppData = Portability.LocalAppData(Environment.OSVersion.Platform, "", ConsensusServerRpcOptions.ApplicationName); var consensusRpcConfig = ConsensusServerRpcOptions.ApplicationName + ".conf"; var consensusConfigFilePath = Path.Combine(consensusRpcAppData, consensusRpcConfig); if (File.Exists(consensusConfigFilePath)) { config = iniParser.ReadFile(consensusConfigFilePath); } } if (config != null) { // Settings can be found in either the Application Options or global sections. var section = config["Application Options"]; if (section == null) { section = config.Global; } var rpcUser = section["rpcuser"] ?? ""; var rpcPass = section["rpcpass"] ?? ""; var rpcListen = section["rpclisten"] ?? ""; var rpcCert = section["rpccert"] ?? ""; // rpclisten and rpccert can be filled with sensible defaults when empty. user and password can not. if (rpcListen == "") { rpcListen = "127.0.0.1"; } if (rpcCert == "") { var localCertPath = ConsensusServerRpcOptions.LocalCertificateFilePath(); if (File.Exists(localCertPath)) { rpcCert = localCertPath; } } DefaultCSRPO = new ConsensusServerRpcOptions(rpcListen, rpcUser, rpcPass, rpcCert); } } catch { } // Ignore any errors, this will just result in leaving defaults empty. var syncTask = Task.Run(async() => { return(await SynchronizerViewModel.Startup(activeNetwork, AppDataDir, args.SearchPathForWalletProcess, args.ExtraWalletArgs)); }); var synchronizer = syncTask.Result; SingletonViewModelLocator.RegisterInstance("Synchronizer", synchronizer); ActiveNetwork = activeNetwork; Synchronizer = synchronizer; Current.Exit += Application_Exit; }
private async void Connect() { try { ConnectCommand.Executable = false; if (string.IsNullOrWhiteSpace(ConsensusServerNetworkAddress)) { MessageBox.Show("Network address is required"); return; } if (string.IsNullOrWhiteSpace(ConsensusServerRpcUsername)) { MessageBox.Show("RPC username is required"); return; } if (ConsensusServerRpcPassword.Length == 0) { MessageBox.Show("RPC password may not be empty"); return; } if (!File.Exists(ConsensusServerCertificateFile)) { MessageBox.Show("Certificate file not found"); return; } var walletClient = App.Current.Synchronizer.WalletRpcClient; var rpcOptions = new ConsensusServerRpcOptions(ConsensusServerNetworkAddress, ConsensusServerRpcUsername, ConsensusServerRpcPassword, ConsensusServerCertificateFile); try { await walletClient.StartConsensusRpc(rpcOptions); } catch (RpcException ex) when(ex.Status.StatusCode == StatusCode.NotFound) { var msg = string.Format("Unable to connect to {0}.\n\nConnection could not be established with `{1}`.", ConsensusServerRpcOptions.ApplicationName, ConsensusServerNetworkAddress); MessageBox.Show(msg, "Error"); return; } catch (Exception ex) when(ErrorHandling.IsTransient(ex) || ErrorHandling.IsClientError(ex)) { MessageBox.Show($"Unable to connect to {ConsensusServerRpcOptions.ApplicationName}.\n\nCheck authentication settings and try again.", "Error"); return; } await Task.Run(() => { // save defaults to a file so that the user doesn't have to type this information again var ini = new IniData(); ini.Sections.AddSection("Application Options"); ini["Application Options"]["rpcuser"] = ConsensusServerRpcUsername; ini["Application Options"]["rpcpass"] = ConsensusServerRpcPassword; ini["Application Options"]["rpclisten"] = ConsensusServerNetworkAddress; ini["Application Options"]["rpccert"] = ConsensusServerCertificateFile; var appDataDir = Portability.LocalAppData(Environment.OSVersion.Platform, AssemblyResources.Organization, AssemblyResources.ProductName); var parser = new FileIniDataParser(); parser.WriteFile(Path.Combine(appDataDir, "defaults.ini"), ini); }); var walletExists = await walletClient.WalletExistsAsync(); if (!walletExists) { _wizard.CurrentDialog = new PickCreateOrImportSeedDialog(Wizard); } else { // Attempt to open the wallet without any public passphrase. If this succeeds, // continue by syncing the wallet. Otherwise, prompt for the public passphrase. try { await walletClient.OpenWallet(""); _wizard.CurrentDialog = new OpenExistingWalletActivityProgress(Wizard); } catch (RpcException ex) when(ex.Status.StatusCode == StatusCode.InvalidArgument) { _wizard.CurrentDialog = new PromptPublicPassphraseDialog(Wizard); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { ConnectCommand.Executable = true; } }