main: Added more domain functions and explorer

This commit is contained in:
Nathan Woodburn 2023-06-07 20:17:34 +10:00
parent 072f32f9a9
commit 3baa6ec8e3
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 355 additions and 9 deletions

View File

@ -46,9 +46,18 @@
panelDNS = new Panel(); panelDNS = new Panel();
groupBoxBids = new GroupBox(); groupBoxBids = new GroupBox();
panelBids = new Panel(); panelBids = new Panel();
groupBoxAction = new GroupBox();
textBoxBlind = new TextBox();
textBoxBid = new TextBox();
labelBlind = new Label();
labelBid = new Label();
buttonActionAlt = new Button();
buttonActionMain = new Button();
buttonExplorer = new Button();
groupBoxStatus.SuspendLayout(); groupBoxStatus.SuspendLayout();
groupBoxDNS.SuspendLayout(); groupBoxDNS.SuspendLayout();
groupBoxBids.SuspendLayout(); groupBoxBids.SuspendLayout();
groupBoxAction.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// labelTitle // labelTitle
@ -229,11 +238,101 @@
panelBids.Size = new System.Drawing.Size(956, 291); panelBids.Size = new System.Drawing.Size(956, 291);
panelBids.TabIndex = 0; panelBids.TabIndex = 0;
// //
// groupBoxAction
//
groupBoxAction.Controls.Add(textBoxBlind);
groupBoxAction.Controls.Add(textBoxBid);
groupBoxAction.Controls.Add(labelBlind);
groupBoxAction.Controls.Add(labelBid);
groupBoxAction.Controls.Add(buttonActionAlt);
groupBoxAction.Controls.Add(buttonActionMain);
groupBoxAction.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxAction.Location = new System.Drawing.Point(396, 68);
groupBoxAction.Name = "groupBoxAction";
groupBoxAction.Size = new System.Drawing.Size(575, 173);
groupBoxAction.TabIndex = 14;
groupBoxAction.TabStop = false;
groupBoxAction.Text = "Bid";
groupBoxAction.Visible = false;
//
// textBoxBlind
//
textBoxBlind.Location = new System.Drawing.Point(60, 64);
textBoxBlind.Name = "textBoxBlind";
textBoxBlind.Size = new System.Drawing.Size(180, 29);
textBoxBlind.TabIndex = 5;
textBoxBlind.Visible = false;
textBoxBlind.TextChanged += textBoxBlind_TextChanged;
//
// textBoxBid
//
textBoxBid.Location = new System.Drawing.Point(60, 22);
textBoxBid.Name = "textBoxBid";
textBoxBid.Size = new System.Drawing.Size(180, 29);
textBoxBid.TabIndex = 4;
textBoxBid.Visible = false;
textBoxBid.TextChanged += textBoxBlind_TextChanged;
//
// labelBlind
//
labelBlind.AutoSize = true;
labelBlind.Location = new System.Drawing.Point(6, 67);
labelBlind.Name = "labelBlind";
labelBlind.Size = new System.Drawing.Size(48, 21);
labelBlind.TabIndex = 3;
labelBlind.Text = "Blind:";
labelBlind.Visible = false;
//
// labelBid
//
labelBid.AutoSize = true;
labelBid.Location = new System.Drawing.Point(19, 25);
labelBid.Name = "labelBid";
labelBid.Size = new System.Drawing.Size(35, 21);
labelBid.TabIndex = 2;
labelBid.Text = "Bid:";
labelBid.Visible = false;
//
// buttonActionAlt
//
buttonActionAlt.FlatStyle = FlatStyle.Flat;
buttonActionAlt.Location = new System.Drawing.Point(253, 130);
buttonActionAlt.Name = "buttonActionAlt";
buttonActionAlt.Size = new System.Drawing.Size(155, 37);
buttonActionAlt.TabIndex = 1;
buttonActionAlt.Text = "Bid in Batch";
buttonActionAlt.UseVisualStyleBackColor = true;
//
// buttonActionMain
//
buttonActionMain.FlatStyle = FlatStyle.Flat;
buttonActionMain.Location = new System.Drawing.Point(414, 130);
buttonActionMain.Name = "buttonActionMain";
buttonActionMain.Size = new System.Drawing.Size(155, 37);
buttonActionMain.TabIndex = 0;
buttonActionMain.Text = "Send Bid";
buttonActionMain.UseVisualStyleBackColor = true;
buttonActionMain.Click += buttonActionMain_Click;
//
// buttonExplorer
//
buttonExplorer.FlatStyle = FlatStyle.Flat;
buttonExplorer.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonExplorer.Location = new System.Drawing.Point(876, 12);
buttonExplorer.Name = "buttonExplorer";
buttonExplorer.Size = new System.Drawing.Size(98, 34);
buttonExplorer.TabIndex = 15;
buttonExplorer.Text = "Explorer";
buttonExplorer.UseVisualStyleBackColor = true;
buttonExplorer.Click += Explorer_Click;
//
// DomainForm // DomainForm
// //
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(986, 572); ClientSize = new System.Drawing.Size(986, 572);
Controls.Add(buttonExplorer);
Controls.Add(groupBoxAction);
Controls.Add(groupBoxBids); Controls.Add(groupBoxBids);
Controls.Add(groupBoxDNS); Controls.Add(groupBoxDNS);
Controls.Add(groupBoxStatus); Controls.Add(groupBoxStatus);
@ -247,6 +346,8 @@
groupBoxStatus.PerformLayout(); groupBoxStatus.PerformLayout();
groupBoxDNS.ResumeLayout(false); groupBoxDNS.ResumeLayout(false);
groupBoxBids.ResumeLayout(false); groupBoxBids.ResumeLayout(false);
groupBoxAction.ResumeLayout(false);
groupBoxAction.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -271,5 +372,13 @@
private Panel panelDNS; private Panel panelDNS;
private GroupBox groupBoxBids; private GroupBox groupBoxBids;
private Panel panelBids; private Panel panelBids;
private GroupBox groupBoxAction;
private TextBox textBoxBlind;
private TextBox textBoxBid;
private Label labelBlind;
private Label labelBid;
private Button buttonActionAlt;
private Button buttonActionMain;
private Button buttonExplorer;
} }
} }

View File

@ -2,11 +2,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using BitMiracle.LibTiff.Classic; using BitMiracle.LibTiff.Classic;
@ -23,13 +25,21 @@ namespace FireWallet
string domain; string domain;
int network; int network;
int height; int height;
bool own;
string state;
string explorerTX;
string explorerName;
public DomainForm(string domain) public Form OriginalForm { get; set; }
public DomainForm(string domain, string explorerTX, string explorerName)
{ {
InitializeComponent(); InitializeComponent();
this.Text = domain + "/ | FireWallet"; this.Text = domain + "/ | FireWallet";
labelTitle.Text = domain + "/"; labelTitle.Text = domain + "/";
this.domain = domain; this.domain = domain;
this.explorerTX = explorerTX;
this.explorerName = explorerName;
} }
#region Theming #region Theming
@ -208,6 +218,7 @@ namespace FireWallet
private void DomainForm_Load(object sender, EventArgs e) private void DomainForm_Load(object sender, EventArgs e)
{ {
UpdateTheme(); UpdateTheme();
own = false;
StreamReader sr = new StreamReader(dir + "node.txt"); StreamReader sr = new StreamReader(dir + "node.txt");
nodeSettings = new Dictionary<string, string>(); nodeSettings = new Dictionary<string, string>();
while (!sr.EndOfStream) while (!sr.EndOfStream)
@ -227,6 +238,7 @@ namespace FireWallet
network = Convert.ToInt32(nodeSettings["Network"]); network = Convert.ToInt32(nodeSettings["Network"]);
GetName(); GetName();
} }
#region API
private async void GetName() private async void GetName()
{ {
try try
@ -293,13 +305,14 @@ namespace FireWallet
else if (state == "BIDDING" || state == "REVEAL") GetBids(state); else if (state == "BIDDING" || state == "REVEAL") GetBids(state);
else groupBoxDNS.Visible = false; else groupBoxDNS.Visible = false;
//Setup action box
ActionSetup(state);
} }
catch (Exception ex) catch (Exception ex)
{ {
// No info -> Domain not yet auctioned // No info -> Domain not yet auctioned
labelStatusMain.Text = "Available"; labelStatusMain.Text = "Available";
ActionSetup("AVAILABLE");
AddLog(ex.Message); AddLog(ex.Message);
AddLog(result.ToString()); AddLog(result.ToString());
} }
@ -420,10 +433,19 @@ namespace FireWallet
if (!response.Contains("\"error\":null")) if (!response.Contains("\"error\":null"))
{ {
AddLog("Syncing Domain"); AddLog("Syncing Domain");
Label syncingLabel = new Label();
syncingLabel.Text = "Syncing Bids...";
syncingLabel.Location = new System.Drawing.Point(10, 10);
syncingLabel.AutoSize = true;
panelBids.Controls.Add(syncingLabel);
// Error // Error
// Try scanning for auction // Try scanning for auction
contentBids = "{\"method\": \"importname\", \"params\": [\"" + domain + "\", " + (height - 2000) + "]}"; contentBids = "{\"method\": \"importname\", \"params\": [\"" + domain + "\", " + (height - 2000) + "]}";
await APIPost("", true, contentBids);
contentBids = "{\"method\": \"getauctioninfo\", \"params\": [\"" + domain + "\"]}";
response = await APIPost("", true, contentBids); response = await APIPost("", true, contentBids);
panelBids.Controls.Clear();
} }
if (state == "BIDDING") if (state == "BIDDING")
@ -466,6 +488,7 @@ namespace FireWallet
} }
else if (state == "REVEAL") else if (state == "REVEAL")
{ {
//! TODO Add reveal info
JObject resp = JObject.Parse(response); JObject resp = JObject.Parse(response);
JObject result = (JObject)resp["result"]; JObject result = (JObject)resp["result"];
JArray bids = (JArray)result["bids"]; JArray bids = (JArray)result["bids"];
@ -473,6 +496,7 @@ namespace FireWallet
int i = 1; int i = 1;
foreach (JObject bid in bids) foreach (JObject bid in bids)
{ {
Panel bidPanel = new Panel(); Panel bidPanel = new Panel();
// Count for scroll width // Count for scroll width
bidPanel.Width = panelBids.Width - SystemInformation.VerticalScrollBarWidth - 2; bidPanel.Width = panelBids.Width - SystemInformation.VerticalScrollBarWidth - 2;
@ -486,7 +510,6 @@ namespace FireWallet
bidNumber.Font = new Font(bidNumber.Font.FontFamily, 11.0f, FontStyle.Bold); bidNumber.Font = new Font(bidNumber.Font.FontFamily, 11.0f, FontStyle.Bold);
bidPanel.Controls.Add(bidNumber); bidPanel.Controls.Add(bidNumber);
Label bidAmount = new Label(); Label bidAmount = new Label();
bidAmount.Text = convertHNS(bid["lockup"].ToString()) + " HNS"; bidAmount.Text = convertHNS(bid["lockup"].ToString()) + " HNS";
bidAmount.Location = new System.Drawing.Point(10, 30); bidAmount.Location = new System.Drawing.Point(10, 30);
bidAmount.AutoSize = true; bidAmount.AutoSize = true;
@ -517,7 +540,7 @@ namespace FireWallet
} }
#region API
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
/// <summary> /// <summary>
/// Post to HSD API /// Post to HSD API
@ -552,6 +575,7 @@ namespace FireWallet
catch (Exception ex) catch (Exception ex)
{ {
AddLog("Post Error: " + ex.Message); AddLog("Post Error: " + ex.Message);
AddLog("Post Error: " + await resp.Content.ReadAsStringAsync());
return "Error"; return "Error";
} }
@ -601,5 +625,198 @@ namespace FireWallet
sw.Dispose(); sw.Dispose();
} }
#endregion #endregion
private void ActionSetup(string state)
{
this.state = state;
switch (state)
{
case "AVAILABLE":
groupBoxAction.Show();
groupBoxAction.Text = "Open Auction";
buttonActionMain.Text = "Send Open";
buttonActionAlt.Text = "Open in Batch";
break;
case "BIDDING":
groupBoxAction.Show();
labelBid.Show();
textBoxBid.Show();
labelBlind.Show();
textBoxBlind.Show();
break;
case "REVEAL":
groupBoxAction.Show();
groupBoxAction.Text = "Reveal Bid";
buttonActionMain.Text = "Send Reveal";
buttonActionAlt.Text = "Reveal in Batch";
break;
case "CLOSED":
if (own)
{
if (labelStatusTransferring.Text == "Yes")
{
// Check if can finalize
}
else
{
groupBoxAction.Show();
groupBoxAction.Text = "Edit";
buttonActionMain.Text = "Edit DNS";
buttonActionAlt.Text = "Edit in Batch";
}
}
break;
}
}
private void textBoxBlind_TextChanged(object sender, EventArgs e)
{
string cleanedText = Regex.Replace(textBoxBid.Text, "[^0-9.]", "");
textBoxBid.Text = cleanedText;
cleanedText = Regex.Replace(textBoxBlind.Text, "[^0-9.]", "");
textBoxBlind.Text = cleanedText;
}
private async void buttonActionMain_Click(object sender, EventArgs e)
{
if (state == "BIDDING")
{
int count = textBoxBid.Text.Count(c => c == '.');
int count2 = textBoxBlind.Text.Count(c => c == '.');
if (count > 1 || count2 > 1)
{
NotifyForm notifyForm = new NotifyForm("Invalid bid amount");
notifyForm.ShowDialog();
notifyForm.Dispose();
return;
}
if (textBoxBid.Text == "" || textBoxBid.Text == ".")
{
textBoxBid.Text = "0";
}
if (textBoxBlind.Text == "" || textBoxBlind.Text == ".")
{
textBoxBlind.Text = "0";
}
await APIPost("", true, "{\"method\": \"selectwallet\", \"params\": [\"" + explorerTX + "\"]}");
decimal bid = Convert.ToDecimal(textBoxBid.Text);
decimal blind = Convert.ToDecimal(textBoxBlind.Text);
decimal lockup = bid + blind;
string content = "{\"method\": \"sendbid\", \"params\": [\"" + domain + "\", " + bid.ToString() + ", " + lockup.ToString() + "]}";
string response = await APIPost("", true, content);
if (response == "Error")
{
NotifyForm notifyForm = new NotifyForm("Error sending bid");
notifyForm.ShowDialog();
notifyForm.Dispose();
}
else
{
JObject jObject = JObject.Parse(response);
if (jObject["result"].ToString() == "")
{
JObject error = (JObject)jObject["error"];
string message = (string)error["message"];
NotifyForm notifyForm2 = new NotifyForm("Error sending bid: \n" + message);
notifyForm2.ShowDialog();
notifyForm2.Dispose();
return;
}
JObject result = (JObject)jObject["result"];
string hash = (string)result["hash"];
NotifyForm notifyForm = new NotifyForm("Bid sent: " + hash, "Explorer", explorerTX + hash);
notifyForm.ShowDialog();
notifyForm.Dispose();
}
}
else if (state == "REVEAL")
{
await APIPost("", true, "{\"method\": \"selectwallet\", \"params\": [\"" + explorerTX + "\"]}");
decimal bid = Convert.ToDecimal(textBoxBid.Text);
decimal blind = Convert.ToDecimal(textBoxBlind.Text);
decimal lockup = bid + blind;
string content = "{\"method\": \"sendreveal\", \"params\": [\"" + domain + "\"]}";
string response = await APIPost("", true, content);
if (response == "Error")
{
NotifyForm notifyForm = new NotifyForm("Error sending reveal");
notifyForm.ShowDialog();
notifyForm.Dispose();
}
else
{
JObject jObject = JObject.Parse(response);
if (jObject["result"].ToString() == "")
{
JObject error = (JObject)jObject["error"];
string message = (string)error["message"];
NotifyForm notifyForm2 = new NotifyForm("Error sending reveal: \n" + message);
notifyForm2.ShowDialog();
notifyForm2.Dispose();
return;
}
JObject result = (JObject)jObject["result"];
string hash = (string)result["hash"];
NotifyForm notifyForm = new NotifyForm("Reveal sent: " + hash, "Explorer", explorerTX + hash);
notifyForm.ShowDialog();
notifyForm.Dispose();
}
}
else if (state == "AVAILABLE")
{
await APIPost("", true, "{\"method\": \"selectwallet\", \"params\": [\"" + explorerTX + "\"]}");
decimal bid = Convert.ToDecimal(textBoxBid.Text);
decimal blind = Convert.ToDecimal(textBoxBlind.Text);
decimal lockup = bid + blind;
string content = "{\"method\": \"sendopen\", \"params\": [\"" + domain + "\"]}";
string response = await APIPost("", true, content);
if (response == "Error")
{
NotifyForm notifyForm = new NotifyForm("Error sending open");
notifyForm.ShowDialog();
notifyForm.Dispose();
}
else
{
JObject jObject = JObject.Parse(response);
if (jObject["result"].ToString() == "")
{
JObject error = (JObject)jObject["error"];
string message = (string)error["message"];
NotifyForm notifyForm2 = new NotifyForm("Error sending open: \n" + message);
notifyForm2.ShowDialog();
notifyForm2.Dispose();
return;
}
JObject result = (JObject)jObject["result"];
string hash = (string)result["hash"];
NotifyForm notifyForm = new NotifyForm("Open sent: " + hash, "Explorer", explorerTX + hash);
notifyForm.ShowDialog();
notifyForm.Dispose();
}
}
}
private void Explorer_Click(object sender, EventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = explorerName + domain,
UseShellExecute = true
};
Process.Start(psi);
}
} }
} }

View File

@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq;
using Point = System.Drawing.Point; using Point = System.Drawing.Point;
using Size = System.Drawing.Size; using Size = System.Drawing.Size;
using IronBarCode; using IronBarCode;
using static System.Windows.Forms.DataFormats;
namespace FireWallet namespace FireWallet
{ {
@ -129,6 +130,8 @@ namespace FireWallet
sw.WriteLine("explorer-tx: https://niami.io/tx/"); sw.WriteLine("explorer-tx: https://niami.io/tx/");
sw.WriteLine("explorer-addr: https://niami.io/address/"); sw.WriteLine("explorer-addr: https://niami.io/address/");
sw.WriteLine("explorer-block: https://niami.io/block/"); sw.WriteLine("explorer-block: https://niami.io/block/");
sw.WriteLine("explorer-domain: https://niami.io/domain/");
sw.WriteLine("confirmations: 1");
sw.Dispose(); sw.Dispose();
} }
@ -146,7 +149,7 @@ namespace FireWallet
#endregion #endregion
#region Logging #region Logging
private void AddLog(string message) public void AddLog(string message)
{ {
StreamWriter sw = new StreamWriter(dir + "log.txt", true); StreamWriter sw = new StreamWriter(dir + "log.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + message); sw.WriteLine(DateTime.Now.ToString() + ": " + message);
@ -463,7 +466,7 @@ namespace FireWallet
panelPortfolio.Visible = false; panelPortfolio.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In"; toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0; screen = 0;
textBoxaccountpassword.Focus();
} }
#endregion #endregion
#region API #region API
@ -622,8 +625,10 @@ namespace FireWallet
Control[] tmpControls = new Control[txCount]; Control[] tmpControls = new Control[txCount];
for (int i = 0; i < txCount; i++) for (int i = 0; i < txCount; i++)
{ {
// Get last tx // Get last tx
JObject tx = JObject.Parse(txs[txs.Count - 1 - i].ToString()); JObject tx = JObject.Parse(txs[txs.Count - 1 - i].ToString());
string hash = tx["hash"].ToString(); string hash = tx["hash"].ToString();
string date = tx["mdate"].ToString(); string date = tx["mdate"].ToString();
@ -641,7 +646,20 @@ namespace FireWallet
Location = new Point(10, 5) Location = new Point(10, 5)
} }
); );
int confirmations = Convert.ToInt32(tx["confirmations"].ToString());
if (userSettings.ContainsKey("confirmations"))
{
if (confirmations < Convert.ToInt32(userSettings["confirmations"]))
{
Label txPending = new Label()
{
Text = "Pending",
Location = new Point(100, 5)
};
tmpPanel.Controls.Add(txPending);
txPending.BringToFront();
}
}
Label labelHash = new Label() Label labelHash = new Label()
{ {
Text = "Hash: " + hash.Substring(0, 10) + "..." + hash.Substring(hash.Length - 10), Text = "Hash: " + hash.Substring(0, 10) + "..." + hash.Substring(hash.Length - 10),
@ -1007,7 +1025,9 @@ namespace FireWallet
if (e.KeyValue == 13) if (e.KeyValue == 13)
{ {
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
DomainForm domainForm = new DomainForm(textBoxDomainSearch.Text); DomainForm domainForm = new DomainForm(textBoxDomainSearch.Text, userSettings["explorer-tx"], userSettings["explorer-domain"]);
domainForm.OriginalForm = this;
domainForm.Show(); domainForm.Show();
} }