From e1829f967c0f921cff383c59e7660f3a26a2406d Mon Sep 17 00:00:00 2001 From: hinto-janaiyo Date: Tue, 6 Dec 2022 13:18:40 -0500 Subject: [PATCH] helper: p2pool - process output regardless of API file status --- src/helper.rs | 69 +++++++++++++++++++++++++++------------------------ src/main.rs | 2 +- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/helper.rs b/src/helper.rs index 04cd40a..3463935 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -391,12 +391,15 @@ impl Helper { } drop(lock); + // Always update from output + PubP2poolApi::update_from_output(&pub_api, &output, process.lock().unwrap().start.elapsed().as_secs_f64(), ®ex); + // Read API file into string if let Ok(string) = Self::read_p2pool_api(&path) { // Deserialize if let Ok(s) = Self::str_to_priv_p2pool_api(&string) { // Update the structs. - PubP2poolApi::update_from_priv(&pub_api, &priv_api, &output, process.lock().unwrap().start.elapsed().as_secs_f64(), ®ex); + PubP2poolApi::update_from_priv(&pub_api, &priv_api); } } @@ -740,23 +743,46 @@ impl PubP2poolApi { } } - // Mutate [PubP2poolApi] with data from a [PrivP2poolApi] and the process output. - fn update_from_priv(public: &Arc>, private: &Arc>, output: &Arc>, start: f64, regex: &P2poolRegex) { - let public_clone = public.lock().unwrap().clone(); + // Mutate [PubP2poolApi] with data the process output. + fn update_from_output(public: &Arc>, output: &Arc>, elapsed: f64, regex: &P2poolRegex) { let output = output.lock().unwrap().clone(); // 1. Parse STDOUT let (payouts, xmr) = Self::calc_payouts_and_xmr(&output, ®ex); - let stdout_parse = Self { + + // 2. Calculate hour/day/month given elapsed time + // Payouts + let per_sec = (payouts as f64) / elapsed; + let payouts_hour = (per_sec * 60.0) * 60.0; + let payouts_day = payouts_hour * 24.0; + let payouts_month = payouts_day * 30.0; + // Total XMR + let per_sec = xmr / elapsed; + let xmr_hour = (per_sec * 60.0) * 60.0; + let xmr_day = payouts_hour * 24.0; + let xmr_month = payouts_day * 30.0; + + // 3. Mutate the struct with the new info + let mut public = public.lock().unwrap(); + *public = Self { output, payouts, xmr, - ..public_clone // <- So useful + payouts_hour, + payouts_day, + payouts_month, + xmr_hour, + xmr_day, + xmr_month, + ..public.clone() }; - // 2. Time calculations - let hour_day_month = Self::update_hour_day_month(stdout_parse, start); + } + + // Mutate [PubP2poolApi] with data from a [PrivP2poolApi] and the process output. + fn update_from_priv(public: &Arc>, private: &Arc>) { // 3. Final priv -> pub conversion let private = private.lock().unwrap(); - *public.lock().unwrap() = Self { + let mut public = public.lock().unwrap(); + *public = Self { hashrate_15m: HumanNumber::from_u128(private.hashrate_15m), hashrate_1h: HumanNumber::from_u128(private.hashrate_1h), hashrate_24h: HumanNumber::from_u128(private.hashrate_24h), @@ -764,7 +790,7 @@ impl PubP2poolApi { average_effort: HumanNumber::to_percent(private.average_effort), current_effort: HumanNumber::to_percent(private.current_effort), connections: HumanNumber::from_u16(private.connections), - ..hour_day_month // <- Holy cow this is so good + ..public.clone() } } @@ -782,29 +808,6 @@ impl PubP2poolApi { } (count, result) } - - // Updates the struct with hour/day/month calculations given an uptime in f64 seconds. - fn update_hour_day_month(self, elapsed: f64) -> Self { - // Payouts - let per_sec = (self.payouts as f64) / elapsed; - let payouts_hour = (per_sec * 60.0) * 60.0; - let payouts_day = payouts_hour * 24.0; - let payouts_month = payouts_day * 30.0; - // Total XMR - let per_sec = self.xmr / elapsed; - let xmr_hour = (per_sec * 60.0) * 60.0; - let xmr_day = payouts_hour * 24.0; - let xmr_month = payouts_day * 30.0; - Self { - payouts_hour, - payouts_day, - payouts_month, - xmr_hour, - xmr_day, - xmr_month, - ..self - } - } } //---------------------------------------------------------------------------------------------------- Private P2Pool API diff --git a/src/main.rs b/src/main.rs index a0924cf..2f7b32b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1074,7 +1074,7 @@ impl eframe::App for App { ui.add_sized([width, height], Button::new("⏹")).on_hover_text("Stop XMRig"); }); if ui.add_sized([width, height], Button::new("⏺")).on_hover_text("Start XMRig").clicked() { - Helper::spawn_xmrig(&self.helper, &self.state.xmrig, self.state.gupax.absolute_xmrig_path.clone()); +// Helper::spawn_xmrig(&self.helper, &self.state.xmrig, self.state.gupax.absolute_xmrig_path.clone()); } } });