diff --git a/src/helper/p2pool.rs b/src/helper/p2pool.rs index 7ed5d25..9b0589e 100644 --- a/src/helper/p2pool.rs +++ b/src/helper/p2pool.rs @@ -76,7 +76,11 @@ impl Helper { ehr ); // multiply by a thousand because value is given as kH/s instead H/s - lock!(gui_api).sidechain_ehr = ehr * 1000.0; + lock!(gui_api).sidechain_ehr = ehr; + debug!( + "P2pool | PTY getting current estimated HR data from status: {} H/s", + lock!(gui_api).sidechain_ehr + ); } else { error!("P2pool | PTY Getting data from status: Lines contains Your shares but no value found: {}", line); } @@ -211,13 +215,13 @@ impl Helper { } // Takes in a 95-char Monero address, returns the first and last - // 6 characters separated with dots like so: [4abcde...abcdef] + // 8 characters separated with dots like so: [4abcdefg...abcdefgh] pub fn head_tail_of_monero_address(address: &str) -> String { if address.len() < 95 { return "???".to_string(); } - let head = &address[0..6]; - let tail = &address[89..95]; + let head = &address[0..8]; + let tail = &address[87..95]; head.to_owned() + "..." + tail } diff --git a/src/utils/regex.rs b/src/utils/regex.rs index 24255b6..190064a 100644 --- a/src/utils/regex.rs +++ b/src/utils/regex.rs @@ -17,6 +17,7 @@ // Some regexes used throughout Gupax. +use log::error; use once_cell::sync::Lazy; use regex::Regex; @@ -149,9 +150,23 @@ pub fn nb_current_shares(s: &str) -> Option { None } pub fn estimated_hr(s: &str) -> Option { - static CURRENT_SHARE: Lazy = - Lazy::new(|| Regex::new(r"(?P[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)").unwrap()); + static CURRENT_SHARE: Lazy = Lazy::new(|| { + Regex::new(r"(?P[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?) (?P.*)H/s").unwrap() + }); if let Some(c) = CURRENT_SHARE.captures(s) { + let coeff = if let Some(unit) = c.name("unit") { + match unit.as_str() { + "K" => 1000, + "M" => 1000 * 1000, + "G" => 1000 * 1000 * 1000, + _ => { + error!("unit of your p2pool sidechain HR is not recognized."); + 1 + } + } + } else { + 1 + } as f32; if let Some(m) = c.name("nb") { return Some( m.as_str().parse::().expect( @@ -160,7 +175,7 @@ pub fn estimated_hr(s: &str) -> Option { m.as_str(), ] .concat(), - ), + ) * coeff, ); } }