From 91150a2b07918dee23b5524f304934c9e2bad31e Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 15 Jul 2023 20:46:58 +1000 Subject: [PATCH 1/4] main: Cleaned up unused code and fixed transfers --- FireWalletLite/DomainForm.Designer.cs | 119 +++++---- FireWalletLite/DomainForm.cs | 344 ++++++++------------------ FireWalletLite/FirstLoginForm.cs | 11 +- FireWalletLite/Loader.cs | 3 +- FireWalletLite/MainForm.cs | 11 +- FireWalletLite/NotifyForm.cs | 12 +- FireWalletLite/ReceiveForm.cs | 11 +- FireWalletLite/SendForm.cs | 11 +- 8 files changed, 162 insertions(+), 360 deletions(-) diff --git a/FireWalletLite/DomainForm.Designer.cs b/FireWalletLite/DomainForm.Designer.cs index 433cf4e..92bb17d 100644 --- a/FireWalletLite/DomainForm.Designer.cs +++ b/FireWalletLite/DomainForm.Designer.cs @@ -29,43 +29,22 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DomainForm)); - groupBoxInfo = new GroupBox(); - labelInfo = new Label(); labelName = new Label(); buttonExplorer = new Button(); buttonRenew = new Button(); buttonTransfer = new Button(); groupBoxManage = new GroupBox(); + labelTransfer = new Label(); textBoxTransferAddress = new TextBox(); buttonCancel = new Button(); buttonFinalize = new Button(); - groupBoxDNS = new GroupBox(); - panelDNS = new Panel(); - groupBoxInfo.SuspendLayout(); + groupBoxSign = new GroupBox(); + textBoxSignMessage = new TextBox(); + labelSignMessage = new Label(); groupBoxManage.SuspendLayout(); - groupBoxDNS.SuspendLayout(); + groupBoxSign.SuspendLayout(); SuspendLayout(); // - // groupBoxInfo - // - groupBoxInfo.Controls.Add(labelInfo); - groupBoxInfo.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); - groupBoxInfo.Location = new Point(12, 52); - groupBoxInfo.Name = "groupBoxInfo"; - groupBoxInfo.Size = new Size(280, 163); - groupBoxInfo.TabIndex = 0; - groupBoxInfo.TabStop = false; - groupBoxInfo.Text = "Info"; - // - // labelInfo - // - labelInfo.AutoSize = true; - labelInfo.Location = new Point(6, 28); - labelInfo.Name = "labelInfo"; - labelInfo.Size = new Size(45, 25); - labelInfo.TabIndex = 0; - labelInfo.Text = "Info"; - // // labelName // labelName.AutoSize = true; @@ -94,7 +73,7 @@ buttonRenew.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonRenew.Location = new Point(6, 31); buttonRenew.Name = "buttonRenew"; - buttonRenew.Size = new Size(89, 30); + buttonRenew.Size = new Size(141, 30); buttonRenew.TabIndex = 1; buttonRenew.Text = "Renew"; buttonRenew.UseVisualStyleBackColor = true; @@ -104,7 +83,7 @@ // buttonTransfer.FlatStyle = FlatStyle.Flat; buttonTransfer.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - buttonTransfer.Location = new Point(375, 67); + buttonTransfer.Location = new Point(655, 70); buttonTransfer.Name = "buttonTransfer"; buttonTransfer.Size = new Size(89, 30); buttonTransfer.TabIndex = 1; @@ -114,33 +93,43 @@ // // groupBoxManage // + groupBoxManage.Controls.Add(labelTransfer); groupBoxManage.Controls.Add(textBoxTransferAddress); groupBoxManage.Controls.Add(buttonRenew); groupBoxManage.Controls.Add(buttonCancel); groupBoxManage.Controls.Add(buttonFinalize); groupBoxManage.Controls.Add(buttonTransfer); groupBoxManage.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); - groupBoxManage.Location = new Point(298, 52); + groupBoxManage.Location = new Point(12, 52); groupBoxManage.Name = "groupBoxManage"; - groupBoxManage.Size = new Size(470, 163); + groupBoxManage.Size = new Size(756, 136); groupBoxManage.TabIndex = 2; groupBoxManage.TabStop = false; groupBoxManage.Text = "Manage"; // + // labelTransfer + // + labelTransfer.AutoSize = true; + labelTransfer.Location = new Point(6, 72); + labelTransfer.Name = "labelTransfer"; + labelTransfer.Size = new Size(83, 25); + labelTransfer.TabIndex = 3; + labelTransfer.Text = "Transfer:"; + // // textBoxTransferAddress // - textBoxTransferAddress.Location = new Point(6, 66); + textBoxTransferAddress.Location = new Point(95, 68); textBoxTransferAddress.Name = "textBoxTransferAddress"; - textBoxTransferAddress.Size = new Size(363, 32); + textBoxTransferAddress.Size = new Size(554, 32); textBoxTransferAddress.TabIndex = 2; // // buttonCancel // buttonCancel.FlatStyle = FlatStyle.Flat; buttonCancel.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - buttonCancel.Location = new Point(6, 67); + buttonCancel.Location = new Point(242, 70); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(89, 30); + buttonCancel.Size = new Size(141, 30); buttonCancel.TabIndex = 1; buttonCancel.Text = "Cancel"; buttonCancel.UseVisualStyleBackColor = true; @@ -151,44 +140,53 @@ // buttonFinalize.FlatStyle = FlatStyle.Flat; buttonFinalize.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - buttonFinalize.Location = new Point(6, 67); + buttonFinalize.Location = new Point(95, 70); buttonFinalize.Name = "buttonFinalize"; - buttonFinalize.Size = new Size(89, 30); + buttonFinalize.Size = new Size(141, 30); buttonFinalize.TabIndex = 1; buttonFinalize.Text = "Finalize"; buttonFinalize.UseVisualStyleBackColor = true; buttonFinalize.Visible = false; buttonFinalize.Click += buttonFinalize_Click; // - // groupBoxDNS + // groupBoxSign // - groupBoxDNS.Controls.Add(panelDNS); - groupBoxDNS.Location = new Point(12, 221); - groupBoxDNS.Name = "groupBoxDNS"; - groupBoxDNS.Size = new Size(756, 224); - groupBoxDNS.TabIndex = 3; - groupBoxDNS.TabStop = false; - groupBoxDNS.Text = "DNS"; + groupBoxSign.Controls.Add(textBoxSignMessage); + groupBoxSign.Controls.Add(labelSignMessage); + groupBoxSign.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); + groupBoxSign.Location = new Point(12, 194); + groupBoxSign.Name = "groupBoxSign"; + groupBoxSign.Size = new Size(756, 257); + groupBoxSign.TabIndex = 3; + groupBoxSign.TabStop = false; + groupBoxSign.Text = "Sign"; // - // panelDNS + // textBoxSignMessage // - panelDNS.AutoSize = true; - panelDNS.Dock = DockStyle.Fill; - panelDNS.Location = new Point(3, 19); - panelDNS.Name = "panelDNS"; - panelDNS.Size = new Size(750, 202); - panelDNS.TabIndex = 0; + textBoxSignMessage.Location = new Point(6, 56); + textBoxSignMessage.Multiline = true; + textBoxSignMessage.Name = "textBoxSignMessage"; + textBoxSignMessage.Size = new Size(744, 195); + textBoxSignMessage.TabIndex = 1; + // + // labelSignMessage + // + labelSignMessage.AutoSize = true; + labelSignMessage.Location = new Point(6, 28); + labelSignMessage.Name = "labelSignMessage"; + labelSignMessage.Size = new Size(90, 25); + labelSignMessage.TabIndex = 0; + labelSignMessage.Text = "Message:"; // // DomainForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(780, 457); - Controls.Add(groupBoxDNS); + Controls.Add(groupBoxSign); Controls.Add(groupBoxManage); Controls.Add(buttonExplorer); Controls.Add(labelName); - Controls.Add(groupBoxInfo); FormBorderStyle = FormBorderStyle.Fixed3D; Icon = (Icon)resources.GetObject("$this.Icon"); MaximizeBox = false; @@ -197,29 +195,26 @@ ShowInTaskbar = false; Text = "DomainsForm"; Load += DomainForm_Load; - groupBoxInfo.ResumeLayout(false); - groupBoxInfo.PerformLayout(); groupBoxManage.ResumeLayout(false); groupBoxManage.PerformLayout(); - groupBoxDNS.ResumeLayout(false); - groupBoxDNS.PerformLayout(); + groupBoxSign.ResumeLayout(false); + groupBoxSign.PerformLayout(); ResumeLayout(false); PerformLayout(); } #endregion - - private GroupBox groupBoxInfo; private Label labelName; private Button buttonExplorer; - private Label labelInfo; private Button buttonRenew; private Button buttonTransfer; private GroupBox groupBoxManage; private TextBox textBoxTransferAddress; private Button buttonFinalize; private Button buttonCancel; - private GroupBox groupBoxDNS; - private Panel panelDNS; + private Label labelTransfer; + private GroupBox groupBoxSign; + private TextBox textBoxSignMessage; + private Label labelSignMessage; } } \ No newline at end of file diff --git a/FireWalletLite/DomainForm.cs b/FireWalletLite/DomainForm.cs index 5ba1c4b..91ade65 100644 --- a/FireWalletLite/DomainForm.cs +++ b/FireWalletLite/DomainForm.cs @@ -6,17 +6,17 @@ namespace FireWalletLite { public partial class DomainForm : Form { - private MainForm main; - private string domain; + private MainForm Main; + private string Domain; public DomainForm(MainForm main, string domain) { InitializeComponent(); - this.main = main; - this.domain = domain; - this.Text = domain + "/"; + this.Main = main; + this.Domain = domain; + Text = domain + "/"; // Theme form - this.BackColor = ColorTranslator.FromHtml(main.Theme["background"]); - this.ForeColor = ColorTranslator.FromHtml(main.Theme["foreground"]); + BackColor = ColorTranslator.FromHtml(main.Theme["background"]); + ForeColor = ColorTranslator.FromHtml(main.Theme["foreground"]); foreach (Control control in Controls) { main.ThemeControl(control); @@ -28,105 +28,45 @@ namespace FireWalletLite { ProcessStartInfo psi = new ProcessStartInfo { - FileName = main.DomainExplorer + domain, + FileName = Main.DomainExplorer + Domain, UseShellExecute = true }; Process.Start(psi); } - - - - private async void GetName() + private void DomainForm_Load(object sender, EventArgs e) { - try + if (!File.Exists(Main.dir + "domains.json")) return; + + JArray domains = JArray.Parse(File.ReadAllText(Main.dir + "domains.json")); + foreach (JObject domain in domains) { - string content = "{\"method\": \"getnameinfo\", \"params\": [\"" + domain + "\"]}"; - string response = await main.APIPost("", false, content); - JObject jObject = JObject.Parse(response); - // Get block height - string Nodeinfo = await main.APIGet("", false); - JObject jObjectInfo = JObject.Parse(Nodeinfo); - JObject chain = (JObject)jObjectInfo["chain"]; - int height = Convert.ToInt32(chain["height"]); - - labelInfo.Text = ""; - if (jObject.ContainsKey("result")) + if (domain["name"].ToString() == Domain) { - JObject result = (JObject)jObject["result"]; - JObject start = (JObject)result["start"]; - if (start["reserved"].ToString().ToLower() == "true") labelInfo.Text = "Reserved for ICANN domain owner\n"; - if (result.ContainsKey("info")) + if (domain.ContainsKey("status")) { - try + switch (domain["status"].ToString()) { - JObject info = (JObject)result["info"]; - string state = info["state"].ToString(); - JObject stats = (JObject)info["stats"]; - - if (info["transfer"].ToString() != "0") - { - labelInfo.Text += "Transferring\n"; - int TransferEnd = Convert.ToInt32(stats["transferLockupEnd"].ToString()); - textBoxTransferAddress.Hide(); - buttonTransfer.Hide(); - if (height >= TransferEnd) - { - buttonFinalize.Show(); - } - else - { - labelInfo.Text += "Finalize in " + (TransferEnd - height).ToString() + " blocks\n"; - buttonCancel.Show(); - } - } - - if (state == "CLOSED") - { - string expires = "Expires in ~" + stats["daysUntilExpire"].ToString() + " days\n"; - labelInfo.Text += expires; - } - else labelInfo.Text += state + "\n"; - - - // Get DNS if the domain isn't in auction - if (state == "CLOSED") GetDNS(); - - - } - catch (Exception ex) - { - // No info -> Domain not in wallet - labelInfo.Text = "No info in node"; + case "transferring": + buttonFinalize.Visible = true; + buttonCancel.Visible = true; + buttonTransfer.Visible = false; + textBoxTransferAddress.Visible = false; + break; + case "closed": + buttonCancel.Visible = false; + buttonFinalize.Visible = false; + break; } } } - else - { - labelInfo.Text = "Error getting Name"; - } } - catch (Exception ex) - { - main.AddLog(ex.Message); - } - - - if (!main.Domains.Contains(domain)) - { - groupBoxManage.Hide(); - } - } - - private void DomainForm_Load(object sender, EventArgs e) - { - GetName(); } private async void buttonRenew_Click(object sender, EventArgs e) { - string content = "{\"method\": \"renew\", \"params\": [\"" + domain + "\"]}"; - string response = await main.APIPost("", true, content); + string content = "{\"method\": \"renew\", \"params\": [\"" + Domain + "\"]}"; + string response = await Main.APIPost("", true, content); if (response == "Error") { NotifyForm notify = new NotifyForm("Error renewing domain"); @@ -137,12 +77,12 @@ namespace FireWalletLite JObject jObject = JObject.Parse(response); if (jObject.ContainsKey("result")) { - main.AddLog(jObject["result"].ToString()); + Main.AddLog(jObject["result"].ToString()); JObject result = (JObject)jObject["result"]; if (result.ContainsKey("txid")) { string txid = result["txid"].ToString(); - NotifyForm notify = new NotifyForm("Renewed domain", "Explorer", main.TXExplorer + txid); + NotifyForm notify = new NotifyForm("Renewed domain", "Explorer", Main.TXExplorer + txid); notify.ShowDialog(); notify.Dispose(); } @@ -158,14 +98,14 @@ namespace FireWalletLite NotifyForm notify = new NotifyForm("Error renewing domain"); notify.ShowDialog(); notify.Dispose(); - main.AddLog(jObject.ToString()); + Main.AddLog(jObject.ToString()); } } private async void buttonTransfer_Click(object sender, EventArgs e) { string address = textBoxTransferAddress.Text; - bool valid = await main.ValidAddress(address); + bool valid = await Main.ValidAddress(address); if (!valid) { NotifyForm notify = new NotifyForm("Invalid address"); @@ -173,8 +113,9 @@ namespace FireWalletLite notify.Dispose(); return; } - string content = "{\"method\": \"transfer\", \"params\": [\"" + domain + "\", \"" + address + "\"]}"; - string response = await main.APIPost("", true, content); + string path = "wallet/" + Main.Account + "/transfer"; + string content = "{\"passphrase\": \"" + Main.Password + "\", \"name\": \"" + Domain + "\", \"broadcast\": true, \"sign\": true, \"address\": \"" + address + "\"}"; + string response = await Main.APIPost(path, true, content); if (response == "Error") { NotifyForm notify = new NotifyForm("Error transferring domain"); @@ -183,209 +124,118 @@ namespace FireWalletLite return; } JObject jObject = JObject.Parse(response); - if (jObject.ContainsKey("result")) + if (jObject.ContainsKey("hash")) { - main.AddLog(jObject["result"].ToString()); - JObject result = (JObject)jObject["result"]; - if (result.ContainsKey("txid")) - { - string txid = result["txid"].ToString(); - NotifyForm notify = new NotifyForm("Renewed domain", "Explorer", main.TXExplorer + txid); - notify.ShowDialog(); - notify.Dispose(); - } - else - { - NotifyForm notify = new NotifyForm("Error renewing domain"); - notify.ShowDialog(); - notify.Dispose(); - } + string txid = jObject["hash"].ToString(); + NotifyForm notify = new NotifyForm("Transferred domain", "Explorer", Main.TXExplorer + txid); + notify.ShowDialog(); + notify.Dispose(); + AddDomainInfo("transferring"); } else { - NotifyForm notify = new NotifyForm("Error renewing domain"); + NotifyForm notify = new NotifyForm("Error transferring domain"); notify.ShowDialog(); notify.Dispose(); - main.AddLog(jObject.ToString()); } } private void buttonFinalize_Click(object sender, EventArgs e) { - string content = "{\"method\": \"finalize\", \"params\": [\"" + domain + "\"]}"; - string response = main.APIPost("", true, content).Result; + string path = "wallet/" + Main.Account + "/finalize"; + string content = "{\"passphrase\": \"" + Main.Password + "\", \"name\": \"" + Domain + "\", \"broadcast\": true, \"sign\": true}"; + string response = Main.APIPost(path, true, content).Result; if (response == "Error") { - NotifyForm notify = new NotifyForm("Error finalizing tranfer"); + NotifyForm notify = new NotifyForm("Error finalizing transfer"); notify.ShowDialog(); notify.Dispose(); return; } JObject jObject = JObject.Parse(response); - if (jObject.ContainsKey("result")) + if (jObject.ContainsKey("hash")) { - main.AddLog(jObject["result"].ToString()); - JObject result = (JObject)jObject["result"]; - if (result.ContainsKey("txid")) - { - string txid = result["txid"].ToString(); - NotifyForm notify = new NotifyForm("Finalized tranfer", "Explorer", main.TXExplorer + txid); - notify.ShowDialog(); - notify.Dispose(); - } - else - { - NotifyForm notify = new NotifyForm("Error finalizing tranfer"); - notify.ShowDialog(); - notify.Dispose(); - } + string txid = jObject["hash"].ToString(); + NotifyForm notify = new NotifyForm("Finalized domain", "Explorer", Main.TXExplorer + txid); + notify.ShowDialog(); + notify.Dispose(); + AddDomainInfo("closed"); } else { - NotifyForm notify = new NotifyForm("Error finalizing tranfer"); + NotifyForm notify = new NotifyForm("Error finalizing domain"); notify.ShowDialog(); notify.Dispose(); - main.AddLog(jObject.ToString()); } } private void buttonCancel_Click(object sender, EventArgs e) { - string content = "{\"method\": \"cancel\", \"params\": [\"" + domain + "\"]}"; - string response = main.APIPost("", true, content).Result; + string path = "wallet/" + Main.Account + "/cancel"; + string content = "{\"passphrase\": \"" + Main.Password + "\", \"name\": \"" + Domain + "\", \"broadcast\": true, \"sign\": true}"; + string response = Main.APIPost(path, true, content).Result; if (response == "Error") { - NotifyForm notify = new NotifyForm("Error cancelling tranfer"); + NotifyForm notify = new NotifyForm("Error cancelling transfer"); notify.ShowDialog(); notify.Dispose(); return; } JObject jObject = JObject.Parse(response); - if (jObject.ContainsKey("result")) + if (jObject.ContainsKey("hash")) { - main.AddLog(jObject["result"].ToString()); - JObject result = (JObject)jObject["result"]; - if (result.ContainsKey("txid")) - { - string txid = result["txid"].ToString(); - NotifyForm notify = new NotifyForm("Cancelled tranfer", "Explorer", main.TXExplorer + txid); - notify.ShowDialog(); - notify.Dispose(); - } - else - { - NotifyForm notify = new NotifyForm("Error cancelling tranfer"); - notify.ShowDialog(); - notify.Dispose(); - } + string txid = jObject["hash"].ToString(); + NotifyForm notify = new NotifyForm("Canceled transfer", "Explorer", Main.TXExplorer + txid); + notify.ShowDialog(); + notify.Dispose(); + AddDomainInfo("closed"); } else { - NotifyForm notify = new NotifyForm("Error cancelling tranfer"); + NotifyForm notify = new NotifyForm("Error cancelling transfer"); notify.ShowDialog(); notify.Dispose(); - main.AddLog(jObject.ToString()); } } - - // Get DNS records for domain. Not implemented yet - private async void GetDNS() + private void AddDomainInfo(string status) { - // Get DNS records - string contentDNS = "{\"method\": \"getnameresource\", \"params\": [\"" + domain + "\"]}"; - string responseDNS = await main.APIPost("", false, contentDNS); - JObject jObjectDNS = JObject.Parse(responseDNS); - - if (jObjectDNS["result"].ToString() == "") + if (File.Exists(Main.dir + "domains.json")) { - // Not registered - groupBoxDNS.Visible = false; - return; - } - - JObject result = (JObject)jObjectDNS["result"]; - JArray records = (JArray)result["records"]; - // For each record - int i = 0; - foreach (JObject record in records) - { - Panel DNSPanel = new Panel(); - // Count for scroll width - DNSPanel.Width = panelDNS.Width - SystemInformation.VerticalScrollBarWidth - 2; - DNSPanel.Height = 60; - DNSPanel.BorderStyle = BorderStyle.FixedSingle; - DNSPanel.Top = 62 * i; - - Label DNSType = new Label(); - DNSType.Text = record["type"].ToString(); - DNSType.Location = new System.Drawing.Point(10, 10); - DNSType.AutoSize = true; - DNSType.Font = new Font(DNSType.Font.FontFamily, 11.0f, FontStyle.Bold); - DNSPanel.Controls.Add(DNSType); - - - switch (DNSType.Text) + bool found = false; + JArray domains = JArray.Parse(File.ReadAllText(Main.dir + "domains.json")); + foreach (JObject domain in domains) { - case "NS": - Label DNSNS = new Label(); - DNSNS.Text = record["ns"].ToString(); - DNSNS.Location = new System.Drawing.Point(10, 30); - DNSNS.AutoSize = true; - DNSPanel.Controls.Add(DNSNS); - break; - case "GLUE4": - case "GLUE6": - Label DNSNS1 = new Label(); - DNSNS1.Text = record["ns"].ToString(); - DNSNS1.Location = new System.Drawing.Point(10, 30); - DNSNS1.AutoSize = true; - DNSPanel.Controls.Add(DNSNS1); - Label address = new Label(); - address.Text = record["address"].ToString(); - address.Location = new System.Drawing.Point(DNSNS1.Left + DNSNS1.Width + 20, 30); - address.AutoSize = true; - DNSPanel.Controls.Add(address); - break; - case "DS": - Label keyTag = new Label(); - keyTag.Text = record["keyTag"].ToString(); - keyTag.Location = new System.Drawing.Point(10, 30); - keyTag.AutoSize = true; - DNSPanel.Controls.Add(keyTag); - Label algorithm = new Label(); - algorithm.Text = record["algorithm"].ToString(); - algorithm.Location = new System.Drawing.Point(keyTag.Left + keyTag.Width + 10, 30); - algorithm.AutoSize = true; - DNSPanel.Controls.Add(algorithm); - Label digestType = new Label(); - digestType.Text = record["digestType"].ToString(); - digestType.Location = new System.Drawing.Point(algorithm.Left + algorithm.Width + 10, 30); - digestType.AutoSize = true; - DNSPanel.Controls.Add(digestType); - Label digest = new Label(); - digest.Text = record["digest"].ToString(); - digest.Location = new System.Drawing.Point(digestType.Left + digestType.Width + 10, 30); - digest.AutoSize = true; - DNSPanel.Controls.Add(digest); - break; - case "TXT": - JArray txts = (JArray)record["txt"]; - int j = 0; - foreach (string txt in txts) + if (domain["name"].ToString() == Domain) + { + found = true; + if (domain.ContainsKey("status")) { - Label DNSTXT = new Label(); - DNSTXT.Text = txt; - DNSTXT.Location = new System.Drawing.Point(10, 30 + (j * 20)); - DNSTXT.AutoSize = true; - DNSPanel.Controls.Add(DNSTXT); - DNSPanel.Height = 60 + (j * 20); - j++; + domain["status"] = status; } - break; - + else + { + domain.Add("status", status); + } + } } - panelDNS.Controls.Add(DNSPanel); - i++; + + if (!found) + { + JObject domain = new JObject(); + domain["name"] = Domain; + domain["status"] = status; + domains.Add(domain); + } + File.WriteAllText(Main.dir + "domains.json", domains.ToString()); + } + else + { + JArray domains = new JArray(); + JObject domain = new JObject(); + domain["name"] = Domain; + domain["status"] = status; + domains.Add(domain); + File.WriteAllText(Main.dir + "domains.json", domains.ToString()); } } } diff --git a/FireWalletLite/FirstLoginForm.cs b/FireWalletLite/FirstLoginForm.cs index a8352ed..0443b16 100644 --- a/FireWalletLite/FirstLoginForm.cs +++ b/FireWalletLite/FirstLoginForm.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using FireWallet; +using FireWallet; using Newtonsoft.Json.Linq; namespace FireWalletLite diff --git a/FireWalletLite/Loader.cs b/FireWalletLite/Loader.cs index 196f51f..d587a65 100644 --- a/FireWalletLite/Loader.cs +++ b/FireWalletLite/Loader.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using System.Net; using System.Text.RegularExpressions; using FireWallet; @@ -9,7 +8,7 @@ namespace FireWalletLite { #region Constants MainForm mainForm = new MainForm(); - bool hideScreen = true; + bool hideScreen = false; Process HSDProcess; #endregion diff --git a/FireWalletLite/MainForm.cs b/FireWalletLite/MainForm.cs index 0f99792..524055f 100644 --- a/FireWalletLite/MainForm.cs +++ b/FireWalletLite/MainForm.cs @@ -1,10 +1,6 @@ -using System.Data; -using System.Diagnostics; -using System.DirectoryServices.ActiveDirectory; -using System.Runtime.InteropServices; +using System.Diagnostics; using FireWallet; using Newtonsoft.Json.Linq; -using static QRCoder.PayloadGenerator; namespace FireWalletLite { @@ -35,8 +31,8 @@ namespace FireWalletLite public Dictionary Theme { get; set; } HttpClient httpClient = new HttpClient(); Decimal Balance { get; set; } - String Account = "primary"; - String Password { get; set; } + public String Account = "primary"; + public String Password { get; set; } #endregion public MainForm() { @@ -247,7 +243,6 @@ namespace FireWalletLite string port = "1203"; if (wallet) port = port + "9"; else port = port + "7"; - HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, "http://" + ip + ":" + port + "/" + path); //req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key))); req.Content = new StringContent(content); diff --git a/FireWalletLite/NotifyForm.cs b/FireWalletLite/NotifyForm.cs index f25b758..48387d6 100644 --- a/FireWalletLite/NotifyForm.cs +++ b/FireWalletLite/NotifyForm.cs @@ -1,15 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Diagnostics; -using System.Drawing; -using System.Linq; +using System.Diagnostics; using System.Runtime.InteropServices; -using System.Security.Policy; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace FireWallet { diff --git a/FireWalletLite/ReceiveForm.cs b/FireWalletLite/ReceiveForm.cs index fab2a1e..4631bd0 100644 --- a/FireWalletLite/ReceiveForm.cs +++ b/FireWalletLite/ReceiveForm.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using QRCoder; +using QRCoder; namespace FireWalletLite { diff --git a/FireWalletLite/SendForm.cs b/FireWalletLite/SendForm.cs index 6e4d655..7cf33f4 100644 --- a/FireWalletLite/SendForm.cs +++ b/FireWalletLite/SendForm.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using FireWallet; +using FireWallet; using Newtonsoft.Json.Linq; namespace FireWalletLite From 4606eaf8a319d99f0134cc1c74c044f34436512a Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 15 Jul 2023 20:58:34 +1000 Subject: [PATCH 2/4] main: Added signing messages --- FireWalletLite/DomainForm.Designer.cs | 27 ++++++++++++++++++++- FireWalletLite/DomainForm.cs | 34 ++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/FireWalletLite/DomainForm.Designer.cs b/FireWalletLite/DomainForm.Designer.cs index 92bb17d..1c33768 100644 --- a/FireWalletLite/DomainForm.Designer.cs +++ b/FireWalletLite/DomainForm.Designer.cs @@ -39,8 +39,10 @@ buttonCancel = new Button(); buttonFinalize = new Button(); groupBoxSign = new GroupBox(); + buttonSign = new Button(); textBoxSignMessage = new TextBox(); labelSignMessage = new Label(); + textBoxSignature = new TextBox(); groupBoxManage.SuspendLayout(); groupBoxSign.SuspendLayout(); SuspendLayout(); @@ -151,6 +153,8 @@ // // groupBoxSign // + groupBoxSign.Controls.Add(textBoxSignature); + groupBoxSign.Controls.Add(buttonSign); groupBoxSign.Controls.Add(textBoxSignMessage); groupBoxSign.Controls.Add(labelSignMessage); groupBoxSign.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); @@ -161,12 +165,22 @@ groupBoxSign.TabStop = false; groupBoxSign.Text = "Sign"; // + // buttonSign + // + buttonSign.Location = new Point(606, 218); + buttonSign.Name = "buttonSign"; + buttonSign.Size = new Size(138, 33); + buttonSign.TabIndex = 2; + buttonSign.Text = "Sign"; + buttonSign.UseVisualStyleBackColor = true; + buttonSign.Click += buttonSign_Click; + // // textBoxSignMessage // textBoxSignMessage.Location = new Point(6, 56); textBoxSignMessage.Multiline = true; textBoxSignMessage.Name = "textBoxSignMessage"; - textBoxSignMessage.Size = new Size(744, 195); + textBoxSignMessage.Size = new Size(472, 156); textBoxSignMessage.TabIndex = 1; // // labelSignMessage @@ -178,6 +192,15 @@ labelSignMessage.TabIndex = 0; labelSignMessage.Text = "Message:"; // + // textBoxSignature + // + textBoxSignature.Location = new Point(484, 56); + textBoxSignature.Multiline = true; + textBoxSignature.Name = "textBoxSignature"; + textBoxSignature.ReadOnly = true; + textBoxSignature.Size = new Size(260, 156); + textBoxSignature.TabIndex = 3; + // // DomainForm // AutoScaleDimensions = new SizeF(7F, 15F); @@ -216,5 +239,7 @@ private GroupBox groupBoxSign; private TextBox textBoxSignMessage; private Label labelSignMessage; + private Button buttonSign; + private TextBox textBoxSignature; } } \ No newline at end of file diff --git a/FireWalletLite/DomainForm.cs b/FireWalletLite/DomainForm.cs index 91ade65..e0c47da 100644 --- a/FireWalletLite/DomainForm.cs +++ b/FireWalletLite/DomainForm.cs @@ -37,7 +37,7 @@ namespace FireWalletLite private void DomainForm_Load(object sender, EventArgs e) { if (!File.Exists(Main.dir + "domains.json")) return; - + JArray domains = JArray.Parse(File.ReadAllText(Main.dir + "domains.json")); foreach (JObject domain in domains) { @@ -238,5 +238,37 @@ namespace FireWalletLite File.WriteAllText(Main.dir + "domains.json", domains.ToString()); } } + + private async void buttonSign_Click(object sender, EventArgs e) + { + if (textBoxSignMessage.Text == "") + { + NotifyForm notify = new NotifyForm("Enter a message to sign"); + notify.ShowDialog(); + notify.Dispose(); + return; + } + string content = "{\"method\": \"signmessagewithname\", \"params\": [\"" + Domain + "\", \"" + textBoxSignMessage.Text + "\"]}"; + string response = await Main.APIPost("", true, content); + Main.AddLog(response); + if (response == "Error") + { + NotifyForm notify = new NotifyForm("Error signing message"); + notify.ShowDialog(); + notify.Dispose(); + return; + } + JObject jObject = JObject.Parse(response); + if (jObject.ContainsKey("result")) + { + textBoxSignature.Text = jObject["result"].ToString(); + } + else + { + NotifyForm notify = new NotifyForm("Error signing message"); + notify.ShowDialog(); + notify.Dispose(); + } + } } } From 5550ce472e338bd1d1531f8f5e1a92912c42f06b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 15 Jul 2023 21:06:11 +1000 Subject: [PATCH 3/4] main: Added save signed message --- FireWalletLite/DomainForm.Designer.cs | 21 +++++++++++---------- FireWalletLite/DomainForm.cs | 25 ++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/FireWalletLite/DomainForm.Designer.cs b/FireWalletLite/DomainForm.Designer.cs index 1c33768..d9498cc 100644 --- a/FireWalletLite/DomainForm.Designer.cs +++ b/FireWalletLite/DomainForm.Designer.cs @@ -39,10 +39,10 @@ buttonCancel = new Button(); buttonFinalize = new Button(); groupBoxSign = new GroupBox(); + textBoxSignature = new TextBox(); buttonSign = new Button(); textBoxSignMessage = new TextBox(); labelSignMessage = new Label(); - textBoxSignature = new TextBox(); groupBoxManage.SuspendLayout(); groupBoxSign.SuspendLayout(); SuspendLayout(); @@ -165,6 +165,15 @@ groupBoxSign.TabStop = false; groupBoxSign.Text = "Sign"; // + // textBoxSignature + // + textBoxSignature.Location = new Point(484, 56); + textBoxSignature.Multiline = true; + textBoxSignature.Name = "textBoxSignature"; + textBoxSignature.ReadOnly = true; + textBoxSignature.Size = new Size(260, 156); + textBoxSignature.TabIndex = 3; + // // buttonSign // buttonSign.Location = new Point(606, 218); @@ -182,6 +191,7 @@ textBoxSignMessage.Name = "textBoxSignMessage"; textBoxSignMessage.Size = new Size(472, 156); textBoxSignMessage.TabIndex = 1; + textBoxSignMessage.TextChanged += textBoxSignMessage_TextChanged; // // labelSignMessage // @@ -192,15 +202,6 @@ labelSignMessage.TabIndex = 0; labelSignMessage.Text = "Message:"; // - // textBoxSignature - // - textBoxSignature.Location = new Point(484, 56); - textBoxSignature.Multiline = true; - textBoxSignature.Name = "textBoxSignature"; - textBoxSignature.ReadOnly = true; - textBoxSignature.Size = new Size(260, 156); - textBoxSignature.TabIndex = 3; - // // DomainForm // AutoScaleDimensions = new SizeF(7F, 15F); diff --git a/FireWalletLite/DomainForm.cs b/FireWalletLite/DomainForm.cs index e0c47da..ff2835d 100644 --- a/FireWalletLite/DomainForm.cs +++ b/FireWalletLite/DomainForm.cs @@ -241,6 +241,23 @@ namespace FireWalletLite private async void buttonSign_Click(object sender, EventArgs e) { + if (buttonSign.Text == "Save") + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Text File|*.txt"; + saveFileDialog.Title = "Save Signature"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + JObject signature = new JObject(); + signature["domain"] = Domain; + signature["message"] = textBoxSignMessage.Text; + signature["signature"] = textBoxSignature.Text; + signature["time"] = DateTime.Now.ToString(); + File.WriteAllText(saveFileDialog.FileName, signature.ToString()); + } + + return; + } if (textBoxSignMessage.Text == "") { NotifyForm notify = new NotifyForm("Enter a message to sign"); @@ -250,7 +267,6 @@ namespace FireWalletLite } string content = "{\"method\": \"signmessagewithname\", \"params\": [\"" + Domain + "\", \"" + textBoxSignMessage.Text + "\"]}"; string response = await Main.APIPost("", true, content); - Main.AddLog(response); if (response == "Error") { NotifyForm notify = new NotifyForm("Error signing message"); @@ -262,13 +278,20 @@ namespace FireWalletLite if (jObject.ContainsKey("result")) { textBoxSignature.Text = jObject["result"].ToString(); + buttonSign.Text = "Save"; } else { + Main.AddLog(response); NotifyForm notify = new NotifyForm("Error signing message"); notify.ShowDialog(); notify.Dispose(); } } + + private void textBoxSignMessage_TextChanged(object sender, EventArgs e) + { + buttonSign.Text = "Sign"; + } } } From 1583670b083e066e12c9ac3d801f59f84d3aaea7 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 15 Jul 2023 21:23:04 +1000 Subject: [PATCH 4/4] readme: Added signing to feature list --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 79615a0..6536cce 100644 --- a/README.md +++ b/README.md @@ -12,20 +12,20 @@ First run flow: Login only requires password as this wallet is made to only use the `primary` wallet. -Main Page includes -- Balance -- Domain Count -- Domain List +This wallet supports +- Displaying balance +- Domain list and expiration date - Renew expiring domains button -- Recieve HNS button (opens a window with address, copy button, and QR code) -- Send HNS button (opens a window with address, amount, and send button) +- Displaying receiving address +- Sending HNS +- Sign message This wallet does not (and will never) support - Creating new wallets - Auctions (bidding, revealing, etc) - Multisig wallets - Hardware wallets -- DNS management (a simple DNS managment page might be added in the future) +- DNS management If you want to use a wallet with more features, please use [Fire Wallet](https://firewallet.au) or [Bob Wallet](https://bobwallet.io) instead. \ No newline at end of file