private void btnStartMining_Click(object sender, EventArgs e)
        {
            var curDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            if (btnStartMining.Text == "Start Mining")
            {
                StringBuilder outputBuilder = new StringBuilder();
                btnStartMining.Text = "Stop Mining";

                var miningexe = System.IO.Path.Combine(curDir, "xmr-stak.exe");

                var conflictingProcesses    = Process.GetProcessesByName("xmr-stak").ToArray();
                int numConflictingProcesses = conflictingProcesses.Length;

                for (int i = 0; i < numConflictingProcesses; i++)
                {
                    /* Need to kill any existing miners to ensure we get max possible hash rate here */
                    conflictingProcesses[i].Kill();
                }
                var     address = myAddressText.Text;
                Process p       = new Process();
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                p.StartInfo.FileName  = miningexe;
                p.OutputDataReceived += CaptureOutput;
                p.StartInfo.Arguments = CLIEncoder.Encode(new string[] { "-o", comboBox1.Text + ":" + txtPoolPort.Text, "-u", address, "-p", "plegui", "--currency", "plenteum", "-r", "plegui", "-i", "7659" });

                int maxConnectionAttempts = 5;

                /* It takes a small amount of time to kill the other processes
                 * if needed, so lets try and connect a few times before failing. */

                for (int i = 0; i < maxConnectionAttempts; i++)
                {
                    if (!minerRunning)
                    {
                        p.Start();

                        System.Threading.Thread.Sleep(1500);
                        if (!p.HasExited)
                        {
                            p.BeginOutputReadLine();
                            //p.WaitForExit();
                            minerRunning = true;
                        }
                    }
                }
                Thread.Sleep(2000);
                if (minerRunning)
                {
                    //first, get Url output to file...
                    GetMinerStats();
                    webBrowser1.Url = new Uri(String.Format("file:///{0}/h.html", curDir));
                    if (checkBoxRefresh.Checked)
                    {
                        minerRefreshTimer.Enabled = true;
                    }
                    //ToDO: Split Tab view with Page showing Pool Stats and Miner Stats from XMR Stak
                    //TODO: Refresh Timer
                }
            }
            else
            {
                //kill mining process and change button text
                btnStartMining.Text = "Start Mining";

                var conflictingProcesses    = Process.GetProcessesByName("xmr-stak").ToArray();
                int numConflictingProcesses = conflictingProcesses.Length;

                for (int i = 0; i < numConflictingProcesses; i++)
                {
                    /* Kill the mining processes on request */
                    conflictingProcesses[i].Kill();
                }
                minerRunning = false;
                txtMinerOutput.Clear(); //clear mining round output
                minerRefreshTimer.Enabled = false;

                this.webBrowser1.Url = new Uri(String.Format("file:///{0}/offline.html", curDir));
            }
        }
        public static Tuple <bool, string, Process> StartDaemon(string wallet, string pass)
        {
            var curDir     = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var serviceexe = System.IO.Path.Combine(curDir, "wallet-service.exe");

            if (IsRunningOnMono())
            {
                serviceexe = System.IO.Path.Combine(curDir, "wallet-service");
            }

            if (!System.IO.File.Exists(wallet))
            {
                return(Tuple.Create <bool, string, Process>(false, "Wallet file cannot be found! Must exit!", null));
            }

            var conflictingProcesses    = Process.GetProcessesByName("wallet-service").ToArray();
            int numConflictingProcesses = conflictingProcesses.Length;

            for (int i = 0; i < numConflictingProcesses; i++)
            {
                /* Need to kill all service and Plenteumd processes so
                 * they don't lock the DB */
                conflictingProcesses[i].Kill();
            }



            /* Delete service.log if it exists so we can ensure when reading
             * the file later upon a crash, that we are reporting the proper
             * crash reason and not some previous crash */
            System.IO.File.Delete("wallet-service.log");

            Process p = new Process();

            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            p.StartInfo.FileName       = serviceexe;

            var daemonProcess = Process.GetProcessesByName("Plenteumd").ToArray();

            if (!daemonProcess.Any())
            {
                //There's no local daemon process running, so start service with a remote node
                //gui.plenteum.com -round-robin DNS
                p.StartInfo.Arguments = CLIEncoder.Encode(new string[] { "-w", wallet, "-p", pass, "--rpc-password", _rpcRand, "--daemon-address", Properties.Settings.Default.deIP, "--daemon-port", Properties.Settings.Default.dePort });
            }
            else
            {
                //there's a local daemon process running already, so start the wallet service linked to that
                p.StartInfo.Arguments = CLIEncoder.Encode(new string[] { "-w", wallet, "-p", pass, "--rpc-password", _rpcRand, "--daemon-address", "127.0.0.1", "--daemon-port", "44016" });
            }

            int maxConnectionAttempts = 5;

            /* It takes a small amount of time to kill the other processes
             * if needed, so lets try and connect a few times before failing. */
            for (int i = 0; i < maxConnectionAttempts; i++)
            {
                p.Start();
                System.Threading.Thread.Sleep(1500);

                if (!p.HasExited)
                {
                    return(Tuple.Create <bool, string, Process>(true, "", p));
                }
            }

            return(Tuple.Create <bool, string, Process>(false, "Unable to keep daemon up!", null));
        }
Exemple #3
0
        private void CreateWallet()
        {
            var curDir      = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var _walletFile = System.IO.Path.Combine(curDir, walletNameText.Text + ".wallet");

            if (walletNameText.Text == "")
            {
                MessageBox.Show("Please enter a valid wallet name", "Plenteum Wallet Creation");
                return;
            }
            else if (walletNameText.Text.Any(c => !Char.IsLetterOrDigit(c)))
            {
                MessageBox.Show("Wallet name cannot contain special characters", "Plenteum Wallet Creation");
                return;
            }
            else if (System.IO.File.Exists(_walletFile))
            {
                MessageBox.Show("A wallet with that name already exists! Choose a different name or choose the \"Select Existing Wallet\" option instead.", "Plenteum Wallet Creation");
                return;
            }

            if (passwordText.Text == "")
            {
                MessageBox.Show("Please enter a valid password", "Plenteum Wallet Creation");
                return;
            }
            else if (passwordText.Text.Length < 6)
            {
                MessageBox.Show("Please enter a password that is larger than 6 characters", "Plenteum Wallet Creation");
                return;
            }
            else if (passwordText.Text.Length > 150)
            {
                MessageBox.Show("Passwords cannot be longer than 150 characters!", "Plenteum Wallet Creation");
                return;
            }

            if (passwordText.Text != passwordConfirmText.Text)
            {
                MessageBox.Show("Passwords do not match", "Plenteum Wallet Creation");
                return;
            }

            var serviceexe = System.IO.Path.Combine(curDir, "wallet-service.exe");

            if (IsRunningOnMono())
            {
                serviceexe = System.IO.Path.Combine(curDir, "wallet-service");
            }

            if (!System.IO.File.Exists(serviceexe))
            {
                MessageBox.Show("The 'wallet-service' daemon is missing from the folder the wallet is currently running from! Please place 'service' next to your wallet exe and run again!", "Plenteum Wallet Creation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utilities.SetDialogResult(this, DialogResult.Abort);
                Utilities.Close(this);
            }

            createProgressbar.Visible = true;
            StringBuilder tmpstdout = new StringBuilder();

            try
            {
                Process p = new Process();
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                p.StartInfo.FileName  = serviceexe;
                p.StartInfo.Arguments = CLIEncoder.Encode(new string[] { "-w", _walletFile, "-p", passwordText.Text, "-g" });
                p.OutputDataReceived += (sender, args) => tmpstdout.AppendLine(args.Data);
                p.Start();
                p.BeginOutputReadLine();
                p.WaitForExit(10000);
                p.CancelOutputRead();

                if (!System.IO.File.Exists(_walletFile))
                {
                    MessageBox.Show("Wallet failed to create after communicating with daemon. Please reinstall the wallet, close any other wallets you may have open, and try again", "Plenteum Wallet Creation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Utilities.SetDialogResult(this, DialogResult.Abort);
                    Utilities.Close(this);
                }
                else
                {
                    WalletPath     = _walletFile;
                    WalletPassword = passwordText.Text;
                    MessageBox.Show("Wallet successfully created at: " + Environment.NewLine + _walletFile + Environment.NewLine + "IMPORTANT:" + Environment.NewLine + "As soon as the main GUI to the wallet opens, you should proceed to the 'BACKUP KEYS' tab to save your secret and view key in case of wallet failure in the future!", "Plenteum Wallet Creation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Utilities.SetDialogResult(this, DialogResult.OK);
                    Utilities.Close(this);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An exception occured while attempting to create the wallet." + Environment.NewLine + "Error:" + Environment.NewLine + ex.Message, "Plenteum Wallet Creation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utilities.SetDialogResult(this, DialogResult.Abort);
                Utilities.Close(this);
            }
        }