diff --git a/BidderGUI/Form1.Designer.cs b/BidderGUI/Form1.Designer.cs index 66d9b2d..cdb4b19 100644 --- a/BidderGUI/Form1.Designer.cs +++ b/BidderGUI/Form1.Designer.cs @@ -69,6 +69,8 @@ private void InitializeComponent() this.settingsgroupBox = new System.Windows.Forms.GroupBox(); this.label13 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.loglinesnumeric = new System.Windows.Forms.NumericUpDown(); + this.label15 = new System.Windows.Forms.Label(); this.timelabel = new System.Windows.Forms.Label(); this.countdowntimer = new System.Windows.Forms.Timer(this.components); this.groupBox1 = new System.Windows.Forms.GroupBox(); @@ -85,6 +87,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.batchsizenumericud)).BeginInit(); this.settingsgroupBox.SuspendLayout(); this.groupBox3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.loglinesnumeric)).BeginInit(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // @@ -327,7 +330,7 @@ private void InitializeComponent() this.intervalnumericUpDown.TabIndex = 4; this.intervalnumericUpDown.TabStop = false; this.intervalnumericUpDown.Value = new decimal(new int[] { - 10, + 600, 0, 0, 0}); @@ -335,11 +338,11 @@ private void InitializeComponent() // label10 // this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(235, 46); + this.label10.Location = new System.Drawing.Point(235, 48); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(50, 15); this.label10.TabIndex = 23; - this.label10.Text = "minutes"; + this.label10.Text = "seconds"; // // modecomboBox // @@ -518,6 +521,11 @@ private void InitializeComponent() this.batchsizenumericud.BackColor = System.Drawing.SystemColors.ControlDarkDark; this.batchsizenumericud.ForeColor = System.Drawing.Color.White; this.batchsizenumericud.Location = new System.Drawing.Point(88, 17); + this.batchsizenumericud.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); this.batchsizenumericud.Minimum = new decimal(new int[] { 10, 0, @@ -564,6 +572,8 @@ private void InitializeComponent() // groupBox3 // this.groupBox3.BackColor = System.Drawing.Color.Black; + this.groupBox3.Controls.Add(this.loglinesnumeric); + this.groupBox3.Controls.Add(this.label15); this.groupBox3.Controls.Add(this.logtextBox); this.groupBox3.Controls.Add(this.button4); this.groupBox3.ForeColor = System.Drawing.Color.White; @@ -574,6 +584,39 @@ private void InitializeComponent() this.groupBox3.TabStop = false; this.groupBox3.Text = "Logs"; // + // loglinesnumeric + // + this.loglinesnumeric.BackColor = System.Drawing.SystemColors.ControlDarkDark; + this.loglinesnumeric.ForeColor = System.Drawing.Color.White; + this.loglinesnumeric.Location = new System.Drawing.Point(878, 22); + this.loglinesnumeric.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.loglinesnumeric.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.loglinesnumeric.Name = "loglinesnumeric"; + this.loglinesnumeric.Size = new System.Drawing.Size(120, 23); + this.loglinesnumeric.TabIndex = 18; + this.loglinesnumeric.Value = new decimal(new int[] { + 10, + 0, + 0, + 0}); + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(808, 26); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(70, 15); + this.label15.TabIndex = 17; + this.label15.Text = "Log Length:"; + // // timelabel // this.timelabel.AutoSize = true; @@ -680,6 +723,7 @@ private void InitializeComponent() this.settingsgroupBox.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.loglinesnumeric)).EndInit(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.ResumeLayout(false); @@ -734,5 +778,7 @@ private void InitializeComponent() private Label label14; private Button regtestbutton; private Button mainnetbutton; + private NumericUpDown loglinesnumeric; + private Label label15; } } \ No newline at end of file diff --git a/BidderGUI/Form1.cs b/BidderGUI/Form1.cs index ac0b748..400f83f 100644 --- a/BidderGUI/Form1.cs +++ b/BidderGUI/Form1.cs @@ -41,7 +41,8 @@ void refreshdomain(string file) } else { - logtextBox.Text += "Domain already in list: " + domain + Environment.NewLine; + + addlog("Domain already in list: " + domain); } } filereader.Close(); @@ -49,8 +50,8 @@ void refreshdomain(string file) // Log errors to log textbox catch (Exception error) { - logtextBox.Text += "Error: " + error.Message + Environment.NewLine; + addlog("Error: " + error.Message); } @@ -62,7 +63,7 @@ async void test() // This will curl the below URL and return the result //curl http://x:api-key@127.0.0.1:12039/wallet/$id/account - logtextBox.Text = logtextBox.Text + "Testing: http://x:" + apitextBox.Text + "@"+ipporttextBox.Text+ Environment.NewLine; + addlog("Testing: http://x:" + apitextBox.Text + "@"+ipporttextBox.Text); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://"+ ipporttextBox.Text + "/wallet/"+wallettextBox.Text+ "/account"); // Add API key to header request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:"+apitextBox.Text))); @@ -73,12 +74,14 @@ async void test() HttpResponseMessage response = await httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); - logtextBox.Text = logtextBox.Text + responseBody + Environment.NewLine; + addlog(responseBody); + } // Log errors to log textbox catch (Exception error) { - logtextBox.Text = logtextBox.Text + "Error: "+ error.Message+ Environment.NewLine; + + addlog("Error: " + error.Message); } } @@ -184,7 +187,8 @@ async void sendtransaction() // Get domain string domain = domainslistBox.Items[0].ToString(); // Log transaction attempt - logtextBox.Text = logtextBox.Text + "Sending " + modecomboBox.Text + " for: " + domain + Environment.NewLine; + addlog("Sending " + modecomboBox.Text + " for: " + domain); + // Select mode if (modecomboBox.Text == "BID") @@ -236,7 +240,7 @@ async void sendtransaction() else { // Log error - logtextBox.Text = logtextBox.Text + "No Domains Found. Cancelled Sending" + Environment.NewLine; + addlog("No Domains Found. Cancelled Sending"); // Stop timers stopbutton.PerformClick(); @@ -246,7 +250,7 @@ async void sendtransaction() else { // Log error - logtextBox.Text = logtextBox.Text + "Invalid Mode. Cancelled Sending" + Environment.NewLine; + addlog("Invalid Mode.Cancelled Sending"); // Stop timers stopbutton.PerformClick(); } @@ -273,7 +277,7 @@ async void sendbatchbid(string[] domains) batch = batch.Substring(0, batch.Length - 2) + "]"; // Log transaction attempt - logtextBox.Text = logtextBox.Text + "Sending: " + batch + Environment.NewLine; + addlog("Sending: " + batch); // Create the API call request.Content = new StringContent("{\"method\": \"sendbatch\",\"params\":[ " + batch + "]}"); @@ -284,18 +288,24 @@ async void sendbatchbid(string[] domains) string responseBody = await response.Content.ReadAsStringAsync(); // Log response - logtextBox.Text = logtextBox.Text + responseBody + Environment.NewLine; + addlog(responseBody); - // Remove domains from list - foreach (string domain in domains) + // Check for errors + if (!Checkerrors(responseBody)) { - domainslistBox.Items.Remove(domain); + // Remove domains from list + foreach (string domain in domains) + { + domainslistBox.Items.Remove(domain); + } } + + // If there are no domains left in the list // Stop timers if (domainslistBox.Items.Count == 0) { - logtextBox.Text = logtextBox.Text + "All domains sent" + Environment.NewLine; + addlog("All domains sent"); stopbutton.PerformClick(); } } @@ -303,7 +313,7 @@ async void sendbatchbid(string[] domains) catch (Exception ex) { // Log error - logtextBox.Text = logtextBox.Text + "Error: " + ex.Message + Environment.NewLine; + addlog("Error: " + ex.Message); // Stop timers stopbutton.PerformClick(); } @@ -331,7 +341,7 @@ async void sendbatch(string[] domains, string method) batch = batch.Substring(0, batch.Length - 2) + "]"; // Log transaction attempt - logtextBox.Text = logtextBox.Text + "Sending: " + batch + Environment.NewLine; + addlog("Sending: " + batch); // Create the API call request.Content = new StringContent("{\"method\": \"sendbatch\",\"params\":[ " + batch + "]}"); @@ -342,18 +352,22 @@ async void sendbatch(string[] domains, string method) string responseBody = await response.Content.ReadAsStringAsync(); // Log response - logtextBox.Text = logtextBox.Text + responseBody + Environment.NewLine; + addlog(responseBody); // Remove domains from list - foreach (string domain in domains) + if (!Checkerrors(responseBody)) { - domainslistBox.Items.Remove(domain); + // Remove domains from list + foreach (string domain in domains) + { + domainslistBox.Items.Remove(domain); + } } // If there are no domains left in the list // Stop timers if (domainslistBox.Items.Count == 0) { - logtextBox.Text = logtextBox.Text + "All domains sent" + Environment.NewLine; + addlog("All domains sent"); stopbutton.PerformClick(); } } @@ -361,7 +375,7 @@ async void sendbatch(string[] domains, string method) catch (Exception ex) { // Log error - logtextBox.Text = logtextBox.Text + "Error: " + ex.Message + Environment.NewLine; + addlog("Error: " + ex.Message); // Stop timers stopbutton.PerformClick(); } @@ -371,7 +385,7 @@ async void sendbatch(string[] domains, string method) async Task unlockwallet() { // Unlocking wallet - logtextBox.Text = logtextBox.Text + "Unlocking Wallet using passphrase" + Environment.NewLine; + addlog("Unlocking Wallet using passphrase"); HttpRequestMessage unlockwalletreq = new HttpRequestMessage(HttpMethod.Post, "http://" + ipporttextBox.Text + "/wallet/" + wallettextBox.Text + "/unlock"); unlockwalletreq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + apitextBox.Text))); unlockwalletreq.Content = new StringContent("{\"passphrase\": \"" + passtextBox.Text + "\",\"timeout\": 60}"); @@ -383,7 +397,7 @@ async Task unlockwallet() unlockwalletresp.EnsureSuccessStatusCode(); // Select wallet - logtextBox.Text = logtextBox.Text + "Selecting Wallet" + Environment.NewLine; + addlog("Selecting Wallet"); HttpRequestMessage selectwalletreq = new HttpRequestMessage(HttpMethod.Post, "http://" + ipporttextBox.Text); selectwalletreq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + apitextBox.Text))); selectwalletreq.Content = new StringContent("{\"method\": \"selectwallet\",\"params\":[ \"" + wallettextBox.Text + "\"]}"); @@ -405,16 +419,21 @@ async void sendapicall(HttpRequestMessage request,string domain) string responseBody = await response.Content.ReadAsStringAsync(); // Log response - logtextBox.Text = logtextBox.Text + responseBody + Environment.NewLine; - + addlog(responseBody); // Remove domain from list - domainslistBox.Items.Remove(domain); + if (!Checkerrors(responseBody)) + { + // Remove domains from list + domainslistBox.Items.Remove(domain); + + } + } // If there is an error catch (Exception ex) { // Log error - logtextBox.Text = logtextBox.Text + "Error: " + ex.Message + Environment.NewLine; + addlog("Error: " + ex.Message); // Stop timers stopbutton.PerformClick(); } @@ -448,8 +467,7 @@ private void removebutton_Click(object sender, EventArgs e) } catch (Exception ex) { - logtextBox.Text = logtextBox.Text + "Error: " + ex.Message + Environment.NewLine; - + addlog("Error: " + ex.Message); } } @@ -506,7 +524,7 @@ private void export_button_Click(object sender, EventArgs e) catch (Exception ex) { // Log error - logtextBox.Text = logtextBox.Text + "Error: " + ex.Message + Environment.NewLine; + addlog("Error: " + ex.Message); } } @@ -553,5 +571,41 @@ private void button_cleardomains_Click(object sender, EventArgs e) { domainslistBox.Items.Clear(); } + string[] errors = { "tx exceeds maximum unconfirmed ancestors" ,"error\":{\"message"}; + public bool Checkerrors(string log) + { + log = log.ToLower(); + // If there is an error in the log + foreach (string error in errors) + { + if (log.Contains(error)) + { + stopbutton.PerformClick(); + // Log error + addlog("Errors Found"); + return true; + } + } + return false; + } + public void addlog(string log) + { + // Count lines in log textbox + string[] lines = logtextBox.Text.Split(Environment.NewLine); + int numlines = lines.Length; + int maxlines = Convert.ToInt32(loglinesnumeric.Value) - 1; + + string[] newlines = new string[maxlines]; + if (numlines > maxlines) + { + Array.Copy(lines, numlines- maxlines, newlines, 0, maxlines); + } + else + { + newlines = lines; + } + + logtextBox.Text = string.Join(Environment.NewLine, newlines) + Environment.NewLine + log; + } } } \ No newline at end of file