From c2990afed38e474275c6fc7104ae3c2dd7d85e0d Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 9 Jun 2023 16:02:16 +1000 Subject: [PATCH] main: Added option to run HSD internally --- FireWallet/MainForm.cs | 91 ++++++++++++++++++++++++++++----- FireWallet/NodeForm.Designer.cs | 13 +++++ FireWallet/NodeForm.cs | 34 ++++++++---- 3 files changed, 114 insertions(+), 24 deletions(-) diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index b548f58..fa3887e 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -31,7 +31,9 @@ namespace FireWallet public bool batchMode { get; set; } public BatchForm batchForm { get; set; } public bool watchOnly { get; set; } + public bool HSD { get; set; } + public Process hsdProcess { get; set; } #endregion #region Application public MainForm() @@ -84,6 +86,22 @@ namespace FireWallet private void MainForm_Closing(object sender, FormClosingEventArgs e) { AddLog("Closing"); + if (hsdProcess != null) + { + this.Hide(); + hsdProcess.Kill(); + AddLog("HSD Closed"); + Thread.Sleep(1000); + + try + { + hsdProcess.Dispose(); + } + catch + { + AddLog("Dispose failed"); + } + } } #endregion @@ -91,8 +109,9 @@ namespace FireWallet #region Settings - private void LoadNode() + private async void LoadNode() { + HSD = false; if (!File.Exists(dir + "node.txt")) { NodeForm cf = new NodeForm(); @@ -137,6 +156,52 @@ namespace FireWallet toolStripStatusLabelNetwork.Text = "Network: Testnet"; break; } + + if (nodeSettings.ContainsKey("HSD")) + { + if (nodeSettings["HSD"].ToLower() == "true") + { + HSD = true; + AddLog("Starting HSD"); + toolStripStatusLabelstatus.Text = "Status: HSD Starting"; + + if (!Directory.Exists(dir + "hsd")) + { + NotifyForm Notifyinstall = new NotifyForm("Installing hsd\nThis may take a few minutes\nDo not close FireWallet", false); + Notifyinstall.Show(); + // Wait for the notification to show + await Task.Delay(1000); + + string repositoryUrl = "https://github.com/handshake-org/hsd.git"; + string destinationPath = dir + "hsd"; + CloneRepository(repositoryUrl, destinationPath); + + Notifyinstall.CloseNotification(); + Notifyinstall.Dispose(); + } + hsdProcess = new Process(); + + hsdProcess.StartInfo.CreateNoWindow = true; + + hsdProcess.StartInfo.RedirectStandardInput = true; + hsdProcess.StartInfo.RedirectStandardOutput = false; + hsdProcess.StartInfo.UseShellExecute = false; + hsdProcess.StartInfo.RedirectStandardError = false; + hsdProcess.StartInfo.FileName = "node.exe"; + hsdProcess.StartInfo.Arguments = dir + "hsd/bin/hsd --index-tx --index-address --api-key" + nodeSettings["Key"]; + + string bobPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Bob\\hsd_data"; + if (Directory.Exists(bobPath)) + { + hsdProcess.StartInfo.Arguments = hsdProcess.StartInfo.Arguments + " --prefix " + bobPath; + } + hsdProcess.Start(); + + + + } + } + NodeStatus(); @@ -1187,21 +1252,19 @@ namespace FireWallet pNpmRunDist.StandardInput.WriteLine("npm install & exit"); pNpmRunDist.WaitForExit(); + if (repositoryUrl == "https://github.com/handshake-org/hsd-ledger.git") + { + // Replace /bin/hsd-ledger with /bin/hsd-ledger from + // https://raw.githubusercontent.com/Nathanwoodburn/FireWallet/master/hsd-ledger + // This version of hsd-ledger has the sendraw transaction function added which is needed for batching - // Replace /bin/hsd-ledger with /bin/hsd-ledger from - // https://raw.githubusercontent.com/Nathanwoodburn/FireWallet/master/hsd-ledger - // This version of hsd-ledger has the sendraw transaction function added which is needed for batching - - string sourcePath = destinationPath + "\\bin\\hsd-ledger"; - File.Delete(sourcePath); - - // Download the new hsd-ledger - WebClient downloader = new WebClient(); - downloader.DownloadFile("https://raw.githubusercontent.com/Nathanwoodburn/FireWallet/master/hsd-ledger", sourcePath); - - - + string sourcePath = destinationPath + "\\bin\\hsd-ledger"; + File.Delete(sourcePath); + // Download the new hsd-ledger + WebClient downloader = new WebClient(); + downloader.DownloadFile("https://raw.githubusercontent.com/Nathanwoodburn/FireWallet/master/hsd-ledger", sourcePath); + } } catch (Exception ex) { diff --git a/FireWallet/NodeForm.Designer.cs b/FireWallet/NodeForm.Designer.cs index 88902d2..62ef6f4 100644 --- a/FireWallet/NodeForm.Designer.cs +++ b/FireWallet/NodeForm.Designer.cs @@ -36,6 +36,7 @@ namespace FireWallet System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NodeForm)); labelWelcome = new Label(); groupBoxNode = new GroupBox(); + checkBoxRunHSD = new CheckBox(); labelNodeStatus = new Label(); comboBoxNodeNetwork = new ComboBox(); buttonSave = new Button(); @@ -61,6 +62,7 @@ namespace FireWallet // // groupBoxNode // + groupBoxNode.Controls.Add(checkBoxRunHSD); groupBoxNode.Controls.Add(labelNodeStatus); groupBoxNode.Controls.Add(comboBoxNodeNetwork); groupBoxNode.Controls.Add(buttonSave); @@ -77,6 +79,16 @@ namespace FireWallet groupBoxNode.TabStop = false; groupBoxNode.Text = "Node"; // + // checkBoxRunHSD + // + checkBoxRunHSD.AutoSize = true; + checkBoxRunHSD.Location = new Point(62, 100); + checkBoxRunHSD.Name = "checkBoxRunHSD"; + checkBoxRunHSD.Size = new Size(304, 19); + checkBoxRunHSD.TabIndex = 10; + checkBoxRunHSD.Text = "Run HSD (use this if you don't want to run Bob/HSD)"; + checkBoxRunHSD.UseVisualStyleBackColor = true; + // // labelNodeStatus // labelNodeStatus.AutoSize = true; @@ -193,5 +205,6 @@ namespace FireWallet private Button buttonSave; private ComboBox comboBoxNodeNetwork; private Label labelNodeStatus; + private CheckBox checkBoxRunHSD; } } \ No newline at end of file diff --git a/FireWallet/NodeForm.cs b/FireWallet/NodeForm.cs index b0a1e3a..e86fdaa 100644 --- a/FireWallet/NodeForm.cs +++ b/FireWallet/NodeForm.cs @@ -278,18 +278,32 @@ namespace FireWallet private void SaveSettings(object sender, EventArgs e) { - buttonNodeTest.PerformClick(); - - if (labelNodeStatus.Text != "Node Connected") + if (checkBoxRunHSD.Checked) { - return; + StreamWriter sw = new StreamWriter(dir + "node.txt"); + sw.WriteLine("IP: " + textBoxNodeIP.Text); + sw.WriteLine("Network: " + comboBoxNodeNetwork.SelectedIndex); + sw.WriteLine("Key: " + textBoxNodeKey.Text); + sw.WriteLine("HSD: True"); + sw.Dispose(); + this.Close(); + } + else + { + + buttonNodeTest.PerformClick(); + + if (labelNodeStatus.Text != "Node Connected") + { + return; + } + StreamWriter sw = new StreamWriter(dir + "node.txt"); + sw.WriteLine("IP: " + textBoxNodeIP.Text); + sw.WriteLine("Network: " + comboBoxNodeNetwork.SelectedIndex); + sw.WriteLine("Key: " + textBoxNodeKey.Text); + sw.Dispose(); + this.Close(); } - StreamWriter sw = new StreamWriter(dir + "node.txt"); - sw.WriteLine("IP: " + textBoxNodeIP.Text); - sw.WriteLine("Network: " + comboBoxNodeNetwork.SelectedIndex); - sw.WriteLine("Key: " + textBoxNodeKey.Text); - sw.Dispose(); - this.Close(); } } }