From a450f1e68493177d7cf00b2622904252e1aabd9b Mon Sep 17 00:00:00 2001 From: mostafaei2002 Date: Tue, 11 Jun 2024 23:05:21 +0330 Subject: [PATCH] fix: formatting --- src/app/mod.rs | 3 ++- src/app/panels/bottom.rs | 10 +++------ src/app/panels/middle/xvb.rs | 33 ++++++++++++------------------ src/disk/state.rs | 2 +- src/helper/tests.rs | 21 +++++++++---------- src/helper/xvb/algorithm.rs | 39 ++++++++++++++++++++++-------------- src/helper/xvb/mod.rs | 3 +-- src/helper/xvb/priv_stats.rs | 21 ++++++++++--------- src/utils/constants.rs | 14 +++++++------ 9 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index e241338..18f24a7 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -527,7 +527,8 @@ impl App { // Set saved Hero mode to runtime. debug!("Setting runtime_mode & runtime_manual_amount"); app.xvb_api.lock().unwrap().stats_priv.runtime_mode = app.state.xvb.mode.clone().into(); - app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = app.state.xvb.manual_amount_raw; + app.xvb_api.lock().unwrap().stats_priv.runtime_manual_amount = + app.state.xvb.manual_amount_raw; // Check if [P2pool.node] exists info!("App Init | Checking if saved remote node still exists..."); app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node); diff --git a/src/app/panels/bottom.rs b/src/app/panels/bottom.rs index 124c242..f1817a5 100644 --- a/src/app/panels/bottom.rs +++ b/src/app/panels/bottom.rs @@ -122,7 +122,7 @@ impl crate::app::App { key, wants_input, ); - }, + } Tab::About => {} } }); @@ -510,7 +510,7 @@ impl crate::app::App { } }); } - + fn xvb_submenu(&mut self, ui: &mut Ui, size: Vec2) { ui.group(|ui| { let width = size.x / 1.5; @@ -526,10 +526,7 @@ impl crate::app::App { } ui.separator(); if ui - .add_sized( - size, - SelectableLabel::new(self.state.xvb.simple, "Simple"), - ) + .add_sized(size, SelectableLabel::new(self.state.xvb.simple, "Simple")) .clicked() { self.state.xvb.simple = true; @@ -613,7 +610,6 @@ impl crate::app::App { } }); } - } fn status_p2pool(state: ProcessState, ui: &mut Ui, size: Vec2) { diff --git a/src/app/panels/middle/xvb.rs b/src/app/panels/middle/xvb.rs index 11779eb..59747d9 100644 --- a/src/app/panels/middle/xvb.rs +++ b/src/app/panels/middle/xvb.rs @@ -6,21 +6,23 @@ use log::debug; use readable::num::Float; use readable::up::Uptime; -use crate::disk::state::{XvbMode, ManualDonationLevel, ManualDonationMetric}; +use crate::disk::state::{ManualDonationLevel, ManualDonationMetric, XvbMode}; use crate::helper::xmrig::PubXmrigApi; use crate::helper::xvb::priv_stats::RuntimeMode; use crate::helper::xvb::PubXvbApi; use crate::regex::num_lines; use crate::utils::constants::{ - GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD, XVB_FAILURE_FIELD, - XVB_HELP, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES, - XVB_WINNER_FIELD, XVB_HERO_SELECT, XVB_MODE_MANUAL_XVB_HELP, XVB_MODE_MANUAL_P2POOL_HELP, XVB_MODE_MANUAL_DONATION_LEVEL_HELP, - XVB_DONATION_LEVEL_DONOR_HELP, XVB_DONATION_LEVEL_VIP_DONOR_HELP, XVB_DONATION_LEVEL_WHALE_DONOR_HELP, - XVB_DONATION_LEVEL_MEGA_DONOR_HELP, XVB_MANUAL_SLIDER_MANUAL_XVB_HELP, XVB_MANUAL_SLIDER_MANUAL_P2POOL_HELP + GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD, + XVB_DONATION_LEVEL_DONOR_HELP, XVB_DONATION_LEVEL_MEGA_DONOR_HELP, + XVB_DONATION_LEVEL_VIP_DONOR_HELP, XVB_DONATION_LEVEL_WHALE_DONOR_HELP, XVB_FAILURE_FIELD, + XVB_HELP, XVB_HERO_SELECT, XVB_MANUAL_SLIDER_MANUAL_P2POOL_HELP, + XVB_MANUAL_SLIDER_MANUAL_XVB_HELP, XVB_MODE_MANUAL_DONATION_LEVEL_HELP, + XVB_MODE_MANUAL_P2POOL_HELP, XVB_MODE_MANUAL_XVB_HELP, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, + XVB_TOKEN_LEN, XVB_URL_RULES, XVB_WINNER_FIELD, }; use crate::utils::macros::lock; use crate::utils::regex::Regexes; -use crate::{XVB_MINING_ON_FIELD}; +use crate::XVB_MINING_ON_FIELD; use crate::{ constants::{BYTES_XVB, SPACE}, utils::constants::{DARK_GRAY, XVB_URL}, @@ -127,7 +129,6 @@ impl crate::disk::state::Xvb { ui.style_mut().spacing.icon_width = width / 35.0; ui.style_mut().spacing.icon_spacing = space_h; - // --------------------------- XVB Simple ------------------------------------------- if self.simple { @@ -180,8 +181,6 @@ impl crate::disk::state::Xvb { 1000.0 } }; - - // Adjust maximum slider amount based on slider metric if self.manual_donation_metric == ManualDonationMetric::Kilo { hashrate_xmrig /= 1000.0; @@ -216,11 +215,8 @@ impl crate::disk::state::Xvb { self.manual_donation_metric = ManualDonationMetric::Mega; self.manual_slider_amount = self.manual_amount_raw / 1_000_000.0; }; - - }); }); - } if self.mode == XvbMode::ManualDonationLevel { @@ -232,14 +228,13 @@ impl crate::disk::state::Xvb { .on_hover_text(XVB_DONATION_LEVEL_WHALE_DONOR_HELP); ui.radio_value(&mut self.manual_donation_level, ManualDonationLevel::DonorMega, "DonorMega") .on_hover_text(XVB_DONATION_LEVEL_MEGA_DONOR_HELP); - + lock!(api).stats_priv.runtime_manual_donation_level = self.manual_donation_level.clone().into(); } - }); }); }); - + // Update manual_amount_raw based on slider match self.manual_donation_metric { ManualDonationMetric::Hash => { @@ -256,7 +251,7 @@ impl crate::disk::state::Xvb { // Set runtime_mode & runtime_manual_amount lock!(api).stats_priv.runtime_mode = self.mode.clone().into(); lock!(api).stats_priv.runtime_manual_amount = self.manual_amount_raw; - } + } ui.add_space(space_h); // need to warn the user if no address is set in p2pool tab @@ -264,11 +259,9 @@ impl crate::disk::state::Xvb { debug!("XvB Tab | Rendering warning text"); ui.horizontal_wrapped(|ui|{ ui.label(RichText::new("You don't have any payout address set in the P2pool Tab ! XvB process needs one to function properly.") - .color(ORANGE)); - + .color(ORANGE)); }); } - // private stats ui.add_space(space_h); // ui.add_enabled_ui(is_alive, |ui| { diff --git a/src/disk/state.rs b/src/disk/state.rs index 29f411d..6fb1133 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -279,7 +279,7 @@ pub enum ManualDonationMetric { #[default] Hash, Kilo, - Mega + Mega, } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/helper/tests.rs b/src/helper/tests.rs index 5f83b79..e7c1d87 100644 --- a/src/helper/tests.rs +++ b/src/helper/tests.rs @@ -3,7 +3,10 @@ mod test { use crate::helper::{ p2pool::{PrivP2poolLocalApi, PrivP2poolNetworkApi}, - xvb::{algorithm::calcul_donated_time, priv_stats::RuntimeMode, priv_stats::RuntimeDonationLevel, rounds::round_type}, + xvb::{ + algorithm::calcul_donated_time, priv_stats::RuntimeDonationLevel, + priv_stats::RuntimeMode, rounds::round_type, + }, Helper, Process, ProcessName, ProcessState, }; @@ -778,9 +781,9 @@ Uptime = 0h 2m 4s / 1000.0; assert_eq!(round_type(share, &gui_api_xvb), Some(XvbRound::DonorVip)); } - + #[test] - fn test_xvb_advanced_options () { + fn test_xvb_advanced_options() { let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new())); let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new())); let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new())); @@ -790,17 +793,16 @@ Uptime = 0h 2m 4s lock!(gui_api_xmrig).hashrate_raw_15m = 5000.0; lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualXvb; lock!(gui_api_xvb).stats_priv.runtime_manual_amount = 500.0; - + let given_time = calcul_donated_time( lock!(gui_api_xmrig).hashrate_raw_15m, &gui_api_p2pool, &gui_api_xvb, &state_p2pool, ); - + assert_eq!(given_time, 60); - - + lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualP2pool; let given_time = calcul_donated_time( @@ -810,12 +812,10 @@ Uptime = 0h 2m 4s &state_p2pool, ); assert_eq!(given_time, 540); - lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualDonationLevel; lock!(gui_api_xvb).stats_priv.runtime_manual_donation_level = RuntimeDonationLevel::Donor; - - + let given_time = calcul_donated_time( lock!(gui_api_xmrig).hashrate_raw_15m, &gui_api_p2pool, @@ -823,6 +823,5 @@ Uptime = 0h 2m 4s &state_p2pool, ); assert_eq!(given_time, 120); - } } diff --git a/src/helper/xvb/algorithm.rs b/src/helper/xvb/algorithm.rs index d16415e..4c4e386 100644 --- a/src/helper/xvb/algorithm.rs +++ b/src/helper/xvb/algorithm.rs @@ -12,7 +12,9 @@ use crate::{ helper::{ p2pool::PubP2poolApi, xmrig::{PrivXmrigApi, PubXmrigApi}, - xvb::{nodes::XvbNode, output_console, output_console_without_time, priv_stats::RuntimeMode}, + xvb::{ + nodes::XvbNode, output_console, output_console_without_time, priv_stats::RuntimeMode, + }, }, macros::lock, BLOCK_PPLNS_WINDOW_MAIN, BLOCK_PPLNS_WINDOW_MINI, SECOND_PER_BLOCK_P2POOL, XMRIG_CONFIG_URI, @@ -77,28 +79,31 @@ pub(crate) fn calcul_donated_time( info!("RuntimeMode::Auto - calculating spared_time"); // calculate how much time needed to be spared to be in most round type minimum HR + buffer minimum_time_for_highest_accessible_round(default_spared_time, lhr, xvb_chr, shr) - }, + } RuntimeMode::Hero => { info!("RuntimeMode::Hero - calculating spared_time lhr:{lhr} min_hr:{min_hr}"); output_console(gui_api_xvb, "Hero mode is enabled for this decision"); default_spared_time - }, + } RuntimeMode::ManualXvb => { let donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; info!("RuntimeMode::ManualXvb - lhr:{lhr} donate_hr:{donate_hr}"); XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32) - }, + } RuntimeMode::ManualP2pool => { let keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; info!("RuntimeMode::ManualXvb - lhr:{lhr} keep_hr:{keep_hr}"); XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32)) - }, + } RuntimeMode::ManualDonationLevel => { - let donation_level = lock!(gui_api_xvb).stats_priv.runtime_manual_donation_level.clone(); + let donation_level = lock!(gui_api_xvb) + .stats_priv + .runtime_manual_donation_level + .clone(); info!("RuntimeMode::ManualDonationLevel"); - + minimum_time_for_manual_round(donation_level, default_spared_time, lhr, xvb_chr, shr) } }; @@ -203,35 +208,39 @@ fn minimum_time_for_highest_accessible_round(st: u32, lhr: f32, chr: f32, shr: f (((hr_for_xvb - (hr_for_xvb - min)) / lhr) * XVB_TIME_ALGO as f32).ceil() as u32 } -fn minimum_time_for_manual_round(level: RuntimeDonationLevel, st: u32, lhr: f32, chr: f32, shr: f32) -> u32 { +fn minimum_time_for_manual_round( + level: RuntimeDonationLevel, + st: u32, + lhr: f32, + chr: f32, + shr: f32, +) -> u32 { let hr_for_xvb = ((st - 1) as f32 / XVB_TIME_ALGO as f32) * lhr; info!( "hr for xvb is: ({st} / {}) * {lhr} = {hr_for_xvb}H/s", XVB_TIME_ALGO ); let ohr = chr - shr; - + let min = match level { RuntimeDonationLevel::Donor => { info!("RuntimeDonationLevel::Donor"); XVB_ROUND_DONOR_MIN_HR as f32 - ohr - }, + } RuntimeDonationLevel::DonorVIP => { info!("RuntimeDonationLevel::DonorVIP"); XVB_ROUND_DONOR_VIP_MIN_HR as f32 - ohr - }, + } RuntimeDonationLevel::DonorWhale => { info!("RuntimeDonationLevel::DonorWhale"); XVB_ROUND_DONOR_WHALE_MIN_HR as f32 - ohr - }, + } RuntimeDonationLevel::DonorMega => { info!("RuntimeDonationLevel::DonorMega"); XVB_ROUND_DONOR_MEGA_MIN_HR as f32 - ohr } }; - - - + (((hr_for_xvb - (hr_for_xvb - min)) / lhr) * XVB_TIME_ALGO as f32).ceil() as u32 } diff --git a/src/helper/xvb/mod.rs b/src/helper/xvb/mod.rs index 782dd79..7bf47e1 100644 --- a/src/helper/xvb/mod.rs +++ b/src/helper/xvb/mod.rs @@ -402,7 +402,6 @@ impl PubXvbApi { } let runtime_mode = std::mem::take(&mut gui_api.stats_priv.runtime_mode); let runtime_manual_amount = std::mem::take(&mut gui_api.stats_priv.runtime_manual_amount); - *gui_api = Self { output, @@ -700,7 +699,7 @@ fn reset_data_xvb(pub_api: &Arc>, gui_api: &Arc for RuntimeMode { XvbMode::ManualXvb => Self::ManualXvb, XvbMode::ManualP2pool => Self::ManualP2pool, XvbMode::Hero => Self::Hero, - XvbMode::ManualDonationLevel => Self::ManualDonationLevel + XvbMode::ManualDonationLevel => Self::ManualDonationLevel, } } } @@ -149,7 +150,7 @@ impl From for RuntimeDonationLevel { ManualDonationLevel::Donor => RuntimeDonationLevel::Donor, ManualDonationLevel::DonorVIP => RuntimeDonationLevel::DonorVIP, ManualDonationLevel::DonorWhale => RuntimeDonationLevel::DonorWhale, - ManualDonationLevel::DonorMega => RuntimeDonationLevel::DonorMega + ManualDonationLevel::DonorMega => RuntimeDonationLevel::DonorMega, } } } diff --git a/src/utils/constants.rs b/src/utils/constants.rs index 37762ba..f9af578 100644 --- a/src/utils/constants.rs +++ b/src/utils/constants.rs @@ -447,13 +447,15 @@ pub const XVB_MODE_MANUAL_XVB_HELP: &str = "Manually set the amount to donate to pub const XVB_MODE_MANUAL_P2POOL_HELP: &str = "Manually set the amount to keep on P2pool, If value is more than xmrig hashrate it might be changed"; pub const XVB_MODE_MANUAL_DONATION_LEVEL_HELP: &str = "Manually set the XvB donation level"; - // Manual Donation Levels -pub const XVB_DONATION_LEVEL_DONOR_HELP: &str = "To qualify at least 1 kH/s will be actively donated (1hr and 24hr avg.)"; -pub const XVB_DONATION_LEVEL_VIP_DONOR_HELP: &str = "To qualify at least 10 kH/s will be actively donated (1hr and 24hr avg.)"; -pub const XVB_DONATION_LEVEL_WHALE_DONOR_HELP: &str = "To qualify at least 100 kH/s will be actively donated (1hr and 24hr avg.)"; -pub const XVB_DONATION_LEVEL_MEGA_DONOR_HELP: &str = "To qualify at least 1000 kH/s will be actively donated (1hr and 24hr avg.)"; - +pub const XVB_DONATION_LEVEL_DONOR_HELP: &str = + "To qualify at least 1 kH/s will be actively donated (1hr and 24hr avg.)"; +pub const XVB_DONATION_LEVEL_VIP_DONOR_HELP: &str = + "To qualify at least 10 kH/s will be actively donated (1hr and 24hr avg.)"; +pub const XVB_DONATION_LEVEL_WHALE_DONOR_HELP: &str = + "To qualify at least 100 kH/s will be actively donated (1hr and 24hr avg.)"; +pub const XVB_DONATION_LEVEL_MEGA_DONOR_HELP: &str = + "To qualify at least 1000 kH/s will be actively donated (1hr and 24hr avg.)"; // CLI argument messages pub const ARG_HELP: &str = r#"USAGE: ./gupaxx [--flag]