main: Added cold wallet sending HNS

This commit is contained in:
Nathan Woodburn 2023-06-09 12:56:27 +10:00
parent 0f84462a03
commit 43c064fd7d
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 156 additions and 75 deletions

View File

@ -111,6 +111,7 @@ namespace FireWallet
textBoxExAddr = new TextBox(); textBoxExAddr = new TextBox();
labelSettings4 = new Label(); labelSettings4 = new Label();
textBoxExTX = new TextBox(); textBoxExTX = new TextBox();
toolStripStatusLabelLedger = new ToolStripStatusLabel();
statusStripmain.SuspendLayout(); statusStripmain.SuspendLayout();
panelaccount.SuspendLayout(); panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout(); groupBoxaccount.SuspendLayout();
@ -134,7 +135,7 @@ namespace FireWallet
// statusStripmain // statusStripmain
// //
statusStripmain.Dock = DockStyle.Top; statusStripmain.Dock = DockStyle.Top;
statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus, toolStripStatusLabelaccount, toolStripSplitButtonlogout }); statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus, toolStripStatusLabelaccount, toolStripStatusLabelLedger, toolStripSplitButtonlogout });
statusStripmain.Location = new Point(0, 0); statusStripmain.Location = new Point(0, 0);
statusStripmain.Name = "statusStripmain"; statusStripmain.Name = "statusStripmain";
statusStripmain.Size = new Size(1152, 22); statusStripmain.Size = new Size(1152, 22);
@ -748,7 +749,7 @@ namespace FireWallet
buttonSettingsRescan.FlatStyle = FlatStyle.Flat; buttonSettingsRescan.FlatStyle = FlatStyle.Flat;
buttonSettingsRescan.Location = new Point(6, 20); buttonSettingsRescan.Location = new Point(6, 20);
buttonSettingsRescan.Name = "buttonSettingsRescan"; buttonSettingsRescan.Name = "buttonSettingsRescan";
buttonSettingsRescan.Size = new Size(98, 53); buttonSettingsRescan.Size = new Size(98, 50);
buttonSettingsRescan.TabIndex = 8; buttonSettingsRescan.TabIndex = 8;
buttonSettingsRescan.Text = "Rescan"; buttonSettingsRescan.Text = "Rescan";
buttonSettingsRescan.UseVisualStyleBackColor = true; buttonSettingsRescan.UseVisualStyleBackColor = true;
@ -757,9 +758,9 @@ namespace FireWallet
// buttonSeed // buttonSeed
// //
buttonSeed.FlatStyle = FlatStyle.Flat; buttonSeed.FlatStyle = FlatStyle.Flat;
buttonSeed.Location = new Point(297, 15); buttonSeed.Location = new Point(297, 20);
buttonSeed.Name = "buttonSeed"; buttonSeed.Name = "buttonSeed";
buttonSeed.Size = new Size(117, 53); buttonSeed.Size = new Size(117, 50);
buttonSeed.TabIndex = 8; buttonSeed.TabIndex = 8;
buttonSeed.Text = "Seed Phrase"; buttonSeed.Text = "Seed Phrase";
buttonSeed.UseVisualStyleBackColor = true; buttonSeed.UseVisualStyleBackColor = true;
@ -936,6 +937,13 @@ namespace FireWallet
textBoxExTX.Size = new Size(307, 29); textBoxExTX.Size = new Size(307, 29);
textBoxExTX.TabIndex = 1; textBoxExTX.TabIndex = 1;
// //
// toolStripStatusLabelLedger
//
toolStripStatusLabelLedger.Margin = new Padding(50, 3, 50, 2);
toolStripStatusLabelLedger.Name = "toolStripStatusLabelLedger";
toolStripStatusLabelLedger.Size = new Size(71, 17);
toolStripStatusLabelLedger.Text = "Cold Wallet:";
//
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -1065,5 +1073,6 @@ namespace FireWallet
private Button buttonSeed; private Button buttonSeed;
private GroupBox groupBoxSettingsWallet; private GroupBox groupBoxSettingsWallet;
private Button buttonSettingsRescan; private Button buttonSettingsRescan;
private ToolStripStatusLabel toolStripStatusLabelLedger;
} }
} }

View File

@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Security.Policy; using System.Security.Policy;
using System.Windows.Forms;
namespace FireWallet namespace FireWallet
{ {
@ -27,7 +28,8 @@ namespace FireWallet
public double syncProgress { get; set; } public double syncProgress { get; set; }
public int pendingTransactions { get; set; } public int pendingTransactions { get; set; }
public bool batchMode { get; set; } public bool batchMode { get; set; }
BatchForm batchForm { get; set; } public BatchForm batchForm { get; set; }
public bool watchOnly { get; set; }
#endregion #endregion
#region Application #region Application
@ -37,6 +39,7 @@ namespace FireWallet
} }
private void MainForm_Load(object sender, EventArgs e) private void MainForm_Load(object sender, EventArgs e)
{ {
watchOnly = false;
account = ""; account = "";
timerNodeStatus.Stop(); timerNodeStatus.Stop();
LoadSettings(); LoadSettings();
@ -447,6 +450,13 @@ namespace FireWallet
return false; return false;
} }
UpdateBalance(); UpdateBalance();
path = "wallet/" + account + "";
APIresponse = await APIGet(path, true);
JObject jObject = JObject.Parse(APIresponse);
if (jObject["watchOnly"].ToString() == "True") watchOnly = true;
else watchOnly = false;
toolStripStatusLabelLedger.Text = "Cold Wallet: " + watchOnly.ToString();
return true; return true;
} }
@ -940,29 +950,6 @@ namespace FireWallet
labelSendingError.Show(); labelSendingError.Show();
labelSendingError.Text = "HIP-02 Not supported yet"; labelSendingError.Text = "HIP-02 Not supported yet";
return; return;
/*
string domain = textBoxSendingTo.Text.Substring(1);
try
{
string address = "";
bool valid = await ValidAddress(address);
if (valid)
{
labelSendingError.Hide();
labelSendingError.Text = "";
}
else
{
labelSendingError.Show();
labelSendingError.Text = "Invalid Address";
}
}
catch (Exception ex)
{
labelSendingError.Show();
labelSendingError.Text = ex.Message;
}*/
} }
else else
{ {
@ -987,7 +974,6 @@ namespace FireWallet
} }
} }
} }
private void textBoxSendingAmount_Leave(object sender, EventArgs e) private void textBoxSendingAmount_Leave(object sender, EventArgs e)
{ {
decimal amount = 0; decimal amount = 0;
@ -1040,6 +1026,9 @@ namespace FireWallet
return; return;
} }
if (!watchOnly)
{
AddLog("Sending " + amount.ToString() + " HNS to " + address); AddLog("Sending " + amount.ToString() + " HNS to " + address);
string content = "{\"method\": \"sendtoaddress\",\"params\": [ \"" + address + "\", " + string content = "{\"method\": \"sendtoaddress\",\"params\": [ \"" + address + "\", " +
amount.ToString() + ", \"\", \"\", " + subtractFee + " ]}"; amount.ToString() + ", \"\", \"\", " + subtractFee + " ]}";
@ -1063,6 +1052,65 @@ namespace FireWallet
labelSendingError.Hide(); labelSendingError.Hide();
labelSendingError.Text = ""; labelSendingError.Text = "";
buttonNavPortfolio.PerformClick(); buttonNavPortfolio.PerformClick();
} else // Cold wallet signing
{
AddLog("Sending CW " + amount.ToString() + " HNS to " + address);
if (!Directory.Exists(dir + "hsd-ledger"))
{
return; // TODO: Create all the ledger stuff
}
NotifyForm notify = new NotifyForm("Please confirm the transaction on your Ledger device",false);
notify.Show();
var proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName = "node.exe";
proc.StartInfo.Arguments = dir + "hsd-ledger/bin/hsd-ledger sendtoaddress " + textBoxSendingTo.Text
+ " " + textBoxSendingAmount.Text + " --api-key " + nodeSettings["Key"] + " -w " + account;
var outputBuilder = new StringBuilder();
// Event handler for capturing output data
proc.OutputDataReceived += (sender, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
outputBuilder.AppendLine(args.Data);
}
};
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();
notify.CloseNotification();
notify.Dispose();
string output = outputBuilder.ToString();
AddLog(output);
if (output.Contains("Submitted TXID"))
{
string hash = output.Substring(output.IndexOf("Submitted TXID") + 16, 64);
string link = userSettings["explorer-tx"] + hash;
NotifyForm notifySuccess = new NotifyForm("Transaction Sent\nThis transaction could take up to 20 minutes to mine",
"Explorer", link);
notifySuccess.ShowDialog();
textBoxSendingTo.Text = "";
textBoxSendingAmount.Text = "";
buttonNavPortfolio.PerformClick();
} else
{
NotifyForm notifyError = new NotifyForm("Error Transaction Failed\nCheck logs for more details");
notifyError.ShowDialog();
notifyError.Dispose();
}
}
} }
catch (Exception ex) catch (Exception ex)
@ -1128,6 +1176,25 @@ namespace FireWallet
i++; i++;
} }
} }
private void textBoxDomainSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
textBoxDomainSearch.Text = textBoxDomainSearch.Text.Trim().ToLower();
e.SuppressKeyPress = true;
DomainForm domainForm = new DomainForm(this, textBoxDomainSearch.Text, userSettings["explorer-tx"], userSettings["explorer-domain"]);
domainForm.Show();
}
}
private void textBoxDomainSearch_TextChanged(object sender, EventArgs e)
{
string domainSearch = textBoxDomainSearch.Text;
domainSearch = Regex.Replace(textBoxDomainSearch.Text, "[^a-zA-Z0-9-_]", "");
textBoxDomainSearch.Text = domainSearch;
}
#endregion #endregion
#region Batching #region Batching
public void AddBatch(string domain, string operation) public void AddBatch(string domain, string operation)
@ -1180,28 +1247,7 @@ namespace FireWallet
else batchForm.Focus(); else batchForm.Focus();
} }
#endregion #endregion
#region SettingsPage
private void textBoxDomainSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
textBoxDomainSearch.Text = textBoxDomainSearch.Text.Trim().ToLower();
e.SuppressKeyPress = true;
DomainForm domainForm = new DomainForm(this, textBoxDomainSearch.Text, userSettings["explorer-tx"], userSettings["explorer-domain"]);
domainForm.Show();
}
}
private void textBoxDomainSearch_TextChanged(object sender, EventArgs e)
{
string domainSearch = textBoxDomainSearch.Text;
domainSearch = Regex.Replace(textBoxDomainSearch.Text, "[^a-zA-Z0-9-_]", "");
textBoxDomainSearch.Text = domainSearch;
}
#region Settings
private void buttonSettingsSave_Click(object sender, EventArgs e) private void buttonSettingsSave_Click(object sender, EventArgs e)
{ {
StreamWriter sw = new StreamWriter(dir + "settings.txt"); StreamWriter sw = new StreamWriter(dir + "settings.txt");
@ -1270,8 +1316,6 @@ namespace FireWallet
} }
} }
#endregion
private async void Rescan_Click(object sender, EventArgs e) private async void Rescan_Click(object sender, EventArgs e)
{ {
string content = "{\"height\": 0}"; string content = "{\"height\": 0}";
@ -1285,5 +1329,11 @@ namespace FireWallet
AddLog("Starting rescan"); AddLog("Starting rescan");
} }
#endregion
} }
} }

View File

@ -82,8 +82,10 @@ namespace FireWallet
Controls.Add(labelmessage); Controls.Add(labelmessage);
FormBorderStyle = FormBorderStyle.FixedDialog; FormBorderStyle = FormBorderStyle.FixedDialog;
Icon = (Icon)resources.GetObject("$this.Icon"); Icon = (Icon)resources.GetObject("$this.Icon");
MaximizeBox = false;
Name = "NotifyForm"; Name = "NotifyForm";
Text = "FireWallet"; Text = "FireWallet";
FormClosing += NotifyForm_FormClosing;
Load += NotifyForm_Load; Load += NotifyForm_Load;
ResumeLayout(false); ResumeLayout(false);
} }

View File

@ -19,13 +19,17 @@ namespace FireWallet
Dictionary<string, string> theme; Dictionary<string, string> theme;
string altLink; string altLink;
bool Linkcopy; bool Linkcopy;
bool allowClose = true;
public NotifyForm(string Message) public NotifyForm(string Message)
{ {
InitializeComponent(); InitializeComponent();
labelmessage.Text = Message; labelmessage.Text = Message;
altLink = ""; altLink = "";
} }
public void CloseNotification()
{
this.Close();
}
public NotifyForm(string Message, string altText, string altLink) public NotifyForm(string Message, string altText, string altLink)
{ {
InitializeComponent(); InitializeComponent();
@ -36,6 +40,16 @@ namespace FireWallet
buttonOK.Focus(); buttonOK.Focus();
Linkcopy = false; Linkcopy = false;
} }
public NotifyForm(string Message, bool allowClose)
{
InitializeComponent();
labelmessage.Text = Message;
buttonOK.Focus();
Linkcopy = false;
buttonOK.Visible = allowClose;
allowClose = allowClose;
}
public NotifyForm(string Message, string altText, string altLink, bool Linkcopy) public NotifyForm(string Message, string altText, string altLink, bool Linkcopy)
{ {
InitializeComponent(); InitializeComponent();
@ -233,6 +247,7 @@ namespace FireWallet
private void OK_Click(object sender, EventArgs e) private void OK_Click(object sender, EventArgs e)
{ {
allowClose = true;
this.Close(); this.Close();
} }
@ -252,5 +267,10 @@ namespace FireWallet
}; };
Process.Start(psi); Process.Start(psi);
} }
private void NotifyForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (!allowClose) e.Cancel = true;
}
} }
} }