Skip to content

Commit

Permalink
feat: console for log, input token field, better logic for running Xv…
Browse files Browse the repository at this point in the history
…B process
  • Loading branch information
Cyrix126 committed Mar 12, 2024
1 parent 71c923f commit dac7dee
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 160 deletions.
5 changes: 3 additions & 2 deletions TODO_XMRvsBeast.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
- [x] logo
- [x] link to website
- [ ] message overing explaining registration and needs to read the rules.
- [ ] token input
- [x] token input
- [ ] hero checkbox
- [ ] log section
- [ ] status of h/s received by the raffle, authentication by token.
- [ ] status of 1h and 24h average h/s sent to raffle from this instance
- [ ] number of failures
- [ ] round type in
- [ ] win or loose
- [x] state of XvB process
- [ ] new process for XvB
- [x] status process XvB
- [x] public information from [API](https://xmrvsbeast.com/p2pool/stats)
- [x] stop, start, restart buttons
- [x] button to autostart
- [ ] distribute hashrate conforming to the algorithm.
- [ ] output log to console in XvB tab
- [x] output log to console in XvB tab
- [ ] edit metadata of project
- [ ] cargo package metadata
- [ ] pgp signatures
9 changes: 8 additions & 1 deletion src/app/eframe_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl eframe::App for App {
xmrig_is_alive,
xvb_is_alive,
);
self.middle_panel(ctx, frame, key, p2pool_is_alive, xmrig_is_alive);
self.middle_panel(
ctx,
frame,
key,
p2pool_is_alive,
xmrig_is_alive,
xvb_is_alive,
);
}
}
127 changes: 79 additions & 48 deletions src/app/panels/bottom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl crate::app::App {
ui.add_sized(size, Button::new("⏹"))
.on_disabled_hover_text("Stop P2Pool");
});
// Check if address is okay before allowing to start.
// Check if address and path is okay before allowing to start.
let mut text = String::new();
let mut ui_enabled = true;
if !Regexes::addr_ok(&self.state.p2pool.address) {
Expand Down Expand Up @@ -556,8 +556,10 @@ impl crate::app::App {
ui.add_sized(size, Button::new("⏹"))
.on_disabled_hover_text("Stop Xvb");
});
let ui_enabled =
!self.state.p2pool.address.is_empty() && !self.state.xvb.token.is_empty();
// verify that adddress and token syntaxes are correct

Check warning on line 559 in src/app/panels/bottom.rs

View workflow job for this annotation

GitHub Actions / typo

"adddress" should be "address".
let ui_enabled = Regexes::addr_ok(&self.state.p2pool.address)
&& self.state.xvb.token.len() == 9
&& self.state.xvb.token.parse::<u32>().is_ok();
ui.set_enabled(ui_enabled);
let color = if ui_enabled { GREEN } else { RED };
if (ui_enabled && key.is_up() && !wants_input)
Expand All @@ -575,57 +577,86 @@ impl crate::app::App {
}

fn status_p2pool(state: ProcessState, ui: &mut Ui, size: Vec2) {
match state {
Alive => ui
.add_sized(size, Label::new(RichText::new("P2Pool ⏺").color(GREEN)))
.on_hover_text(P2POOL_ALIVE),
Dead => ui
.add_sized(size, Label::new(RichText::new("P2Pool ⏺").color(GRAY)))
.on_hover_text(P2POOL_DEAD),
Failed => ui
.add_sized(size, Label::new(RichText::new("P2Pool ⏺").color(RED)))
.on_hover_text(P2POOL_FAILED),
Syncing => ui
.add_sized(size, Label::new(RichText::new("P2Pool ⏺").color(ORANGE)))
.on_hover_text(P2POOL_SYNCING),
Middle | Waiting | NotMining => ui
.add_sized(size, Label::new(RichText::new("P2Pool ⏺").color(YELLOW)))
.on_hover_text(P2POOL_MIDDLE),
let color;
let hover_text = match state {
Alive => {
color = GREEN;
P2POOL_ALIVE
}
Dead => {
color = GRAY;
P2POOL_DEAD
}
Failed => {
color = RED;
P2POOL_FAILED
}
Syncing => {
color = ORANGE;
P2POOL_SYNCING
}
Middle | Waiting | NotMining => {
color = YELLOW;
P2POOL_MIDDLE
}
};
status(ui, color, hover_text, size, "P2pool ⏺");
}

fn status_xmrig(state: ProcessState, ui: &mut Ui, size: Vec2) {
match state {
Alive => ui
.add_sized(size, Label::new(RichText::new("XMRig ⏺").color(GREEN)))
.on_hover_text(XMRIG_ALIVE),
Dead => ui
.add_sized(size, Label::new(RichText::new("XMRig ⏺").color(GRAY)))
.on_hover_text(XMRIG_DEAD),
Failed => ui
.add_sized(size, Label::new(RichText::new("XMRig ⏺").color(RED)))
.on_hover_text(XMRIG_FAILED),
NotMining => ui
.add_sized(size, Label::new(RichText::new("XMRig ⏺").color(ORANGE)))
.on_hover_text(XMRIG_NOT_MINING),
Middle | Waiting | Syncing => ui
.add_sized(size, Label::new(RichText::new("XMRig ⏺").color(YELLOW)))
.on_hover_text(XMRIG_MIDDLE),
let color;
let hover_text = match state {
Alive => {
color = GREEN;
XMRIG_ALIVE
}
Dead => {
color = GRAY;
XMRIG_DEAD
}
Failed => {
color = RED;
XMRIG_FAILED
}
NotMining => {
color = ORANGE;
XMRIG_NOT_MINING
}
Middle | Waiting | Syncing => {
color = YELLOW;
XMRIG_MIDDLE
}
};
status(ui, color, hover_text, size, "XMRig ⏺");
}
fn status_xvb(state: ProcessState, ui: &mut Ui, size: Vec2) {
match state {
Alive => ui
.add_sized(size, Label::new(RichText::new("XvB ⏺").color(GREEN)))
.on_hover_text(XVB_ALIVE),
Dead => ui
.add_sized(size, Label::new(RichText::new("XvB ⏺").color(GRAY)))
.on_hover_text(XVB_DEAD),
Failed => ui
.add_sized(size, Label::new(RichText::new("XvB ⏺").color(RED)))
.on_hover_text(XVB_FAILED),
Middle | Waiting | NotMining | Syncing => ui
.add_sized(size, Label::new(RichText::new("XvB ⏺").color(YELLOW)))
.on_hover_text(XVB_MIDDLE),
let color;
let hover_text = match state {
Alive => {
color = GREEN;
XVB_ALIVE
}
Dead => {
color = GRAY;
XVB_DEAD
}
Failed => {
color = RED;
XVB_FAILED
}
NotMining => {
color = ORANGE;
XVB_PUBLIC_ONLY
}
Middle | Waiting | Syncing => {
color = YELLOW;
XVB_MIDDLE
}
};
status(ui, color, hover_text, size, "XvB ⏺");
}

fn status(ui: &mut Ui, color: Color32, hover_text: &str, size: Vec2, text: &str) {
ui.add_sized(size, Label::new(RichText::new(text).color(color)))
.on_hover_text(hover_text);
}
5 changes: 3 additions & 2 deletions src/app/panels/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl crate::app::App {
key: KeyPressed,
p2pool_is_alive: bool,
xmrig_is_alive: bool,
xvb_is_alive: bool,
) {
// Middle panel, contents of the [Tab]
debug!("App | Rendering CENTRAL_PANEL (tab contents)");
Expand Down Expand Up @@ -144,7 +145,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.xvb_api,&self.p2pool_img, &self.xmrig_img, p2pool_is_alive, xmrig_is_alive, self.max_threads, &self.gupax_p2pool_api, &self.benchmarks, self.size, 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, xvb_is_alive, self.max_threads, &self.gupax_p2pool_api, &self.benchmarks, self.size, ctx, ui);
}
Tab::Gupax => {
debug!("App | Entering [Gupax] Tab");
Expand All @@ -160,7 +161,7 @@ path_xmr: {:#?}\n
}
Tab::Xvb => {
debug!("App | Entering [XvB] Tab");
crate::disk::state::Xvb::show(self.size, ctx, ui, &self.xvb_api);
crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, ctx, ui, &self.xvb_api);
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/app/panels/middle/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Status {
xmrig_img: &Arc<Mutex<ImgXmrig>>,
p2pool_alive: bool,
xmrig_alive: bool,
xvb_alive: bool,
max_threads: usize,
gupax_p2pool_api: &Arc<Mutex<GupaxP2poolApi>>,
benchmarks: &[Benchmark],
Expand All @@ -65,6 +66,7 @@ impl Status {
xmrig_alive,
xmrig_api,
xmrig_img,
xvb_alive,
xvb_api,
max_threads,
);
Expand Down
15 changes: 11 additions & 4 deletions src/app/panels/middle/status/processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Status {
xmrig_alive: bool,
xmrig_api: &Arc<Mutex<PubXmrigApi>>,
xmrig_img: &Arc<Mutex<ImgXmrig>>,
xvb_alive: bool,
xvb_api: &Arc<Mutex<PubXvbApi>>,
max_threads: usize,
) {
Expand Down Expand Up @@ -56,7 +57,7 @@ impl Status {
max_threads,
);
// [XvB]
xvb(ui, min_height, width, height, xvb_api);
xvb(ui, min_height, width, height, xvb_alive, xvb_api);
});
}
}
Expand Down Expand Up @@ -351,11 +352,17 @@ fn xmrig(
});
}

fn xvb(ui: &mut Ui, min_height: f32, width: f32, height: f32, xvb_api: &Arc<Mutex<PubXvbApi>>) {
fn xvb(
ui: &mut Ui,
min_height: f32,
width: f32,
height: f32,
xvb_alive: bool,
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();
let enabled = xvb_alive;
ScrollArea::vertical().show(ui, |ui| {
ui.group(|ui| {
ui.vertical(|ui| {
Expand Down
45 changes: 40 additions & 5 deletions src/app/panels/middle/xvb.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::sync::{Arc, Mutex};

use egui::TextStyle::Name;
use egui::{Hyperlink, Image, TextEdit, Vec2};
use egui::{Hyperlink, Image, Label, RichText, TextEdit, Vec2};
use log::debug;

use crate::helper::xvb::PubXvbApi;
use crate::utils::constants::{GREEN, LIGHT_GRAY, RED, XVB_HELP, XVB_TOKEN_LEN};
use crate::utils::macros::lock;
use crate::{
constants::{BYTES_XVB, SPACE},
Expand All @@ -13,11 +14,16 @@ use crate::{

impl crate::disk::state::Xvb {
#[inline(always)] // called once
pub fn show(size: Vec2, _ctx: &egui::Context, ui: &mut egui::Ui, api: &Arc<Mutex<PubXvbApi>>) {
pub fn show(
&mut self,
size: Vec2,
_ctx: &egui::Context,
ui: &mut egui::Ui,
api: &Arc<Mutex<PubXvbApi>>,
) {
let website_height = size.y / 10.0;
// let width = size.x - SPACE;
// let height = size.y - SPACE;
let height = size.y;
let width = size.x;
let text_edit = size.y / 25.0;
// logo and website link
Expand Down Expand Up @@ -50,8 +56,37 @@ impl crate::disk::state::Xvb {
);
});
});
// address check
// input token
});
// input token
let len_token = format!("{}", self.token.len());
let text_check;
let color;
if self.token.is_empty() {
text_check = format!("[{}/{}] ➖", len_token, XVB_TOKEN_LEN);
color = LIGHT_GRAY;
} else if self.token.parse::<u32>().is_ok() && self.token.len() < XVB_TOKEN_LEN {
text_check = format!("[{}/{}] ", len_token, XVB_TOKEN_LEN);
color = GREEN;
} else if self.token.parse::<u32>().is_ok() && self.token.len() == XVB_TOKEN_LEN {
text_check = "✔".to_string();
color = GREEN;
} else {
text_check = format!("[{}/{}] ❌", len_token, XVB_TOKEN_LEN);
color = RED;
}
ui.group(|ui| {
let width = width - SPACE;
ui.spacing_mut().text_edit_width = (width) - (SPACE * 3.0);
ui.label("Your Token:");
ui.horizontal(|ui| {
ui.add_sized(
[width / 8.0, text_edit],
TextEdit::singleline(&mut self.token),
)
.on_hover_text_at_pointer(XVB_HELP);
ui.add(Label::new(RichText::new(text_check).color(color)))
});
});
// need to warn the user if no address is set in p2pool tab
}
}
14 changes: 8 additions & 6 deletions src/disk/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{bail, Result};
use hyper::StatusCode;
use hyper_tls::HttpsConnector;

use super::*;
use crate::{components::node::RemoteNode, disk::status::*};
Expand Down Expand Up @@ -329,8 +330,8 @@ impl Default for P2pool {

impl Xvb {
pub async fn is_token_exist(address: String, token: String) -> Result<()> {
let client: hyper::Client<hyper::client::HttpConnector> =
hyper::Client::builder().build(hyper::client::HttpConnector::new());
let https = HttpsConnector::new();
let client = hyper::Client::builder().build(https);
if let Ok(request) = hyper::Request::builder()
.method("GET")
.uri(format!(
Expand All @@ -339,16 +340,17 @@ impl Xvb {
))
.body(hyper::Body::empty())
{
if let Ok(resp) = client.request(request).await {
match resp.status() {
match client.request(request).await {
Ok(resp) => match resp.status() {
StatusCode::OK => Ok(()),
StatusCode::UNPROCESSABLE_ENTITY => {
bail!("the token is invalid for this xmr address.")
}
_ => bail!("The status of the response is not expected"),
},
Err(err) => {
bail!("error from response: {}", err)
}
} else {
bail!("error from response")
}
} else {
bail!("request could not be build")
Expand Down
Loading

0 comments on commit dac7dee

Please sign in to comment.