public static Tuple <bool, string, Process> StartDaemon(string wallet, string pass)
        {
            var curDir     = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var walletdexe = System.IO.Path.Combine(curDir, "walletd.exe");

            if (IsRunningOnMono())
            {
                walletdexe = System.IO.Path.Combine(curDir, "walletd");
            }

            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("walletd")
                                       .Concat(Process.GetProcessesByName("Worktipsd")).ToArray();

            int numConflictingProcesses = conflictingProcesses.Length;

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

            /* Delete walletd.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("walletd.log");

            Process p = new Process();

            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            p.StartInfo.FileName       = walletdexe;
            p.StartInfo.Arguments      = CLIEncoder.Encode(new string[] { "-w", wallet, "-p", pass, "--local", "--rpc-password", _rpcRand });

            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));
        }
        private void ImportWallet()
        {
            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", "Worktips Wallet Import");
                return;
            }
            else if (walletNameText.Text.Any(c => !Char.IsLetterOrDigit(c)))
            {
                MessageBox.Show("Wallet name cannot contain special characters", "Worktips Wallet Import");
                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.", "Worktips Wallet Import");
                return;
            }

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

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

            if (viewSecretKeyText.Text.Length != 64 || spendSecretKeyText.Text.Length != 64)
            {
                MessageBox.Show("View key or spend key is incorrect length! Should be 64 characters long.", "Worktips Wallet Import");
                return;
            }

            var walletdexe = System.IO.Path.Combine(curDir, "walletd.exe");

            if (IsRunningOnMono())
            {
                walletdexe = System.IO.Path.Combine(curDir, "walletd");
            }

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

            importProgressbar.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 = walletdexe;

                p.StartInfo.Arguments = CLIEncoder.Encode(new string[]
                                                          { "-w", _walletFile, "-p", passwordText.Text, "--view-key",
                                                            viewSecretKeyText.Text, "--spend-key", spendSecretKeyText.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 import after communicating with daemon. Please ensure your secret keys are correct, and open walletd.log for more information on what went wrong, if it exists.", "Worktips Wallet Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Utilities.SetDialogResult(this, DialogResult.Abort);
                    Utilities.Close(this);
                }
                else
                {
                    ImportWalletPath     = _walletFile;
                    ImportWalletPassword = passwordText.Text;
                    MessageBox.Show("Wallet successfully imported at: " + Environment.NewLine + _walletFile, "Worktips Wallet Import", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Utilities.SetDialogResult(this, DialogResult.OK);
                    Utilities.Close(this);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An exception occured while attempting to import the wallet." + Environment.NewLine + "Error:" + Environment.NewLine + ex.Message, "Worktips Wallet Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utilities.SetDialogResult(this, DialogResult.Abort);
                Utilities.Close(this);
            }
        }
        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", "Worktips Wallet Creation");
                return;
            }
            else if (walletNameText.Text.Any(c => !Char.IsLetterOrDigit(c)))
            {
                MessageBox.Show("Wallet name cannot contain special characters", "Worktips 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.", "Worktips Wallet Creation");
                return;
            }

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

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

            var walletdexe = System.IO.Path.Combine(curDir, "walletd.exe");

            if (IsRunningOnMono())
            {
                walletdexe = System.IO.Path.Combine(curDir, "walletd");
            }

            if (!System.IO.File.Exists(walletdexe))
            {
                MessageBox.Show("The 'walletd' daemon is missing from the folder the wallet is currently running from! Please place 'walletd' next to your wallet exe and run again!", "Worktips 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  = walletdexe;
                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", "Worktips 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!", "Worktips 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, "Worktips Wallet Creation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utilities.SetDialogResult(this, DialogResult.Abort);
                Utilities.Close(this);
            }
        }