From 54d5c63db7575d802546c103c5f25c44e3f13e3c Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 26 Jun 2023 18:48:12 +1000 Subject: [PATCH] multisig: Finished signing for hot wallets --- FireWallet/ImportTXForm.Designer.cs | 35 +++++++++++++- FireWallet/ImportTXForm.cs | 75 ++++++++++++++++++++++++++--- FireWallet/MainForm.cs | 2 +- 3 files changed, 103 insertions(+), 9 deletions(-) diff --git a/FireWallet/ImportTXForm.Designer.cs b/FireWallet/ImportTXForm.Designer.cs index 2e46a28..3007d92 100644 --- a/FireWallet/ImportTXForm.Designer.cs +++ b/FireWallet/ImportTXForm.Designer.cs @@ -40,6 +40,8 @@ labelSigsReq = new Label(); labelSigsSigned = new Label(); labelSigInfo = new Label(); + buttonExport = new Button(); + buttonSend = new Button(); groupBoxIn.SuspendLayout(); groupBoxOut.SuspendLayout(); SuspendLayout(); @@ -86,7 +88,7 @@ // buttonSign.FlatStyle = FlatStyle.Flat; buttonSign.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - buttonSign.Location = new Point(789, 444); + buttonSign.Location = new Point(700, 444); buttonSign.Name = "buttonSign"; buttonSign.Size = new Size(83, 36); buttonSign.TabIndex = 2; @@ -98,7 +100,7 @@ // Cancelbutton2.FlatStyle = FlatStyle.Flat; Cancelbutton2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - Cancelbutton2.Location = new Point(700, 444); + Cancelbutton2.Location = new Point(12, 441); Cancelbutton2.Name = "Cancelbutton2"; Cancelbutton2.Size = new Size(83, 36); Cancelbutton2.TabIndex = 2; @@ -150,6 +152,31 @@ labelSigInfo.TabIndex = 8; labelSigInfo.Text = "#"; // + // buttonExport + // + buttonExport.Enabled = false; + buttonExport.FlatStyle = FlatStyle.Flat; + buttonExport.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + buttonExport.Location = new Point(611, 444); + buttonExport.Name = "buttonExport"; + buttonExport.Size = new Size(83, 36); + buttonExport.TabIndex = 2; + buttonExport.Text = "Export"; + buttonExport.UseVisualStyleBackColor = true; + buttonExport.Click += buttonExport_Click; + // + // buttonSend + // + buttonSend.FlatStyle = FlatStyle.Flat; + buttonSend.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + buttonSend.Location = new Point(789, 444); + buttonSend.Name = "buttonSend"; + buttonSend.Size = new Size(83, 36); + buttonSend.TabIndex = 2; + buttonSend.Text = "Send"; + buttonSend.UseVisualStyleBackColor = true; + buttonSend.Click += buttonSend_Click; + // // ImportTXForm // AutoScaleDimensions = new SizeF(7F, 15F); @@ -162,6 +189,8 @@ Controls.Add(label1); Controls.Add(groupBoxOut); Controls.Add(groupBoxIn); + Controls.Add(buttonSend); + Controls.Add(buttonExport); Controls.Add(Cancelbutton2); Controls.Add(buttonSign); FormBorderStyle = FormBorderStyle.FixedSingle; @@ -188,5 +217,7 @@ private Label labelSigsReq; private Label labelSigsSigned; private Label labelSigInfo; + private Button buttonExport; + private Button buttonSend; } } \ No newline at end of file diff --git a/FireWallet/ImportTXForm.cs b/FireWallet/ImportTXForm.cs index ab9de67..7a4c41b 100644 --- a/FireWallet/ImportTXForm.cs +++ b/FireWallet/ImportTXForm.cs @@ -9,6 +9,7 @@ namespace FireWallet int totalSigs; int reqSigs; int sigs; + string signedTX; public ImportTXForm(MainForm mainForm) { InitializeComponent(); @@ -18,6 +19,7 @@ namespace FireWallet private void ImportTXForm_Load(object sender, EventArgs e) { // Default variables + signedTX = ""; totalSigs = 3; reqSigs = 2; sigs = 0; @@ -109,7 +111,7 @@ namespace FireWallet JObject sigGetResult = (JObject)sigGetJson["result"]; string[] asm = sigGetResult["asm"].ToString().Split(" "); string totalSigsStr = asm[asm.Length - 2]; - totalSigs = int.Parse(totalSigsStr.Replace("OP_","")); + totalSigs = int.Parse(totalSigsStr.Replace("OP_", "")); reqSigs = int.Parse(sigGetResult["reqSigs"].ToString()); sigs = -1; for (int i = 0; i < witnesses.Count; i++) @@ -121,14 +123,14 @@ namespace FireWallet } } - + // Set sig label sizes labelSigsReq.Width = (labelSigsTotal.Width / totalSigs) * reqSigs; labelSigsSigned.Width = (labelSigsTotal.Width / totalSigs) * sigs; - labelSigInfo.Text = "Signed: " + sigs + "\nReq: " + reqSigs + " of "+ totalSigs; + labelSigInfo.Text = "Signed: " + sigs + "\nReq: " + reqSigs + " of " + totalSigs; @@ -267,9 +269,70 @@ namespace FireWallet private async void buttonSign_Click(object sender, EventArgs e) { - string content = "{\"tx\":\"" + tx["tx"].ToString() + "\", \"passphrase\":\"" + mainForm.Password + "\"}"; - string response = await mainForm.APIPost("wallet/" + mainForm.Account + "/sign", true, content); - mainForm.AddLog(response); + if (!mainForm.WatchOnly) + { + string content = "{\"tx\":\"" + tx["tx"].ToString() + "\", \"passphrase\":\"" + mainForm.Password + "\"}"; + string response = await mainForm.APIPost("wallet/" + mainForm.Account + "/sign", true, content); + if (response == "Error" || response == "") + { + NotifyForm notifyForm = new NotifyForm("Error signing transaction"); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + return; + } + buttonSign.Enabled = false; + buttonExport.Enabled = true; + sigs++; + // Set sig label sizes + labelSigsReq.Width = (labelSigsTotal.Width / totalSigs) * reqSigs; + labelSigsSigned.Width = (labelSigsTotal.Width / totalSigs) * sigs; + labelSigInfo.Text = "Signed: " + sigs + "\nReq: " + reqSigs + " of " + totalSigs; + signedTX = response; + } + } + + private void buttonExport_Click(object sender, EventArgs e) + { + mainForm.ExportTransaction(signedTX); + } + + private async void buttonSend_Click(object sender, EventArgs e) + { + string content = ""; + if (signedTX != "") + { + JObject signed = JObject.Parse(signedTX); + content = "{\"method\":\"sendrawtransaction\", \"params\":[\"" + signed["hex"].ToString() + "\"]}"; + } + else + { + content = "{\"method\":\"sendrawtransaction\", \"params\":[\"" + tx["tx"].ToString() + "\"]}"; + } + string response = await mainForm.APIPost("", false, content); + if (response == "Error" || response == "") + { + mainForm.AddLog(response); + NotifyForm notifyError = new NotifyForm("Error sending transaction"); + notifyError.ShowDialog(); + notifyError.Dispose(); + return; + } + JObject responseJson = JObject.Parse(response); + if (responseJson["error"].ToString() != "") + { + mainForm.AddLog(response); + JObject error = (JObject)responseJson["error"]; + NotifyForm notifyError = new NotifyForm("Error sending transaction\n" + error["message"].ToString()); + notifyError.ShowDialog(); + notifyError.Dispose(); + return; + } + string txHash = responseJson["result"].ToString(); + NotifyForm notifyForm = new NotifyForm("Transaction sent\nIf the transaction hasn't been signed it might not be mined", "Explorer", mainForm.UserSettings["explorer-tx"] + txHash); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + this.Close(); + } } } diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index dc7134f..e769fc1 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -2699,7 +2699,7 @@ namespace FireWallet #region Multi - private void ExportTransaction(string rawTX) + public void ExportTransaction(string rawTX) { JObject tx = JObject.Parse(rawTX); JObject toExport = new JObject();