main: Added Register support

This commit is contained in:
Nathan Woodburn 2023-06-21 12:12:45 +10:00
parent 8f241fc90a
commit 9f33c74bb0
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 61 additions and 11 deletions

View File

@ -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<Batch> temp = new List<Batch>();
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<Batch> temp = new List<Batch>();
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<Batch> temp = new List<Batch>();
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<Batch> temp = new List<Batch>();
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 + "\"]";
}
}

View File

@ -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);

View File

@ -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];

View File

@ -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

View File

@ -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);