mirror of
https://github.com/Nathanwoodburn/FireWallet.git
synced 2024-11-24 08:08:14 +11:00
main: Cold wallet batching
This commit is contained in:
parent
43c064fd7d
commit
b1e3cd5818
@ -1,6 +1,9 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Text;
|
||||||
using Microsoft.VisualBasic;
|
using Microsoft.VisualBasic;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Point = System.Drawing.Point;
|
using Point = System.Drawing.Point;
|
||||||
@ -460,6 +463,8 @@ namespace FireWallet
|
|||||||
}
|
}
|
||||||
HttpClient httpClient = new HttpClient();
|
HttpClient httpClient = new HttpClient();
|
||||||
private async void buttonSend_Click(object sender, EventArgs e)
|
private async void buttonSend_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!mainForm.watchOnly)
|
||||||
{
|
{
|
||||||
string batchTX = "[" + string.Join(", ", batches.Select(batch => batch.ToString())) + "]";
|
string batchTX = "[" + string.Join(", ", batches.Select(batch => batch.ToString())) + "]";
|
||||||
string content = "{\"method\": \"sendbatch\",\"params\":[ " + batchTX + "]}";
|
string content = "{\"method\": \"sendbatch\",\"params\":[ " + batchTX + "]}";
|
||||||
@ -493,6 +498,89 @@ namespace FireWallet
|
|||||||
notifyForm2.Dispose();
|
notifyForm2.Dispose();
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
else // watch only
|
||||||
|
{
|
||||||
|
string batchTX = "[" + string.Join(", ", batches.Select(batch => batch.ToString())) + "]";
|
||||||
|
string content = "{\"method\": \"createbatch\",\"params\":[ " + batchTX + "]}";
|
||||||
|
string response = await APIPost("", true, content);
|
||||||
|
|
||||||
|
if (response == "Error")
|
||||||
|
{
|
||||||
|
AddLog("Error creating batch");
|
||||||
|
NotifyForm notifyForm = new NotifyForm("Error creating batch");
|
||||||
|
notifyForm.ShowDialog();
|
||||||
|
notifyForm.Dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JObject jObject = JObject.Parse(response);
|
||||||
|
if (jObject["error"].ToString() != "")
|
||||||
|
{
|
||||||
|
AddLog("Error: ");
|
||||||
|
AddLog(jObject["error"].ToString());
|
||||||
|
NotifyForm notifyForm = new NotifyForm("Error: \n" + jObject["error"].ToString());
|
||||||
|
notifyForm.ShowDialog();
|
||||||
|
notifyForm.Dispose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamWriter sw = new StreamWriter(dir + "hsd-ledger/bin/names.txt");
|
||||||
|
string domainslist = string.Join(",", batches.Select(batch => batch.domain));
|
||||||
|
sw.Write(domainslist);
|
||||||
|
sw.Dispose();
|
||||||
|
StreamWriter sw2 = new StreamWriter(dir + "hsd-ledger/bin/batch.json");
|
||||||
|
sw2.Write(response);
|
||||||
|
sw2.Dispose();
|
||||||
|
|
||||||
|
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.WorkingDirectory = dir + "hsd-ledger/bin/";
|
||||||
|
proc.StartInfo.Arguments = dir + "hsd-ledger/bin/hsd-ledger sendraw batch.json names.txt --api-key " + mainForm.nodeSettings["Key"] + " -w " + mainForm.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 = mainForm.userSettings["explorer-tx"] + hash;
|
||||||
|
NotifyForm notifySuccess = new NotifyForm("Transaction Sent\nThis transaction could take up to 20 minutes to mine",
|
||||||
|
"Explorer", link);
|
||||||
|
notifySuccess.ShowDialog();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NotifyForm notifyError = new NotifyForm("Error Transaction Failed\nCheck logs for more details");
|
||||||
|
notifyError.ShowDialog();
|
||||||
|
notifyError.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void BatchForm_FormClosing(object sender, FormClosingEventArgs e)
|
private void BatchForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user