From 9f33c74bb09fff00c1e569a405df0b6e43441617 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 21 Jun 2023 12:12:45 +1000 Subject: [PATCH] main: Added Register support --- FireWallet/BatchForm.cs | 32 ++++++++++++++++++-------- FireWallet/BatchImportForm.Designer.cs | 2 +- FireWallet/BatchImportForm.cs | 15 ++++++++++++ FireWallet/DNSForm.cs | 6 +++++ FireWallet/DomainForm.cs | 17 +++++++++++++- 5 files changed, 61 insertions(+), 11 deletions(-) diff --git a/FireWallet/BatchForm.cs b/FireWallet/BatchForm.cs index f2e583f..58de35a 100644 --- a/FireWallet/BatchForm.cs +++ b/FireWallet/BatchForm.cs @@ -1,5 +1,6 @@ using System.Data; using System.Diagnostics; +using System.Net; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms.VisualStyles; @@ -58,7 +59,7 @@ namespace FireWallet List temp = new List(); foreach (Batch batch in batches) { - if (batch.domain != domain && batch.method != operation) + if (batch.domain != domain || batch.method != operation) { temp.Add(batch); } @@ -122,7 +123,7 @@ namespace FireWallet List temp = new List(); foreach (Batch batch in batches) { - if (batch.domain != domain && batch.method != operation) + if (batch.domain != domain || batch.method != operation) { temp.Add(batch); } @@ -182,7 +183,7 @@ namespace FireWallet List temp = new List(); foreach (Batch batch in batches) { - if (batch.domain != domain && batch.method != operation) + if (batch.domain != domain || batch.method != operation) { temp.Add(batch); } @@ -238,7 +239,7 @@ namespace FireWallet List temp = new List(); foreach (Batch batch in batches) { - if (batch.domain != domain && batch.method != operation) + if (batch.domain != domain || batch.method != operation) { temp.Add(batch); } @@ -750,6 +751,10 @@ namespace FireWallet { AddBatch(b.domain, b.method, b.toAddress); } + else if (b.method == "UPDATE") + { + AddBatch(b.domain, b.method, b.update); + } else { AddBatch(b.domain, b.method); @@ -792,21 +797,26 @@ namespace FireWallet req.Content = new StringContent(content); // Send request - HttpResponseMessage resp = await httpClient.SendAsync(req); try { - resp.EnsureSuccessStatusCode(); + HttpResponseMessage resp = await httpClient.SendAsync(req); + if (resp.StatusCode != HttpStatusCode.OK) + { + AddLog("Post Error: " + resp.StatusCode.ToString()); + AddLog(await resp.Content.ReadAsStringAsync()); + AddLog(content); + return "Error"; + } + return await resp.Content.ReadAsStringAsync(); } catch (Exception ex) { AddLog("Post Error: " + ex.Message); - AddLog(await resp.Content.ReadAsStringAsync()); - AddLog(content); return "Error"; } - return await resp.Content.ReadAsStringAsync(); + } } public class Batch @@ -868,6 +878,10 @@ namespace FireWallet return "[\"UPDATE\", \"" + domain + "\", " + records + "]"; } + else if (method == "UPDATE") + { + return "[\"UPDATE\", \"" + domain + "\", {\"records\":[]}]"; + } return "[\"" + method + "\", \"" + domain + "\"]"; } } diff --git a/FireWallet/BatchImportForm.Designer.cs b/FireWallet/BatchImportForm.Designer.cs index 6ddc815..46ba86f 100644 --- a/FireWallet/BatchImportForm.Designer.cs +++ b/FireWallet/BatchImportForm.Designer.cs @@ -72,7 +72,7 @@ comboBoxMode.FlatStyle = FlatStyle.Flat; comboBoxMode.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); comboBoxMode.FormattingEnabled = true; - comboBoxMode.Items.AddRange(new object[] { "OPEN", "BID", "REVEAL", "REDEEM", "RENEW", "TRANSFER", "FINALIZE", "CANCEL" }); + comboBoxMode.Items.AddRange(new object[] { "OPEN", "BID", "REVEAL", "REDEEM", "REGISTER", "RENEW", "TRANSFER", "FINALIZE", "CANCEL" }); comboBoxMode.Location = new Point(346, 42); comboBoxMode.Name = "comboBoxMode"; comboBoxMode.Size = new Size(226, 29); diff --git a/FireWallet/BatchImportForm.cs b/FireWallet/BatchImportForm.cs index aad2bf6..b41ee35 100644 --- a/FireWallet/BatchImportForm.cs +++ b/FireWallet/BatchImportForm.cs @@ -263,6 +263,21 @@ namespace FireWallet } this.Close(); } + else if (comboBoxMode.Text == "REGISTER") + { + batches = new Batch[0]; + foreach (string domain in listBoxDomains.Items) + { + if (domain != "") + { + Batch[] newBatch = new Batch[batches.Length + 1]; + Array.Copy(batches, newBatch, batches.Length); + newBatch[newBatch.Length - 1] = new Batch(domain,"UPDATE",new DNS[0]); + batches = newBatch; + } + } + this.Close(); + } else if (comboBoxMode.Text == "TRANSFER") { batches = new Batch[0]; diff --git a/FireWallet/DNSForm.cs b/FireWallet/DNSForm.cs index d86d03a..f36c822 100644 --- a/FireWallet/DNSForm.cs +++ b/FireWallet/DNSForm.cs @@ -363,6 +363,12 @@ namespace FireWallet string contentDNS = "{\"method\": \"getnameresource\", \"params\": [\"" + domain + "\"]}"; string responseDNS = await APIPost("", false, contentDNS); JObject jObjectDNS = JObject.Parse(responseDNS); + + if (jObjectDNS["result"].ToString() == "") + { + return; + } + JObject result = (JObject)jObjectDNS["result"]; JArray records = (JArray)result["records"]; // For each record diff --git a/FireWallet/DomainForm.cs b/FireWallet/DomainForm.cs index d1d22b7..3cca470 100644 --- a/FireWallet/DomainForm.cs +++ b/FireWallet/DomainForm.cs @@ -279,6 +279,14 @@ namespace FireWallet string contentDNS = "{\"method\": \"getnameresource\", \"params\": [\"" + domain + "\"]}"; string responseDNS = await APIPost("", false, contentDNS); JObject jObjectDNS = JObject.Parse(responseDNS); + + if (jObjectDNS["result"].ToString() == "") + { + // Not registered + groupBoxDNS.Visible = false; + return; + } + JObject result = (JObject)jObjectDNS["result"]; JArray records = (JArray)result["records"]; // For each record @@ -814,7 +822,14 @@ namespace FireWallet if (!DNSEdit.cancel) { - string records = string.Join(", ", DNSEdit.DNSrecords.Select(record => record.ToString())); + string records = ""; + if (DNSEdit.DNSrecords != null) + { + if (DNSEdit.DNSrecords.Count() > 0) + { + records = string.Join(", ", DNSEdit.DNSrecords.Select(record => record.ToString())); + } + } string content = "{\"method\": \"sendupdate\", \"params\": [\"" + domain + "\", {\"records\": [" + records + "]}]}"; string response = await APIPost("", true, content);