fix: formatting

This commit is contained in:
mostafaei2002 2024-06-11 23:05:21 +03:30
parent f2a3c00145
commit a450f1e684
9 changed files with 73 additions and 73 deletions

View file

@ -527,7 +527,8 @@ impl App {
// Set saved Hero mode to runtime. // Set saved Hero mode to runtime.
debug!("Setting runtime_mode & runtime_manual_amount"); 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_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 // Check if [P2pool.node] exists
info!("App Init | Checking if saved remote node still exists..."); info!("App Init | Checking if saved remote node still exists...");
app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node); app.state.p2pool.node = RemoteNode::check_exists(&app.state.p2pool.node);

View file

@ -122,7 +122,7 @@ impl crate::app::App {
key, key,
wants_input, wants_input,
); );
}, }
Tab::About => {} Tab::About => {}
} }
}); });
@ -526,10 +526,7 @@ impl crate::app::App {
} }
ui.separator(); ui.separator();
if ui if ui
.add_sized( .add_sized(size, SelectableLabel::new(self.state.xvb.simple, "Simple"))
size,
SelectableLabel::new(self.state.xvb.simple, "Simple"),
)
.clicked() .clicked()
{ {
self.state.xvb.simple = true; self.state.xvb.simple = true;
@ -613,7 +610,6 @@ impl crate::app::App {
} }
}); });
} }
} }
fn status_p2pool(state: ProcessState, ui: &mut Ui, size: Vec2) { fn status_p2pool(state: ProcessState, ui: &mut Ui, size: Vec2) {

View file

@ -6,21 +6,23 @@ use log::debug;
use readable::num::Float; use readable::num::Float;
use readable::up::Uptime; 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::xmrig::PubXmrigApi;
use crate::helper::xvb::priv_stats::RuntimeMode; use crate::helper::xvb::priv_stats::RuntimeMode;
use crate::helper::xvb::PubXvbApi; use crate::helper::xvb::PubXvbApi;
use crate::regex::num_lines; use crate::regex::num_lines;
use crate::utils::constants::{ use crate::utils::constants::{
GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD, XVB_FAILURE_FIELD, GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD,
XVB_HELP, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES, XVB_DONATION_LEVEL_DONOR_HELP, XVB_DONATION_LEVEL_MEGA_DONOR_HELP,
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_VIP_DONOR_HELP, XVB_DONATION_LEVEL_WHALE_DONOR_HELP, XVB_FAILURE_FIELD,
XVB_DONATION_LEVEL_DONOR_HELP, XVB_DONATION_LEVEL_VIP_DONOR_HELP, XVB_DONATION_LEVEL_WHALE_DONOR_HELP, XVB_HELP, XVB_HERO_SELECT, XVB_MANUAL_SLIDER_MANUAL_P2POOL_HELP,
XVB_DONATION_LEVEL_MEGA_DONOR_HELP, XVB_MANUAL_SLIDER_MANUAL_XVB_HELP, 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::macros::lock;
use crate::utils::regex::Regexes; use crate::utils::regex::Regexes;
use crate::{XVB_MINING_ON_FIELD}; use crate::XVB_MINING_ON_FIELD;
use crate::{ use crate::{
constants::{BYTES_XVB, SPACE}, constants::{BYTES_XVB, SPACE},
utils::constants::{DARK_GRAY, XVB_URL}, 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_width = width / 35.0;
ui.style_mut().spacing.icon_spacing = space_h; ui.style_mut().spacing.icon_spacing = space_h;
// --------------------------- XVB Simple ------------------------------------------- // --------------------------- XVB Simple -------------------------------------------
if self.simple { if self.simple {
@ -180,8 +181,6 @@ impl crate::disk::state::Xvb {
1000.0 1000.0
} }
}; };
// Adjust maximum slider amount based on slider metric // Adjust maximum slider amount based on slider metric
if self.manual_donation_metric == ManualDonationMetric::Kilo { if self.manual_donation_metric == ManualDonationMetric::Kilo {
hashrate_xmrig /= 1000.0; hashrate_xmrig /= 1000.0;
@ -216,11 +215,8 @@ impl crate::disk::state::Xvb {
self.manual_donation_metric = ManualDonationMetric::Mega; self.manual_donation_metric = ManualDonationMetric::Mega;
self.manual_slider_amount = self.manual_amount_raw / 1_000_000.0; self.manual_slider_amount = self.manual_amount_raw / 1_000_000.0;
}; };
}); });
}); });
} }
if self.mode == XvbMode::ManualDonationLevel { if self.mode == XvbMode::ManualDonationLevel {
@ -235,7 +231,6 @@ impl crate::disk::state::Xvb {
lock!(api).stats_priv.runtime_manual_donation_level = self.manual_donation_level.clone().into(); lock!(api).stats_priv.runtime_manual_donation_level = self.manual_donation_level.clone().into();
} }
}); });
}); });
}); });
@ -264,11 +259,9 @@ impl crate::disk::state::Xvb {
debug!("XvB Tab | Rendering warning text"); debug!("XvB Tab | Rendering warning text");
ui.horizontal_wrapped(|ui|{ 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.") 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 // private stats
ui.add_space(space_h); ui.add_space(space_h);
// ui.add_enabled_ui(is_alive, |ui| { // ui.add_enabled_ui(is_alive, |ui| {

View file

@ -279,7 +279,7 @@ pub enum ManualDonationMetric {
#[default] #[default]
Hash, Hash,
Kilo, Kilo,
Mega Mega,
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]

View file

@ -3,7 +3,10 @@ mod test {
use crate::helper::{ use crate::helper::{
p2pool::{PrivP2poolLocalApi, PrivP2poolNetworkApi}, 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, Helper, Process, ProcessName, ProcessState,
}; };
@ -780,7 +783,7 @@ Uptime = 0h 2m 4s
} }
#[test] #[test]
fn test_xvb_advanced_options () { fn test_xvb_advanced_options() {
let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new())); let gui_api_xvb = Arc::new(Mutex::new(PubXvbApi::new()));
let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new())); let gui_api_p2pool = Arc::new(Mutex::new(PubP2poolApi::new()));
let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new())); let gui_api_xmrig = Arc::new(Mutex::new(PubXmrigApi::new()));
@ -800,7 +803,6 @@ Uptime = 0h 2m 4s
assert_eq!(given_time, 60); assert_eq!(given_time, 60);
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualP2pool; lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualP2pool;
let given_time = calcul_donated_time( let given_time = calcul_donated_time(
@ -811,11 +813,9 @@ Uptime = 0h 2m 4s
); );
assert_eq!(given_time, 540); assert_eq!(given_time, 540);
lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualDonationLevel; lock!(gui_api_xvb).stats_priv.runtime_mode = RuntimeMode::ManualDonationLevel;
lock!(gui_api_xvb).stats_priv.runtime_manual_donation_level = RuntimeDonationLevel::Donor; lock!(gui_api_xvb).stats_priv.runtime_manual_donation_level = RuntimeDonationLevel::Donor;
let given_time = calcul_donated_time( let given_time = calcul_donated_time(
lock!(gui_api_xmrig).hashrate_raw_15m, lock!(gui_api_xmrig).hashrate_raw_15m,
&gui_api_p2pool, &gui_api_p2pool,
@ -823,6 +823,5 @@ Uptime = 0h 2m 4s
&state_p2pool, &state_p2pool,
); );
assert_eq!(given_time, 120); assert_eq!(given_time, 120);
} }
} }

View file

@ -12,7 +12,9 @@ use crate::{
helper::{ helper::{
p2pool::PubP2poolApi, p2pool::PubP2poolApi,
xmrig::{PrivXmrigApi, PubXmrigApi}, 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, macros::lock,
BLOCK_PPLNS_WINDOW_MAIN, BLOCK_PPLNS_WINDOW_MINI, SECOND_PER_BLOCK_P2POOL, XMRIG_CONFIG_URI, BLOCK_PPLNS_WINDOW_MAIN, BLOCK_PPLNS_WINDOW_MINI, SECOND_PER_BLOCK_P2POOL, XMRIG_CONFIG_URI,
@ -77,26 +79,29 @@ pub(crate) fn calcul_donated_time(
info!("RuntimeMode::Auto - calculating spared_time"); info!("RuntimeMode::Auto - calculating spared_time");
// calculate how much time needed to be spared to be in most round type minimum HR + buffer // 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) minimum_time_for_highest_accessible_round(default_spared_time, lhr, xvb_chr, shr)
}, }
RuntimeMode::Hero => { RuntimeMode::Hero => {
info!("RuntimeMode::Hero - calculating spared_time lhr:{lhr} min_hr:{min_hr}"); info!("RuntimeMode::Hero - calculating spared_time lhr:{lhr} min_hr:{min_hr}");
output_console(gui_api_xvb, "Hero mode is enabled for this decision"); output_console(gui_api_xvb, "Hero mode is enabled for this decision");
default_spared_time default_spared_time
}, }
RuntimeMode::ManualXvb => { RuntimeMode::ManualXvb => {
let donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; let donate_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount;
info!("RuntimeMode::ManualXvb - lhr:{lhr} donate_hr:{donate_hr}"); info!("RuntimeMode::ManualXvb - lhr:{lhr} donate_hr:{donate_hr}");
XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32) XVB_TIME_ALGO * (donate_hr as u32) / (lhr as u32)
}, }
RuntimeMode::ManualP2pool => { RuntimeMode::ManualP2pool => {
let keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount; let keep_hr = lock!(gui_api_xvb).stats_priv.runtime_manual_amount;
info!("RuntimeMode::ManualXvb - lhr:{lhr} keep_hr:{keep_hr}"); info!("RuntimeMode::ManualXvb - lhr:{lhr} keep_hr:{keep_hr}");
XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32)) XVB_TIME_ALGO - (XVB_TIME_ALGO * (keep_hr as u32) / (lhr as u32))
}, }
RuntimeMode::ManualDonationLevel => { 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"); info!("RuntimeMode::ManualDonationLevel");
minimum_time_for_manual_round(donation_level, default_spared_time, lhr, xvb_chr, shr) minimum_time_for_manual_round(donation_level, default_spared_time, lhr, xvb_chr, shr)
@ -203,7 +208,13 @@ 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 (((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; let hr_for_xvb = ((st - 1) as f32 / XVB_TIME_ALGO as f32) * lhr;
info!( info!(
"hr for xvb is: ({st} / {}) * {lhr} = {hr_for_xvb}H/s", "hr for xvb is: ({st} / {}) * {lhr} = {hr_for_xvb}H/s",
@ -215,23 +226,21 @@ fn minimum_time_for_manual_round(level: RuntimeDonationLevel, st: u32, lhr: f32,
RuntimeDonationLevel::Donor => { RuntimeDonationLevel::Donor => {
info!("RuntimeDonationLevel::Donor"); info!("RuntimeDonationLevel::Donor");
XVB_ROUND_DONOR_MIN_HR as f32 - ohr XVB_ROUND_DONOR_MIN_HR as f32 - ohr
}, }
RuntimeDonationLevel::DonorVIP => { RuntimeDonationLevel::DonorVIP => {
info!("RuntimeDonationLevel::DonorVIP"); info!("RuntimeDonationLevel::DonorVIP");
XVB_ROUND_DONOR_VIP_MIN_HR as f32 - ohr XVB_ROUND_DONOR_VIP_MIN_HR as f32 - ohr
}, }
RuntimeDonationLevel::DonorWhale => { RuntimeDonationLevel::DonorWhale => {
info!("RuntimeDonationLevel::DonorWhale"); info!("RuntimeDonationLevel::DonorWhale");
XVB_ROUND_DONOR_WHALE_MIN_HR as f32 - ohr XVB_ROUND_DONOR_WHALE_MIN_HR as f32 - ohr
}, }
RuntimeDonationLevel::DonorMega => { RuntimeDonationLevel::DonorMega => {
info!("RuntimeDonationLevel::DonorMega"); info!("RuntimeDonationLevel::DonorMega");
XVB_ROUND_DONOR_MEGA_MIN_HR as f32 - ohr 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 (((hr_for_xvb - (hr_for_xvb - min)) / lhr) * XVB_TIME_ALGO as f32).ceil() as u32
} }

View file

@ -403,7 +403,6 @@ impl PubXvbApi {
let runtime_mode = std::mem::take(&mut gui_api.stats_priv.runtime_mode); 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); let runtime_manual_amount = std::mem::take(&mut gui_api.stats_priv.runtime_manual_amount);
*gui_api = Self { *gui_api = Self {
output, output,
stats_priv: XvbPrivStats { stats_priv: XvbPrivStats {

View file

@ -9,14 +9,16 @@ use reqwest::{Client, StatusCode};
use serde::Deserialize; use serde::Deserialize;
use tokio::time::sleep; use tokio::time::sleep;
use crate::{
disk::state::ManualDonationLevel, helper::{xvb::output_console, Process, ProcessState}, macros::lock, XVB_URL
};
use crate::disk::state::XvbMode; use crate::disk::state::XvbMode;
use crate::{
disk::state::ManualDonationLevel,
helper::{xvb::output_console, Process, ProcessState},
macros::lock,
XVB_URL,
};
use super::{nodes::XvbNode, rounds::XvbRound, PubXvbApi}; use super::{nodes::XvbNode, rounds::XvbRound, PubXvbApi};
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)] #[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)]
pub enum RuntimeMode { pub enum RuntimeMode {
#[default] #[default]
@ -24,17 +26,16 @@ pub enum RuntimeMode {
ManualXvb, ManualXvb,
ManualP2pool, ManualP2pool,
Hero, Hero,
ManualDonationLevel ManualDonationLevel,
} }
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)] #[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)]
pub enum RuntimeDonationLevel { pub enum RuntimeDonationLevel {
#[default] #[default]
Donor, Donor,
DonorVIP, DonorVIP,
DonorWhale, DonorWhale,
DonorMega DonorMega,
} }
#[derive(Debug, Clone, Default, Deserialize)] #[derive(Debug, Clone, Default, Deserialize)]
@ -60,7 +61,7 @@ pub struct XvbPrivStats {
#[serde(skip)] #[serde(skip)]
pub runtime_manual_amount: f64, pub runtime_manual_amount: f64,
#[serde(skip)] #[serde(skip)]
pub runtime_manual_donation_level: RuntimeDonationLevel pub runtime_manual_donation_level: RuntimeDonationLevel,
} }
impl XvbPrivStats { impl XvbPrivStats {
@ -138,7 +139,7 @@ impl From<XvbMode> for RuntimeMode {
XvbMode::ManualXvb => Self::ManualXvb, XvbMode::ManualXvb => Self::ManualXvb,
XvbMode::ManualP2pool => Self::ManualP2pool, XvbMode::ManualP2pool => Self::ManualP2pool,
XvbMode::Hero => Self::Hero, XvbMode::Hero => Self::Hero,
XvbMode::ManualDonationLevel => Self::ManualDonationLevel XvbMode::ManualDonationLevel => Self::ManualDonationLevel,
} }
} }
} }
@ -149,7 +150,7 @@ impl From<ManualDonationLevel> for RuntimeDonationLevel {
ManualDonationLevel::Donor => RuntimeDonationLevel::Donor, ManualDonationLevel::Donor => RuntimeDonationLevel::Donor,
ManualDonationLevel::DonorVIP => RuntimeDonationLevel::DonorVIP, ManualDonationLevel::DonorVIP => RuntimeDonationLevel::DonorVIP,
ManualDonationLevel::DonorWhale => RuntimeDonationLevel::DonorWhale, ManualDonationLevel::DonorWhale => RuntimeDonationLevel::DonorWhale,
ManualDonationLevel::DonorMega => RuntimeDonationLevel::DonorMega ManualDonationLevel::DonorMega => RuntimeDonationLevel::DonorMega,
} }
} }
} }

View file

@ -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_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"; pub const XVB_MODE_MANUAL_DONATION_LEVEL_HELP: &str = "Manually set the XvB donation level";
// Manual Donation Levels // 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_DONOR_HELP: &str =
pub const XVB_DONATION_LEVEL_VIP_DONOR_HELP: &str = "To qualify at least 10 kH/s will be actively donated (1hr and 24hr avg.)"; "To qualify at least 1 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_VIP_DONOR_HELP: &str =
pub const XVB_DONATION_LEVEL_MEGA_DONOR_HELP: &str = "To qualify at least 1000 kH/s will be actively donated (1hr and 24hr avg.)"; "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 // CLI argument messages
pub const ARG_HELP: &str = r#"USAGE: ./gupaxx [--flag] pub const ARG_HELP: &str = r#"USAGE: ./gupaxx [--flag]