Skip to content

Commit

Permalink
feat: show XvB stats to Status Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrix126 committed Mar 4, 2024
1 parent f164184 commit 7f8b1b2
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 22 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ walkdir = "2.4.0"
zeroize = "1.7.0"
strsim = "0.11.0"
strip-ansi-escapes = "0.2.0"

derive_more = {version="0.99.17", default-features=false, features=["display"]}
serde-this-or-that = "0.4.2"
# Unix dependencies
[target.'cfg(unix)'.dependencies]
tar = "0.4.40"
Expand Down
5 changes: 5 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::helper::p2pool::ImgP2pool;
use crate::helper::p2pool::PubP2poolApi;
use crate::helper::xmrig::ImgXmrig;
use crate::helper::xmrig::PubXmrigApi;
use crate::helper::xvb::PubXvbApi;
use crate::helper::Helper;
use crate::helper::Process;
use crate::helper::ProcessName;
Expand Down Expand Up @@ -103,6 +104,7 @@ pub struct App {
pub xmrig: Arc<Mutex<Process>>, // [XMRig] process state
pub p2pool_api: Arc<Mutex<PubP2poolApi>>, // Public ready-to-print P2Pool API made by the "helper" thread
pub xmrig_api: Arc<Mutex<PubXmrigApi>>, // Public ready-to-print XMRig API made by the "helper" thread
pub xvb_api: Arc<Mutex<PubXvbApi>>, // Public XvB API
pub p2pool_img: Arc<Mutex<ImgP2pool>>, // A one-time snapshot of what data P2Pool started with
pub xmrig_img: Arc<Mutex<ImgXmrig>>, // A one-time snapshot of what data XMRig started with
// STDIN Buffer
Expand Down Expand Up @@ -181,6 +183,7 @@ impl App {
));
let p2pool_api = arc_mut!(PubP2poolApi::new());
let xmrig_api = arc_mut!(PubXmrigApi::new());
let xvb_api = arc_mut!(PubXvbApi::new());
let p2pool_img = arc_mut!(ImgP2pool::new());
let xmrig_img = arc_mut!(ImgXmrig::new());

Expand Down Expand Up @@ -243,13 +246,15 @@ impl App {
xmrig.clone(),
p2pool_api.clone(),
xmrig_api.clone(),
xvb_api.clone(),
p2pool_img.clone(),
xmrig_img.clone(),
arc_mut!(GupaxP2poolApi::new())
)),
p2pool,
xmrig,
p2pool_api,
xvb_api,
xmrig_api,
p2pool_img,
xmrig_img,
Expand Down
2 changes: 1 addition & 1 deletion src/app/panels/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ path_xmr: {:#?}\n
}
Tab::Status => {
debug!("App | Entering [Status] Tab");
crate::disk::state::Status::show(&mut self.state.status, &self.pub_sys, &self.p2pool_api, &self.xmrig_api, &self.p2pool_img, &self.xmrig_img, p2pool_is_alive, xmrig_is_alive, self.max_threads, &self.gupax_p2pool_api, &self.benchmarks, self.width, self.height, ctx, ui);
crate::disk::state::Status::show(&mut self.state.status, &self.pub_sys, &self.p2pool_api, &self.xmrig_api, &self.xvb_api,&self.p2pool_img, &self.xmrig_img, p2pool_is_alive, xmrig_is_alive, self.max_threads, &self.gupax_p2pool_api, &self.benchmarks, self.width, self.height, ctx, ui);
}
Tab::Gupax => {
debug!("App | Entering [Gupax] Tab");
Expand Down
5 changes: 4 additions & 1 deletion src/app/panels/middle/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
helper::{
p2pool::{ImgP2pool, PubP2poolApi},
xmrig::{ImgXmrig, PubXmrigApi},
xvb::PubXvbApi,
Sys,
},
};
Expand All @@ -38,6 +39,7 @@ impl Status {
sys: &Arc<Mutex<Sys>>,
p2pool_api: &Arc<Mutex<PubP2poolApi>>,
xmrig_api: &Arc<Mutex<PubXmrigApi>>,
xvb_api: &Arc<Mutex<PubXvbApi>>,
p2pool_img: &Arc<Mutex<ImgP2pool>>,
xmrig_img: &Arc<Mutex<ImgXmrig>>,
p2pool_alive: bool,
Expand All @@ -59,10 +61,11 @@ impl Status {
ui,
p2pool_alive,
p2pool_api,
p2pool_img,
xmrig_alive,
xmrig_api,
p2pool_img,
xmrig_img,
xvb_api,
max_threads,
);
//---------------------------------------------------------------------------------------------------- [P2Pool]
Expand Down
146 changes: 143 additions & 3 deletions src/app/panels/middle/status/processes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use egui::Ui;
use egui::{ScrollArea, Ui};
use std::sync::{Arc, Mutex};

use crate::disk::state::Status;
use crate::helper::p2pool::{ImgP2pool, PubP2poolApi};
use crate::helper::xmrig::{ImgXmrig, PubXmrigApi};
use crate::helper::xvb::{PubXvbApi, XvbRound};
use crate::helper::Sys;
use crate::utils::macros::lock;
use egui::TextStyle;
Expand All @@ -21,13 +22,14 @@ impl Status {
ui: &mut egui::Ui,
p2pool_alive: bool,
p2pool_api: &Arc<Mutex<PubP2poolApi>>,
p2pool_img: &Arc<Mutex<ImgP2pool>>,
xmrig_alive: bool,
xmrig_api: &Arc<Mutex<PubXmrigApi>>,
p2pool_img: &Arc<Mutex<ImgP2pool>>,
xmrig_img: &Arc<Mutex<ImgXmrig>>,
xvb_api: &Arc<Mutex<PubXvbApi>>,
max_threads: usize,
) {
let width = (width / 3.0) - (SPACE * 1.666);
let width = (width / 4.0) - (SPACE * 1.7500);
let min_height = height - SPACE;
let height = height / 25.0;
ui.horizontal(|ui| {
Expand All @@ -54,6 +56,8 @@ impl Status {
xmrig_img,
max_threads,
);
// [XvB]
xvb(ui, min_height, width, height, xvb_api);
});
}
}
Expand Down Expand Up @@ -346,3 +350,139 @@ fn xmrig(
})
});
}

fn xvb(ui: &mut Ui, min_height: f32, width: f32, height: f32, xvb_api: &Arc<Mutex<PubXvbApi>>) {
//
let api = lock!(xvb_api);
// if this field is empty, it means nothing was received from the API.
let enabled = !api.reward_yearly.is_empty();
ScrollArea::vertical().show(ui, |ui| {
ui.group(|ui| {
ui.vertical(|ui| {
debug!("Status Tab | Rendering [XvB]");
ui.set_enabled(enabled); // for now there is no API ping or /health, so we verify if the field reward_yearly is empty or not.
ui.set_min_height(min_height);
ui.add_sized(
[width, height],
Label::new(
RichText::new("[XvB]")
.color(LIGHT_GRAY)
.text_style(TextStyle::Name("MonospaceLarge".into())),
),
)
.on_hover_text("XvB API stats")
.on_disabled_hover_text("No data received from XvB API");
// [Round Type]
ui.add_sized(
[width, height],
Label::new(RichText::new("Round Type").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_ROUND_TYPE);
ui.add_sized([width, height], Label::new(api.round_type.to_string()));
// [Time Remaining]
ui.add_sized(
[width, height],
Label::new(
RichText::new("Raffle Round Time Remaining")
.underline()
.color(BONE),
),
)
.on_hover_text(STATUS_XVB_TIME_REMAIN);
ui.add_sized(
[width, height],
Label::new(format!("{} minutes left", api.time_remain)),
);
// Donated Hashrate
ui.add_sized(
[width, height],
Label::new(RichText::new("Donated Hashrate").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_DONATED_HR);
ui.add_sized(
[width, height],
Label::new(format!(
"Bonus HR\n{}kH/s\n+\n{}kH/s\ndonated by\n{} donors\n with\n{} miners",
api.bonus_hr, api.donate_hr, api.donate_miners, api.donate_workers
)),
);
// Players
ui.add_sized(
[width, height],
Label::new(RichText::new("Players").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_PLAYERS);
ui.add_sized(
[width, height],
Label::new(format!(
"[Registered: {}]\n[Playing: {}]",
api.players, api.players_round
)),
);
// Winner
ui.add_sized(
[width, height],
Label::new(RichText::new("Winner").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_WINNER);
ui.add_sized([width, height], Label::new(&api.winner));
// Share effort
ui.add_sized(
[width, height],
Label::new(RichText::new("Share Effort").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_SHARE);
ui.add_sized([width, height], Label::new(format!("{}", api.share_effort)));
// Block reward
ui.add_sized(
[width, height],
Label::new(RichText::new("Block Reward").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_BLOCK_REWARD);
ui.add_sized([width, height], Label::new(format!("{}", api.block_reward)));
//block height
ui.add_sized(
[width, height],
Label::new(RichText::new("Block Height").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_BLOCK_HEIGHT);
ui.add_sized([width, height], Label::new(format!("{}", api.block_height)));
// block hash
ui.add_sized(
[width, height],
Label::new(RichText::new("Block Hash").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_BLOCK_HASH);
ui.add_sized([width, height], Label::new(format!("{}", api.block_hash)));
// reward yearly
ui.add_sized(
[width, height],
Label::new(RichText::new("Reward Yearly").underline().color(BONE)),
)
.on_hover_text(STATUS_XVB_YEARLY);
if api.reward_yearly.is_empty() {
ui.add_sized([width, height], Label::new("No information".to_string()));
} else {
ui.add_sized(
[width, height],
Label::new(format!(
"{}: {} XMR\n{}: {} XMR\n{}: {} XMR\n{}: {} XMR\n{}: {} XMR",
XvbRound::Vip,
api.reward_yearly[0],
XvbRound::Donor,
api.reward_yearly[1],
XvbRound::DonorVip,
api.reward_yearly[2],
XvbRound::DonorWhale,
api.reward_yearly[3],
XvbRound::DonorMega,
api.reward_yearly[4]
)),
);
}
drop(api);
});
// by round
});
});
}
Loading

0 comments on commit 7f8b1b2

Please sign in to comment.