mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
Merge branch 'main' into dev
This commit is contained in:
commit
26fc4a9fa4
9 changed files with 191 additions and 155 deletions
41
Cargo.lock
generated
41
Cargo.lock
generated
|
@ -997,6 +997,46 @@ dependencies = [
|
|||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.65",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70"
|
||||
|
||||
[[package]]
|
||||
name = "clipboard-win"
|
||||
version = "5.3.1"
|
||||
|
@ -2150,6 +2190,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"cfg-if",
|
||||
"chrono",
|
||||
"clap",
|
||||
"derive_more",
|
||||
"dirs",
|
||||
"eframe",
|
||||
|
|
|
@ -29,6 +29,7 @@ bundle = []
|
|||
distro = []
|
||||
|
||||
[dependencies]
|
||||
clap = {version="4.5", features=["cargo", "derive"]}
|
||||
anyhow = "1.0.86"
|
||||
benri = "0.1.12"
|
||||
bytes = "1.6.0"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
Example:
|
||||
|
||||
```
|
||||
gupaxx-cli --token xxxxx --address xxxxx --hero --p2pool="127.0.0.1:3333" --xmrig-add-args="--xxx --xxx" -t 8 -q --path-xmrig="/path/to/xmrig-binary"
|
||||
gupaxx --cli --token xxxxx --address xxxxx --hero --p2pool="127.0.0.1:3333" --xmrig-add-args="--xxx --xxx" -t 8 -q --path-xmrig="/path/to/xmrig-binary"
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
@ -46,7 +46,5 @@ You are not the winner
|
|||
|
||||
## Technical implementation
|
||||
|
||||
The CLI binary must be constructed by enabling the feature `cli`.
|
||||
The feature enabled will adapt the code of the GUI.
|
||||
|
||||
It has also his own main source file.
|
||||
The cli args are managed by [clap](https://docs.rs/clap).
|
||||
The code for managing current args from upstream will be replaced to use this crate.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use crate::cli::parse_args;
|
||||
use crate::cli::Cli;
|
||||
use crate::components::gupax::FileWindow;
|
||||
use crate::components::node::Ping;
|
||||
use crate::components::node::RemoteNode;
|
||||
|
@ -27,7 +29,6 @@ use crate::inits::init_text_styles;
|
|||
use crate::miscs::cmp_f64;
|
||||
use crate::miscs::get_exe;
|
||||
use crate::miscs::get_exe_dir;
|
||||
use crate::miscs::parse_args;
|
||||
use crate::utils::constants::VISUALS;
|
||||
use crate::utils::macros::arc_mut;
|
||||
use crate::utils::macros::lock;
|
||||
|
@ -170,7 +171,7 @@ impl App {
|
|||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn new(now: Instant) -> Self {
|
||||
pub fn new(now: Instant, args: Cli) -> Self {
|
||||
info!("Initializing App Struct...");
|
||||
info!("App Init | P2Pool & XMRig processes...");
|
||||
let p2pool = arc_mut!(Process::new(
|
||||
|
@ -336,7 +337,7 @@ impl App {
|
|||
// It's not safe to [--reset] if any of the previous variables
|
||||
// are unset (null path), so make sure we just abort if the [panic] String contains something.
|
||||
info!("App Init | Applying argument state...");
|
||||
let mut app = parse_args(app, panic);
|
||||
let mut app = parse_args(app, args, panic);
|
||||
|
||||
use crate::disk::errors::TomlError::*;
|
||||
// Read disk state
|
||||
|
|
133
src/cli.rs
Normal file
133
src/cli.rs
Normal file
|
@ -0,0 +1,133 @@
|
|||
use std::process::exit;
|
||||
|
||||
use clap::crate_authors;
|
||||
use clap::crate_description;
|
||||
use clap::crate_name;
|
||||
use clap::crate_version;
|
||||
use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
use log::debug;
|
||||
use log::info;
|
||||
use log::warn;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::miscs::print_disk_file;
|
||||
use crate::miscs::print_gupax_p2pool_api;
|
||||
use crate::resets::reset;
|
||||
use crate::resets::reset_gupax_p2pool_api;
|
||||
use crate::resets::reset_nodes;
|
||||
use crate::resets::reset_pools;
|
||||
use crate::resets::reset_state;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = crate_name!())]
|
||||
#[command(author = crate_authors!())]
|
||||
#[command(version = crate_version!())]
|
||||
#[command(about = crate_description!(), long_about = None)]
|
||||
#[command(next_line_help = true)]
|
||||
#[group(required = false, multiple = false)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub info: Option<GupaxxData>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum GupaxxData {
|
||||
#[command(about = "Print Gupaxx state")]
|
||||
State,
|
||||
#[command(about = "Print the manual node list")]
|
||||
Nodes,
|
||||
#[command(about = "Print the P2Pool payout log, payout count, and total XMR mined")]
|
||||
Payouts,
|
||||
#[command(about = "Reset all Gupaxxstate (your settings)")]
|
||||
ResetState,
|
||||
#[command(about = "Reset the manual node list in the [P2Pool] tab")]
|
||||
ResetNodes,
|
||||
#[command(about = "Reset the manual pool list in the [XMRig] tab")]
|
||||
ResetPools,
|
||||
#[command(about = "Reset the permanent P2Pool stats that appear in the [Status] tab")]
|
||||
ResetPayouts,
|
||||
#[command(about = "Reset all Gupaxx state (your settings)")]
|
||||
ResetAll,
|
||||
#[command(
|
||||
about = "Disable all auto-startup settings for this instance (auto-update, auto-ping, etc)",
|
||||
name = "no-startup"
|
||||
)]
|
||||
Nostartup,
|
||||
}
|
||||
// #[cold]
|
||||
// #[inline(never)]
|
||||
pub fn parse_args<S: Into<String>>(mut app: App, args: Cli, panic: S) -> App {
|
||||
info!("Parsing CLI arguments...");
|
||||
|
||||
// Abort on panic
|
||||
let panic = panic.into();
|
||||
if !panic.is_empty() {
|
||||
warn!("[Gupax error] {}", panic);
|
||||
exit(1);
|
||||
}
|
||||
if let Some(arg) = args.info {
|
||||
match arg {
|
||||
GupaxxData::State => {
|
||||
debug!("Printing state...");
|
||||
print_disk_file(&app.state_path);
|
||||
exit(0);
|
||||
}
|
||||
GupaxxData::Nodes => {
|
||||
debug!("Printing node list...");
|
||||
print_disk_file(&app.node_path);
|
||||
exit(0);
|
||||
}
|
||||
GupaxxData::Payouts => {
|
||||
debug!("Printing payouts...\n");
|
||||
print_gupax_p2pool_api(&app.gupax_p2pool_api);
|
||||
exit(0);
|
||||
}
|
||||
GupaxxData::ResetState => {
|
||||
if let Ok(()) = reset_state(&app.state_path) {
|
||||
println!("\nState reset ... OK");
|
||||
exit(0);
|
||||
} else {
|
||||
eprintln!("\nState reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
GupaxxData::ResetNodes => {
|
||||
if let Ok(()) = reset_nodes(&app.node_path) {
|
||||
println!("\nNode reset ... OK");
|
||||
exit(0)
|
||||
} else {
|
||||
eprintln!("\nNode reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
GupaxxData::ResetPools => {
|
||||
if let Ok(()) = reset_pools(&app.pool_path) {
|
||||
println!("\nPool reset ... OK");
|
||||
exit(0)
|
||||
} else {
|
||||
eprintln!("\nPool reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
GupaxxData::ResetPayouts => {
|
||||
if let Ok(()) = reset_gupax_p2pool_api(&app.gupax_p2pool_api_path) {
|
||||
println!("\nGupaxP2poolApi reset ... OK");
|
||||
exit(0)
|
||||
} else {
|
||||
eprintln!("\nGupaxP2poolApi reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
GupaxxData::ResetAll => reset(
|
||||
&app.os_data_path,
|
||||
&app.state_path,
|
||||
&app.node_path,
|
||||
&app.pool_path,
|
||||
&app.gupax_p2pool_api_path,
|
||||
),
|
||||
GupaxxData::Nostartup => app.no_startup = true,
|
||||
}
|
||||
}
|
||||
app
|
||||
}
|
|
@ -26,6 +26,7 @@ compile_error!("gupax is only compatible with 64-bit CPUs");
|
|||
compile_error!("gupax is only built for windows/macos/linux");
|
||||
|
||||
use crate::app::App;
|
||||
use crate::cli::Cli;
|
||||
//---------------------------------------------------------------------------------------------------- Imports
|
||||
use crate::constants::*;
|
||||
use crate::inits::init_auto;
|
||||
|
@ -33,12 +34,14 @@ use crate::inits::init_logger;
|
|||
use crate::inits::init_options;
|
||||
use crate::miscs::clean_dir;
|
||||
use crate::utils::*;
|
||||
use clap::Parser;
|
||||
use egui::Vec2;
|
||||
use log::info;
|
||||
use log::warn;
|
||||
use std::time::Instant;
|
||||
|
||||
mod app;
|
||||
mod cli;
|
||||
mod components;
|
||||
mod disk;
|
||||
mod helper;
|
||||
|
@ -52,6 +55,7 @@ extern crate sudo as sudo_check;
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- Main [App] frame
|
||||
fn main() {
|
||||
let args = Cli::parse();
|
||||
let now = Instant::now();
|
||||
|
||||
// Set custom panic hook.
|
||||
|
@ -59,7 +63,7 @@ fn main() {
|
|||
|
||||
// Init logger.
|
||||
init_logger(now);
|
||||
let mut app = App::new(now);
|
||||
let mut app = App::new(now, args);
|
||||
init_auto(&mut app);
|
||||
|
||||
// Init GUI stuff.
|
||||
|
|
120
src/miscs.rs
120
src/miscs.rs
|
@ -1,111 +1,4 @@
|
|||
//---------------------------------------------------------------------------------------------------- Misc functions
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn parse_args<S: Into<String>>(mut app: App, panic: S) -> App {
|
||||
info!("Parsing CLI arguments...");
|
||||
let mut args: Vec<String> = env::args().collect();
|
||||
if args.len() == 1 {
|
||||
info!("No args ... OK");
|
||||
return app;
|
||||
} else {
|
||||
args.remove(0);
|
||||
info!("Args ... {:?}", args);
|
||||
}
|
||||
// [help/version], exit early
|
||||
for arg in &args {
|
||||
match arg.as_str() {
|
||||
"--help" => {
|
||||
println!("{}", ARG_HELP);
|
||||
exit(0);
|
||||
}
|
||||
"--version" => {
|
||||
println!("Gupaxx {} [OS: {}, Commit: {}]\nThis Gupax was originally bundled with:\n - P2Pool {}\n - XMRig {}\n\n{}", GUPAX_VERSION, OS_NAME, &COMMIT[..40], P2POOL_VERSION, XMRIG_VERSION, ARG_COPYRIGHT);
|
||||
exit(0);
|
||||
}
|
||||
"--ferris" => {
|
||||
println!("{}", FERRIS_ANSI);
|
||||
exit(0);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
// Abort on panic
|
||||
let panic = panic.into();
|
||||
if !panic.is_empty() {
|
||||
info!("[Gupax error] {}", panic);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Everything else
|
||||
for arg in args {
|
||||
match arg.as_str() {
|
||||
"--state" => {
|
||||
info!("Printing state...");
|
||||
print_disk_file(&app.state_path);
|
||||
}
|
||||
"--nodes" => {
|
||||
info!("Printing node list...");
|
||||
print_disk_file(&app.node_path);
|
||||
}
|
||||
"--payouts" => {
|
||||
info!("Printing payouts...\n");
|
||||
print_gupax_p2pool_api(&app.gupax_p2pool_api);
|
||||
}
|
||||
"--reset-state" => {
|
||||
if let Ok(()) = reset_state(&app.state_path) {
|
||||
println!("\nState reset ... OK");
|
||||
exit(0);
|
||||
} else {
|
||||
eprintln!("\nState reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
"--reset-nodes" => {
|
||||
if let Ok(()) = reset_nodes(&app.node_path) {
|
||||
println!("\nNode reset ... OK");
|
||||
exit(0)
|
||||
} else {
|
||||
eprintln!("\nNode reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
"--reset-pools" => {
|
||||
if let Ok(()) = reset_pools(&app.pool_path) {
|
||||
println!("\nPool reset ... OK");
|
||||
exit(0)
|
||||
} else {
|
||||
eprintln!("\nPool reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
"--reset-payouts" => {
|
||||
if let Ok(()) = reset_gupax_p2pool_api(&app.gupax_p2pool_api_path) {
|
||||
println!("\nGupaxP2poolApi reset ... OK");
|
||||
exit(0)
|
||||
} else {
|
||||
eprintln!("\nGupaxP2poolApi reset ... FAIL");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
"--reset-all" => reset(
|
||||
&app.os_data_path,
|
||||
&app.state_path,
|
||||
&app.node_path,
|
||||
&app.pool_path,
|
||||
&app.gupax_p2pool_api_path,
|
||||
),
|
||||
"--no-startup" => app.no_startup = true,
|
||||
_ => {
|
||||
eprintln!(
|
||||
"\n[Gupax error] Invalid option: [{}]\nFor help, use: [--help]",
|
||||
arg
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
// Get absolute [Gupax] binary path
|
||||
#[cold]
|
||||
|
@ -167,7 +60,7 @@ pub fn clean_dir() -> Result<(), anyhow::Error> {
|
|||
// Print disk files to console
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn print_disk_file(path: &PathBuf) {
|
||||
pub fn print_disk_file(path: &PathBuf) {
|
||||
match std::fs::read_to_string(path) {
|
||||
Ok(string) => {
|
||||
print!("{}", string);
|
||||
|
@ -240,21 +133,14 @@ use log::error;
|
|||
use log::warn;
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::{env, process::exit};
|
||||
|
||||
use log::info;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Use
|
||||
use crate::{
|
||||
app::App,
|
||||
constants::*,
|
||||
utils::{
|
||||
ferris::FERRIS_ANSI,
|
||||
resets::{reset, reset_gupax_p2pool_api, reset_nodes, reset_pools, reset_state},
|
||||
},
|
||||
};
|
||||
use crate::constants::*;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
#[cold]
|
||||
|
|
|
@ -442,6 +442,7 @@ pub const XVB_ROUND_DONOR_VIP_MIN_HR: u32 = 10000;
|
|||
pub const XVB_ROUND_DONOR_WHALE_MIN_HR: u32 = 100000;
|
||||
pub const XVB_ROUND_DONOR_MEGA_MIN_HR: u32 = 1000000;
|
||||
|
||||
|
||||
// Manual Mode
|
||||
pub const XVB_MODE_MANUAL_XVB_HELP: &str = "Manually set the amount to donate to XmrVsBeast, 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";
|
||||
|
@ -457,28 +458,6 @@ pub const XVB_DONATION_LEVEL_WHALE_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.)";
|
||||
|
||||
// CLI argument messages
|
||||
pub const ARG_HELP: &str = r#"USAGE: ./gupaxx [--flag]
|
||||
|
||||
--help Print this help message
|
||||
--version Print version and build info
|
||||
--state Print Gupaxxstate
|
||||
--nodes Print the manual node list
|
||||
--payouts Print the P2Pool payout log, payout count, and total XMR mined
|
||||
--no-startup Disable all auto-startup settings for this instance (auto-update, auto-ping, etc)
|
||||
--reset-state Reset all Gupaxxstate (your settings)
|
||||
--reset-nodes Reset the manual node list in the [P2Pool] tab
|
||||
--reset-pools Reset the manual pool list in the [XMRig] tab
|
||||
--reset-payouts Reset the permanent P2Pool stats that appear in the [Status] tab
|
||||
--reset-all Reset the state, manual node list, manual pool list, and P2Pool stats
|
||||
|
||||
To view more detailed console debug information, start Gupaxxwith
|
||||
the environment variable [RUST_LOG] set to a log level like so:
|
||||
RUST_LOG=(trace|debug|info|warn|error) ./gupaxx"#;
|
||||
pub const ARG_COPYRIGHT: &str = r#"Gupaxxis licensed under GPLv3.
|
||||
For more information, see link below:
|
||||
<https://github.com/Cyrix126/gupaxx>"#;
|
||||
|
||||
// Unknown Data, replace HumanNumlber::unknown()
|
||||
pub const UNKNOWN_DATA: &str = "???";
|
||||
// Time PPLNS WINDOW in seconds
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue