Exemplo n.º 1
0
 public async Task StartConsensusRpc(ConsensusServerRpcOptions options)
 {
     var certificateTask = ReadFileAsync(options.CertificatePath);
     var client          = WalletLoaderService.NewClient(_channel);
     var request         = new StartConsensusRpcRequest
     {
         NetworkAddress = options.NetworkAddress,
         Username       = options.RpcUser,
         Password       = ByteString.CopyFromUtf8(options.RpcPassword),
         Certificate    = ByteString.CopyFrom(await certificateTask),
     };
     await client.StartConsensusRpcAsync(request, cancellationToken : _tokenSource.Token);
 }
Exemplo n.º 2
0
        public ConsensusServerRpcConnectionDialog(StartupWizard wizard, ConsensusServerRpcOptions csro = null) : base(wizard)
        {
            ConnectCommand = new DelegateCommand(Connect);

            // Apply any discovered RPC defaults.
            if (csro != null)
            {
                ConsensusServerNetworkAddress = csro.NetworkAddress;
                ConsensusServerRpcUsername = csro.RpcUser;
                ConsensusServerRpcPassword = csro.RpcPassword;
                ConsensusServerCertificateFile = csro.CertificatePath;
            }
        }
Exemplo n.º 3
0
 public async Task StartConsensusRpc(ConsensusServerRpcOptions options)
 {
     var certificateTask = ReadFileAsync(options.CertificatePath);
     var client = new WalletLoaderService.WalletLoaderServiceClient(_channel);
     var request = new StartConsensusRpcRequest
     {
         NetworkAddress = options.NetworkAddress,
         Username = options.RpcUser,
         Password = ByteString.CopyFromUtf8(options.RpcPassword),
         Certificate = ByteString.CopyFrom(await certificateTask),
     };
     await client.StartConsensusRpcAsync(request, cancellationToken: _tokenSource.Token);
 }
Exemplo n.º 4
0
        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();

            var appDataDir = Portability.LocalAppData(Environment.OSVersion.Platform,
                AssemblyResources.Organization, AssemblyResources.ProductName);

            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;
        }
Exemplo n.º 5
0
        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 (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 App.Current.Synchronizer.WalletRpcClient.WalletExistsAsync();
                if (!walletExists)
                {
                    _wizard.CurrentDialog = new PickCreateOrImportSeedDialog(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;
            }
        }
Exemplo n.º 6
0
 public StartupWizard(ShellViewModelBase shell, ConsensusServerRpcOptions csro = null) : base()
 {
     CurrentDialog = new ConsensusServerRpcConnectionDialog(this, csro);
 }
Exemplo n.º 7
0
        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.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");
                    MessageBox.Show(ex.Message);
                    return;
                }

                var walletExists = await App.Current.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;
            }
        }