mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-11-16 23:37:47 +00:00
fix: rustfmt formatting
This commit is contained in:
parent
56cee0da0a
commit
55baa7054e
18 changed files with 10340 additions and 7832 deletions
522
src/constants.rs
522
src/constants.rs
|
@ -15,51 +15,49 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
pub const GUPAX_VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION")); // e.g: v1.0.0
|
pub const GUPAX_VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION")); // e.g: v1.0.0
|
||||||
pub const P2POOL_VERSION: &str = "v3.10";
|
pub const P2POOL_VERSION: &str = "v3.10";
|
||||||
pub const XMRIG_VERSION: &str = "v6.21.0";
|
pub const XMRIG_VERSION: &str = "v6.21.0";
|
||||||
pub const COMMIT: &str = env!("COMMIT"); // set in build.rs
|
pub const COMMIT: &str = env!("COMMIT"); // set in build.rs
|
||||||
// e.g: Gupax_v1_0_0
|
// e.g: Gupax_v1_0_0
|
||||||
// Would have been [Gupax_v1.0.0] but P2Pool truncates everything after [.]
|
// Would have been [Gupax_v1.0.0] but P2Pool truncates everything after [.]
|
||||||
pub const GUPAX_VERSION_UNDERSCORE: &str = concat!(
|
pub const GUPAX_VERSION_UNDERSCORE: &str = concat!(
|
||||||
"Gupax_v",
|
"Gupax_v",
|
||||||
env!("CARGO_PKG_VERSION_MAJOR"),
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
||||||
"_",
|
"_",
|
||||||
env!("CARGO_PKG_VERSION_MINOR"),
|
env!("CARGO_PKG_VERSION_MINOR"),
|
||||||
"_",
|
"_",
|
||||||
env!("CARGO_PKG_VERSION_PATCH"),
|
env!("CARGO_PKG_VERSION_PATCH"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// App frame resolution, [4:3] aspect ratio, [1.33:1]
|
// App frame resolution, [4:3] aspect ratio, [1.33:1]
|
||||||
pub const APP_MIN_WIDTH: f32 = 640.0;
|
pub const APP_MIN_WIDTH: f32 = 640.0;
|
||||||
pub const APP_MIN_HEIGHT: f32 = 480.0;
|
pub const APP_MIN_HEIGHT: f32 = 480.0;
|
||||||
pub const APP_MAX_WIDTH: f32 = 3840.0;
|
pub const APP_MAX_WIDTH: f32 = 3840.0;
|
||||||
pub const APP_MAX_HEIGHT: f32 = 2160.0;
|
pub const APP_MAX_HEIGHT: f32 = 2160.0;
|
||||||
// Default, 1280x960
|
// Default, 1280x960
|
||||||
pub const APP_DEFAULT_WIDTH: f32 = 1280.0;
|
pub const APP_DEFAULT_WIDTH: f32 = 1280.0;
|
||||||
pub const APP_DEFAULT_HEIGHT: f32 = 960.0;
|
pub const APP_DEFAULT_HEIGHT: f32 = 960.0;
|
||||||
// App resolution scaling
|
// App resolution scaling
|
||||||
pub const APP_MIN_SCALE: f32 = 0.1;
|
pub const APP_MIN_SCALE: f32 = 0.1;
|
||||||
pub const APP_MAX_SCALE: f32 = 2.0;
|
pub const APP_MAX_SCALE: f32 = 2.0;
|
||||||
pub const APP_DEFAULT_SCALE: f32 = 1.0;
|
pub const APP_DEFAULT_SCALE: f32 = 1.0;
|
||||||
|
|
||||||
// Constants specific for Linux distro packaging of Gupax
|
// Constants specific for Linux distro packaging of Gupax
|
||||||
#[cfg(feature = "distro")]
|
#[cfg(feature = "distro")]
|
||||||
pub const DISTRO_NO_UPDATE: &str =
|
pub const DISTRO_NO_UPDATE: &str = r#"This [Gupax] was compiled for use as a Linux distro package. Built-in updates are disabled. The below settings [Update-via-Tor] & [Auto-Update] will not do anything. Please use your package manager to update [Gupax/P2Pool/XMRig]."#;
|
||||||
r#"This [Gupax] was compiled for use as a Linux distro package. Built-in updates are disabled. The below settings [Update-via-Tor] & [Auto-Update] will not do anything. Please use your package manager to update [Gupax/P2Pool/XMRig]."#;
|
|
||||||
|
|
||||||
// Use macOS shaped icon for macOS
|
// Use macOS shaped icon for macOS
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub const BYTES_ICON: &[u8] = include_bytes!("../images/icons/icon@2x.png");
|
pub const BYTES_ICON: &[u8] = include_bytes!("../images/icons/icon@2x.png");
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
pub const BYTES_ICON: &[u8] = include_bytes!("../images/icons/icon.png");
|
pub const BYTES_ICON: &[u8] = include_bytes!("../images/icons/icon.png");
|
||||||
pub const BYTES_BANNER: &[u8] = include_bytes!("../images/banner.png");
|
pub const BYTES_BANNER: &[u8] = include_bytes!("../images/banner.png");
|
||||||
pub const HORIZONTAL: &str = "--------------------------------------------";
|
pub const HORIZONTAL: &str = "--------------------------------------------";
|
||||||
pub const HORI_CONSOLE: &str = "---------------------------------------------------------------------------------------------------------------------------";
|
pub const HORI_CONSOLE: &str = "---------------------------------------------------------------------------------------------------------------------------";
|
||||||
|
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
pub const KEYBOARD_SHORTCUTS: &str =
|
pub const KEYBOARD_SHORTCUTS: &str = r#"*---------------------------------------*
|
||||||
r#"*---------------------------------------*
|
|
||||||
| Key shortcuts |
|
| Key shortcuts |
|
||||||
|---------------------------------------|
|
|---------------------------------------|
|
||||||
| F11 | Fullscreen |
|
| F11 | Fullscreen |
|
||||||
|
@ -75,28 +73,29 @@ r#"*---------------------------------------*
|
||||||
*---------------------------------------*"#;
|
*---------------------------------------*"#;
|
||||||
// P2Pool & XMRig default API stuff
|
// P2Pool & XMRig default API stuff
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub const P2POOL_API_PATH_LOCAL: &str = r"local\stratum";
|
pub const P2POOL_API_PATH_LOCAL: &str = r"local\stratum";
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub const P2POOL_API_PATH_NETWORK: &str = r"network\stats";
|
pub const P2POOL_API_PATH_NETWORK: &str = r"network\stats";
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub const P2POOL_API_PATH_POOL: &str = r"pool\stats";
|
pub const P2POOL_API_PATH_POOL: &str = r"pool\stats";
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub const P2POOL_API_PATH_LOCAL: &str = "local/stratum";
|
pub const P2POOL_API_PATH_LOCAL: &str = "local/stratum";
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub const P2POOL_API_PATH_NETWORK: &str = "network/stats";
|
pub const P2POOL_API_PATH_NETWORK: &str = "network/stats";
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub const P2POOL_API_PATH_POOL: &str = "pool/stats";
|
pub const P2POOL_API_PATH_POOL: &str = "pool/stats";
|
||||||
pub const XMRIG_API_URI: &str = "1/summary"; // The default relative URI of XMRig's API
|
pub const XMRIG_API_URI: &str = "1/summary"; // The default relative URI of XMRig's API
|
||||||
|
|
||||||
// Process state tooltips (online, offline, etc)
|
// Process state tooltips (online, offline, etc)
|
||||||
pub const P2POOL_ALIVE: &str = "P2Pool is online and fully synchronized";
|
pub const P2POOL_ALIVE: &str = "P2Pool is online and fully synchronized";
|
||||||
pub const P2POOL_DEAD: &str = "P2Pool is offline";
|
pub const P2POOL_DEAD: &str = "P2Pool is offline";
|
||||||
pub const P2POOL_FAILED: &str = "P2Pool is offline and failed when exiting";
|
pub const P2POOL_FAILED: &str = "P2Pool is offline and failed when exiting";
|
||||||
pub const P2POOL_MIDDLE: &str = "P2Pool is in the middle of (re)starting/stopping";
|
pub const P2POOL_MIDDLE: &str = "P2Pool is in the middle of (re)starting/stopping";
|
||||||
pub const P2POOL_SYNCING: &str = "P2Pool is still syncing. This indicator will turn GREEN when P2Pool is ready";
|
pub const P2POOL_SYNCING: &str =
|
||||||
|
"P2Pool is still syncing. This indicator will turn GREEN when P2Pool is ready";
|
||||||
|
|
||||||
pub const XMRIG_ALIVE: &str = "XMRig is online and mining";
|
pub const XMRIG_ALIVE: &str = "XMRig is online and mining";
|
||||||
pub const XMRIG_DEAD: &str = "XMRig is offline";
|
pub const XMRIG_DEAD: &str = "XMRig is offline";
|
||||||
pub const XMRIG_FAILED: &str = "XMRig is offline and failed when exiting";
|
pub const XMRIG_FAILED: &str = "XMRig is offline and failed when exiting";
|
||||||
pub const XMRIG_MIDDLE: &str = "XMRig is in the middle of (re)starting/stopping";
|
pub const XMRIG_MIDDLE: &str = "XMRig is in the middle of (re)starting/stopping";
|
||||||
pub const XMRIG_NOT_MINING: &str = "XMRig is online, but not mining to any pool";
|
pub const XMRIG_NOT_MINING: &str = "XMRig is online, but not mining to any pool";
|
||||||
|
@ -108,31 +107,29 @@ pub const XMRIG_NOT_MINING: &str = "XMRig is online, but not mining to any pool"
|
||||||
pub const SPACE: f32 = 10.0;
|
pub const SPACE: f32 = 10.0;
|
||||||
|
|
||||||
// Some colors
|
// Some colors
|
||||||
pub const RED: egui::Color32 = egui::Color32::from_rgb(230, 50, 50);
|
pub const RED: egui::Color32 = egui::Color32::from_rgb(230, 50, 50);
|
||||||
pub const GREEN: egui::Color32 = egui::Color32::from_rgb(100, 230, 100);
|
pub const GREEN: egui::Color32 = egui::Color32::from_rgb(100, 230, 100);
|
||||||
pub const BLUE: egui::Color32 = egui::Color32::from_rgb(100, 175, 255);
|
pub const BLUE: egui::Color32 = egui::Color32::from_rgb(100, 175, 255);
|
||||||
pub const ORANGE: egui::Color32 = egui::Color32::from_rgb(255, 120, 40);
|
pub const ORANGE: egui::Color32 = egui::Color32::from_rgb(255, 120, 40);
|
||||||
pub const YELLOW: egui::Color32 = egui::Color32::from_rgb(230, 230, 100);
|
pub const YELLOW: egui::Color32 = egui::Color32::from_rgb(230, 230, 100);
|
||||||
pub const BRIGHT_YELLOW: egui::Color32 = egui::Color32::from_rgb(250, 250, 100);
|
pub const BRIGHT_YELLOW: egui::Color32 = egui::Color32::from_rgb(250, 250, 100);
|
||||||
pub const BONE: egui::Color32 = egui::Color32::from_rgb(190, 190, 190); // In between LIGHT_GRAY <-> GRAY
|
pub const BONE: egui::Color32 = egui::Color32::from_rgb(190, 190, 190); // In between LIGHT_GRAY <-> GRAY
|
||||||
pub const WHITE: egui::Color32 = egui::Color32::WHITE;
|
pub const WHITE: egui::Color32 = egui::Color32::WHITE;
|
||||||
pub const GRAY: egui::Color32 = egui::Color32::GRAY;
|
pub const GRAY: egui::Color32 = egui::Color32::GRAY;
|
||||||
pub const LIGHT_GRAY: egui::Color32 = egui::Color32::LIGHT_GRAY;
|
pub const LIGHT_GRAY: egui::Color32 = egui::Color32::LIGHT_GRAY;
|
||||||
pub const BLACK: egui::Color32 = egui::Color32::BLACK;
|
pub const BLACK: egui::Color32 = egui::Color32::BLACK;
|
||||||
pub const DARK_GRAY: egui::Color32 = egui::Color32::from_gray(13);
|
pub const DARK_GRAY: egui::Color32 = egui::Color32::from_gray(13);
|
||||||
|
|
||||||
// [Duration] constants
|
// [Duration] constants
|
||||||
pub const SECOND: std::time::Duration = std::time::Duration::from_secs(1);
|
pub const SECOND: std::time::Duration = std::time::Duration::from_secs(1);
|
||||||
|
|
||||||
// The explanation given to the user on why XMRig needs sudo.
|
// The explanation given to the user on why XMRig needs sudo.
|
||||||
pub const XMRIG_ADMIN_REASON: &str =
|
pub const XMRIG_ADMIN_REASON: &str = r#"The large hashrate difference between XMRig and other miners like Monero and P2Pool's built-in miners is mostly due to XMRig configuring CPU MSRs and setting up hugepages. Other miners like Monero or P2Pool's built-in miner do not do this. It can be done manually but it isn't recommended since XMRig does this for you automatically, but only if it has the proper admin privileges."#;
|
||||||
r#"The large hashrate difference between XMRig and other miners like Monero and P2Pool's built-in miners is mostly due to XMRig configuring CPU MSRs and setting up hugepages. Other miners like Monero or P2Pool's built-in miner do not do this. It can be done manually but it isn't recommended since XMRig does this for you automatically, but only if it has the proper admin privileges."#;
|
|
||||||
// Password buttons
|
// Password buttons
|
||||||
pub const PASSWORD_TEXT: &str = "Enter sudo/admin password...";
|
pub const PASSWORD_TEXT: &str = "Enter sudo/admin password...";
|
||||||
pub const PASSWORD_LEAVE: &str = "Return to the previous screen";
|
pub const PASSWORD_LEAVE: &str = "Return to the previous screen";
|
||||||
pub const PASSWORD_ENTER: &str = "Attempt with the current password";
|
pub const PASSWORD_ENTER: &str = "Attempt with the current password";
|
||||||
pub const PASSWORD_HIDE: &str = "Toggle hiding/showing the password";
|
pub const PASSWORD_HIDE: &str = "Toggle hiding/showing the password";
|
||||||
|
|
||||||
|
|
||||||
// OS specific
|
// OS specific
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
@ -154,111 +151,132 @@ pub const OS_NAME: &str = "Linux";
|
||||||
|
|
||||||
// Tooltips
|
// Tooltips
|
||||||
// Status
|
// Status
|
||||||
pub const STATUS_GUPAX_UPTIME: &str = "How long Gupax has been online";
|
pub const STATUS_GUPAX_UPTIME: &str = "How long Gupax has been online";
|
||||||
pub const STATUS_GUPAX_CPU_USAGE: &str = "How much CPU Gupax is currently using. This accounts for all your threads (it is out of 100%)";
|
pub const STATUS_GUPAX_CPU_USAGE: &str =
|
||||||
pub const STATUS_GUPAX_MEMORY_USAGE: &str = "How much memory Gupax is currently using in Megabytes";
|
"How much CPU Gupax is currently using. This accounts for all your threads (it is out of 100%)";
|
||||||
|
pub const STATUS_GUPAX_MEMORY_USAGE: &str = "How much memory Gupax is currently using in Megabytes";
|
||||||
pub const STATUS_GUPAX_SYSTEM_CPU_USAGE: &str = "How much CPU your entire system is currently using. This accounts for all your threads (it is out of 100%)";
|
pub const STATUS_GUPAX_SYSTEM_CPU_USAGE: &str = "How much CPU your entire system is currently using. This accounts for all your threads (it is out of 100%)";
|
||||||
pub const STATUS_GUPAX_SYSTEM_MEMORY: &str = "How much memory your entire system has (including swap) and is currently using in Gigabytes";
|
pub const STATUS_GUPAX_SYSTEM_MEMORY: &str =
|
||||||
pub const STATUS_GUPAX_SYSTEM_CPU_MODEL: &str = "The detected model of your system's CPU and its current frequency";
|
"How much memory your entire system has (including swap) and is currently using in Gigabytes";
|
||||||
|
pub const STATUS_GUPAX_SYSTEM_CPU_MODEL: &str =
|
||||||
|
"The detected model of your system's CPU and its current frequency";
|
||||||
//--
|
//--
|
||||||
pub const STATUS_P2POOL_UPTIME: &str = "How long P2Pool has been online";
|
pub const STATUS_P2POOL_UPTIME: &str = "How long P2Pool has been online";
|
||||||
pub const STATUS_P2POOL_PAYOUTS: &str = "The total amount of payouts received in this instance of P2Pool and an extrapolated estimate of how many you will receive. Warning: these stats will be quite inaccurate if your P2Pool hasn't been running for a long time!";
|
pub const STATUS_P2POOL_PAYOUTS: &str = "The total amount of payouts received in this instance of P2Pool and an extrapolated estimate of how many you will receive. Warning: these stats will be quite inaccurate if your P2Pool hasn't been running for a long time!";
|
||||||
pub const STATUS_P2POOL_XMR: &str = "The total amount of XMR mined in this instance of P2Pool and an extrapolated estimate of how many you will mine in the future. Warning: these stats will be quite inaccurate if your P2Pool hasn't been running for a long time!";
|
pub const STATUS_P2POOL_XMR: &str = "The total amount of XMR mined in this instance of P2Pool and an extrapolated estimate of how many you will mine in the future. Warning: these stats will be quite inaccurate if your P2Pool hasn't been running for a long time!";
|
||||||
pub const STATUS_P2POOL_HASHRATE: &str = "The total amount of hashrate your P2Pool has pointed at it in 15 minute, 1 hour, and 24 hour averages";
|
pub const STATUS_P2POOL_HASHRATE: &str = "The total amount of hashrate your P2Pool has pointed at it in 15 minute, 1 hour, and 24 hour averages";
|
||||||
pub const STATUS_P2POOL_SHARES: &str = "The total amount of shares found on P2Pool";
|
pub const STATUS_P2POOL_SHARES: &str = "The total amount of shares found on P2Pool";
|
||||||
pub const STATUS_P2POOL_EFFORT: &str = "The average amount of effort needed to find a share, and the current effort";
|
pub const STATUS_P2POOL_EFFORT: &str =
|
||||||
|
"The average amount of effort needed to find a share, and the current effort";
|
||||||
pub const STATUS_P2POOL_CONNECTIONS: &str = "The total amount of miner connections on this P2Pool";
|
pub const STATUS_P2POOL_CONNECTIONS: &str = "The total amount of miner connections on this P2Pool";
|
||||||
pub const STATUS_P2POOL_MONERO_NODE: &str = "The Monero node being used by P2Pool";
|
pub const STATUS_P2POOL_MONERO_NODE: &str = "The Monero node being used by P2Pool";
|
||||||
pub const STATUS_P2POOL_POOL: &str = "The P2Pool sidechain you're currently connected to";
|
pub const STATUS_P2POOL_POOL: &str = "The P2Pool sidechain you're currently connected to";
|
||||||
pub const STATUS_P2POOL_ADDRESS: &str = "The Monero address P2Pool will send payouts to";
|
pub const STATUS_P2POOL_ADDRESS: &str = "The Monero address P2Pool will send payouts to";
|
||||||
//--
|
//--
|
||||||
pub const STATUS_XMRIG_UPTIME: &str = "How long XMRig has been online";
|
pub const STATUS_XMRIG_UPTIME: &str = "How long XMRig has been online";
|
||||||
pub const STATUS_XMRIG_CPU: &str = "The average CPU load of XMRig. [1.0] represents 1 thread is maxed out, e.g: If you have 8 threads, [4.0] means half your threads are maxed out.";
|
pub const STATUS_XMRIG_CPU: &str = "The average CPU load of XMRig. [1.0] represents 1 thread is maxed out, e.g: If you have 8 threads, [4.0] means half your threads are maxed out.";
|
||||||
pub const STATUS_XMRIG_HASHRATE: &str = "The average hashrate of XMRig";
|
pub const STATUS_XMRIG_HASHRATE: &str = "The average hashrate of XMRig";
|
||||||
pub const STATUS_XMRIG_DIFFICULTY: &str = "The current difficulty of the job XMRig is working on";
|
pub const STATUS_XMRIG_DIFFICULTY: &str = "The current difficulty of the job XMRig is working on";
|
||||||
pub const STATUS_XMRIG_SHARES: &str = "The amount of accepted and rejected shares";
|
pub const STATUS_XMRIG_SHARES: &str = "The amount of accepted and rejected shares";
|
||||||
pub const STATUS_XMRIG_POOL: &str = "The pool XMRig is currently mining to";
|
pub const STATUS_XMRIG_POOL: &str = "The pool XMRig is currently mining to";
|
||||||
pub const STATUS_XMRIG_THREADS: &str = "The amount of threads XMRig is currently using";
|
pub const STATUS_XMRIG_THREADS: &str = "The amount of threads XMRig is currently using";
|
||||||
// Status Submenus
|
// Status Submenus
|
||||||
pub const STATUS_SUBMENU_PROCESSES: &str = "View the status of process related data for [Gupax|P2Pool|XMRig]";
|
pub const STATUS_SUBMENU_PROCESSES: &str =
|
||||||
pub const STATUS_SUBMENU_P2POOL: &str = "View P2Pool specific data";
|
"View the status of process related data for [Gupax|P2Pool|XMRig]";
|
||||||
pub const STATUS_SUBMENU_HASHRATE: &str = "Compare your CPU hashrate with others";
|
pub const STATUS_SUBMENU_P2POOL: &str = "View P2Pool specific data";
|
||||||
|
pub const STATUS_SUBMENU_HASHRATE: &str = "Compare your CPU hashrate with others";
|
||||||
//-- P2Pool
|
//-- P2Pool
|
||||||
pub const STATUS_SUBMENU_PAYOUT: &str = "The total amount of payouts received via P2Pool across all time. This includes all payouts you have ever received using Gupax and P2Pool.";
|
pub const STATUS_SUBMENU_PAYOUT: &str = "The total amount of payouts received via P2Pool across all time. This includes all payouts you have ever received using Gupax and P2Pool.";
|
||||||
pub const STATUS_SUBMENU_XMR: &str = "The total of XMR mined via P2Pool across all time. This includes all the XMR you have ever mined using Gupax and P2Pool.";
|
pub const STATUS_SUBMENU_XMR: &str = "The total of XMR mined via P2Pool across all time. This includes all the XMR you have ever mined using Gupax and P2Pool.";
|
||||||
pub const STATUS_SUBMENU_LATEST: &str = "Sort the payouts from latest to oldest";
|
pub const STATUS_SUBMENU_LATEST: &str = "Sort the payouts from latest to oldest";
|
||||||
pub const STATUS_SUBMENU_OLDEST: &str = "Sort the payouts from oldest to latest";
|
pub const STATUS_SUBMENU_OLDEST: &str = "Sort the payouts from oldest to latest";
|
||||||
pub const STATUS_SUBMENU_BIGGEST: &str = "Sort the payouts from biggest to smallest";
|
pub const STATUS_SUBMENU_BIGGEST: &str = "Sort the payouts from biggest to smallest";
|
||||||
pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the payouts from smallest to biggest";
|
pub const STATUS_SUBMENU_SMALLEST: &str = "Sort the payouts from smallest to biggest";
|
||||||
pub const STATUS_SUBMENU_AUTOMATIC: &str = "Automatically calculate share/block time with your current P2Pool 1 hour average hashrate";
|
pub const STATUS_SUBMENU_AUTOMATIC: &str =
|
||||||
|
"Automatically calculate share/block time with your current P2Pool 1 hour average hashrate";
|
||||||
pub const STATUS_SUBMENU_MANUAL: &str = "Manually input a hashrate to calculate share/block time with current P2Pool/Monero network stats";
|
pub const STATUS_SUBMENU_MANUAL: &str = "Manually input a hashrate to calculate share/block time with current P2Pool/Monero network stats";
|
||||||
pub const STATUS_SUBMENU_HASH: &str = "Use [Hash] as the hashrate metric";
|
pub const STATUS_SUBMENU_HASH: &str = "Use [Hash] as the hashrate metric";
|
||||||
pub const STATUS_SUBMENU_KILO: &str = "Use [Kilo] as the hashrate metric (1,000x hash)";
|
pub const STATUS_SUBMENU_KILO: &str = "Use [Kilo] as the hashrate metric (1,000x hash)";
|
||||||
pub const STATUS_SUBMENU_MEGA: &str = "Use [Mega] as the hashrate metric (1,000,000x hash)";
|
pub const STATUS_SUBMENU_MEGA: &str = "Use [Mega] as the hashrate metric (1,000,000x hash)";
|
||||||
pub const STATUS_SUBMENU_GIGA: &str = "Use [Giga] as the hashrate metric (1,000,000,000x hash)";
|
pub const STATUS_SUBMENU_GIGA: &str = "Use [Giga] as the hashrate metric (1,000,000,000x hash)";
|
||||||
pub const STATUS_SUBMENU_P2POOL_BLOCK_MEAN: &str = "The average time it takes for P2Pool to find a block";
|
pub const STATUS_SUBMENU_P2POOL_BLOCK_MEAN: &str =
|
||||||
pub const STATUS_SUBMENU_YOUR_P2POOL_HASHRATE: &str = "Your 1 hour average hashrate on P2Pool";
|
"The average time it takes for P2Pool to find a block";
|
||||||
pub const STATUS_SUBMENU_P2POOL_SHARE_MEAN: &str = "The average time it takes for your hashrate to find a share on P2Pool";
|
pub const STATUS_SUBMENU_YOUR_P2POOL_HASHRATE: &str = "Your 1 hour average hashrate on P2Pool";
|
||||||
pub const STATUS_SUBMENU_SOLO_BLOCK_MEAN: &str = "The average time it would take for your hashrate to find a block solo mining Monero";
|
pub const STATUS_SUBMENU_P2POOL_SHARE_MEAN: &str =
|
||||||
|
"The average time it takes for your hashrate to find a share on P2Pool";
|
||||||
|
pub const STATUS_SUBMENU_SOLO_BLOCK_MEAN: &str =
|
||||||
|
"The average time it would take for your hashrate to find a block solo mining Monero";
|
||||||
pub const STATUS_SUBMENU_MONERO_DIFFICULTY: &str = "The current Monero network's difficulty (how many hashes it will take on average to find a block)";
|
pub const STATUS_SUBMENU_MONERO_DIFFICULTY: &str = "The current Monero network's difficulty (how many hashes it will take on average to find a block)";
|
||||||
pub const STATUS_SUBMENU_MONERO_HASHRATE: &str = "The current Monero network's hashrate";
|
pub const STATUS_SUBMENU_MONERO_HASHRATE: &str = "The current Monero network's hashrate";
|
||||||
pub const STATUS_SUBMENU_P2POOL_DIFFICULTY: &str = "The current P2Pool network's difficulty (how many hashes it will take on average to find a share)";
|
pub const STATUS_SUBMENU_P2POOL_DIFFICULTY: &str = "The current P2Pool network's difficulty (how many hashes it will take on average to find a share)";
|
||||||
pub const STATUS_SUBMENU_P2POOL_HASHRATE: &str = "The current P2Pool network's hashrate";
|
pub const STATUS_SUBMENU_P2POOL_HASHRATE: &str = "The current P2Pool network's hashrate";
|
||||||
pub const STATUS_SUBMENU_P2POOL_MINERS: &str = "The current amount of miners on P2Pool";
|
pub const STATUS_SUBMENU_P2POOL_MINERS: &str = "The current amount of miners on P2Pool";
|
||||||
pub const STATUS_SUBMENU_P2POOL_DOMINANCE: &str = "The percent of hashrate P2Pool accounts for in the entire Monero network";
|
pub const STATUS_SUBMENU_P2POOL_DOMINANCE: &str =
|
||||||
pub const STATUS_SUBMENU_YOUR_P2POOL_DOMINANCE: &str = "The percent of hashrate you account for in P2Pool";
|
"The percent of hashrate P2Pool accounts for in the entire Monero network";
|
||||||
pub const STATUS_SUBMENU_YOUR_MONERO_DOMINANCE: &str = "The percent of hashrate you account for in the entire Monero network";
|
pub const STATUS_SUBMENU_YOUR_P2POOL_DOMINANCE: &str =
|
||||||
|
"The percent of hashrate you account for in P2Pool";
|
||||||
|
pub const STATUS_SUBMENU_YOUR_MONERO_DOMINANCE: &str =
|
||||||
|
"The percent of hashrate you account for in the entire Monero network";
|
||||||
pub const STATUS_SUBMENU_PROGRESS_BAR: &str = "The next time Gupax will update P2Pool stats. Each [*] is 900ms (updates roughly every 54 seconds)";
|
pub const STATUS_SUBMENU_PROGRESS_BAR: &str = "The next time Gupax will update P2Pool stats. Each [*] is 900ms (updates roughly every 54 seconds)";
|
||||||
//-- Benchmarks
|
//-- Benchmarks
|
||||||
pub const STATUS_SUBMENU_YOUR_CPU: &str = "The CPU detected by Gupax";
|
pub const STATUS_SUBMENU_YOUR_CPU: &str = "The CPU detected by Gupax";
|
||||||
pub const STATUS_SUBMENU_YOUR_BENCHMARKS: &str = "How many benchmarks your CPU has had uploaded to [https://xmrig.com/benchmark] ";
|
pub const STATUS_SUBMENU_YOUR_BENCHMARKS: &str =
|
||||||
pub const STATUS_SUBMENU_YOUR_RANK: &str = "Your CPU's rank out of all CPUs listed on [https://xmrig.com/benchmark] (higher is better)";
|
"How many benchmarks your CPU has had uploaded to [https://xmrig.com/benchmark] ";
|
||||||
pub const STATUS_SUBMENU_YOUR_HIGH: &str = "The highest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
pub const STATUS_SUBMENU_YOUR_RANK: &str =
|
||||||
pub const STATUS_SUBMENU_YOUR_AVERAGE: &str = "The average hashrate of your CPU based off the data at [https://xmrig.com/benchmark]";
|
"Your CPU's rank out of all CPUs listed on [https://xmrig.com/benchmark] (higher is better)";
|
||||||
pub const STATUS_SUBMENU_YOUR_LOW: &str = "The lowest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
pub const STATUS_SUBMENU_YOUR_HIGH: &str =
|
||||||
|
"The highest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
||||||
|
pub const STATUS_SUBMENU_YOUR_AVERAGE: &str =
|
||||||
|
"The average hashrate of your CPU based off the data at [https://xmrig.com/benchmark]";
|
||||||
|
pub const STATUS_SUBMENU_YOUR_LOW: &str =
|
||||||
|
"The lowest hashrate recorded for your CPU on [https://xmrig.com/benchmark]";
|
||||||
pub const STATUS_SUBMENU_OTHER_CPUS: &str = "A list of ALL the recorded CPU benchmarks. The CPUs most similar to yours are listed first. All this data is taken from [https://xmrig.com/benchmark].";
|
pub const STATUS_SUBMENU_OTHER_CPUS: &str = "A list of ALL the recorded CPU benchmarks. The CPUs most similar to yours are listed first. All this data is taken from [https://xmrig.com/benchmark].";
|
||||||
pub const STATUS_SUBMENU_OTHER_CPU: &str = "The CPU name";
|
pub const STATUS_SUBMENU_OTHER_CPU: &str = "The CPU name";
|
||||||
pub const STATUS_SUBMENU_OTHER_RELATIVE: &str = "The relative hashrate power compared to the fastest recorded CPU, which is current: [AMD EPYC 7T83 64-Core Processor]";
|
pub const STATUS_SUBMENU_OTHER_RELATIVE: &str = "The relative hashrate power compared to the fastest recorded CPU, which is current: [AMD EPYC 7T83 64-Core Processor]";
|
||||||
pub const STATUS_SUBMENU_OTHER_HIGH: &str = "Highest hashrate record";
|
pub const STATUS_SUBMENU_OTHER_HIGH: &str = "Highest hashrate record";
|
||||||
pub const STATUS_SUBMENU_OTHER_AVERAGE: &str = "Average hashrate";
|
pub const STATUS_SUBMENU_OTHER_AVERAGE: &str = "Average hashrate";
|
||||||
pub const STATUS_SUBMENU_OTHER_LOW: &str = "Lowest hashrate record";
|
pub const STATUS_SUBMENU_OTHER_LOW: &str = "Lowest hashrate record";
|
||||||
pub const STATUS_SUBMENU_OTHER_RANK: &str = "The rank of this CPU out of [1567] (lower is better)";
|
pub const STATUS_SUBMENU_OTHER_RANK: &str = "The rank of this CPU out of [1567] (lower is better)";
|
||||||
pub const STATUS_SUBMENU_OTHER_BENCHMARKS: &str = "How many benchmarks this CPU has had posted to [https://xmrig.com/benchmark]";
|
pub const STATUS_SUBMENU_OTHER_BENCHMARKS: &str =
|
||||||
|
"How many benchmarks this CPU has had posted to [https://xmrig.com/benchmark]";
|
||||||
|
|
||||||
// Gupax
|
// Gupax
|
||||||
pub const GUPAX_UPDATE: &str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";
|
pub const GUPAX_UPDATE: &str =
|
||||||
pub const GUPAX_AUTO_UPDATE: &str = "Automatically check for updates at startup";
|
"Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";
|
||||||
pub const GUPAX_SHOULD_RESTART: &str = "Gupax was updated. A restart is recommended but not required";
|
pub const GUPAX_AUTO_UPDATE: &str = "Automatically check for updates at startup";
|
||||||
pub const GUPAX_UP_TO_DATE: &str = "Gupax is up-to-date";
|
pub const GUPAX_SHOULD_RESTART: &str =
|
||||||
|
"Gupax was updated. A restart is recommended but not required";
|
||||||
|
pub const GUPAX_UP_TO_DATE: &str = "Gupax is up-to-date";
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
pub const GUPAX_UPDATE_VIA_TOR: &str = "Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required";
|
pub const GUPAX_UPDATE_VIA_TOR: &str = "Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required";
|
||||||
#[cfg(target_os = "macos")] // Arti library has issues on macOS
|
#[cfg(target_os = "macos")] // Arti library has issues on macOS
|
||||||
pub const GUPAX_UPDATE_VIA_TOR: &str = "WARNING: This option is unstable on macOS. Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required";
|
pub const GUPAX_UPDATE_VIA_TOR: &str = "WARNING: This option is unstable on macOS. Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required";
|
||||||
pub const GUPAX_ASK_BEFORE_QUIT: &str = "Ask before quitting Gupax";
|
pub const GUPAX_ASK_BEFORE_QUIT: &str = "Ask before quitting Gupax";
|
||||||
pub const GUPAX_SAVE_BEFORE_QUIT: &str = "Automatically save any changed settings before quitting";
|
pub const GUPAX_SAVE_BEFORE_QUIT: &str = "Automatically save any changed settings before quitting";
|
||||||
pub const GUPAX_AUTO_P2POOL: &str = "Automatically start P2Pool on Gupax startup. If you are using [P2Pool Simple], this will NOT wait for your [Auto-Ping] to finish, it will start P2Pool on the pool you already have selected. This option will fail if your P2Pool settings aren't valid!";
|
pub const GUPAX_AUTO_P2POOL: &str = "Automatically start P2Pool on Gupax startup. If you are using [P2Pool Simple], this will NOT wait for your [Auto-Ping] to finish, it will start P2Pool on the pool you already have selected. This option will fail if your P2Pool settings aren't valid!";
|
||||||
pub const GUPAX_AUTO_XMRIG: &str = "Automatically start XMRig on Gupax startup. This option will fail if your XMRig settings aren't valid!";
|
pub const GUPAX_AUTO_XMRIG: &str = "Automatically start XMRig on Gupax startup. This option will fail if your XMRig settings aren't valid!";
|
||||||
pub const GUPAX_ADJUST: &str = "Adjust and set the width/height of the Gupax window";
|
pub const GUPAX_ADJUST: &str = "Adjust and set the width/height of the Gupax window";
|
||||||
pub const GUPAX_WIDTH: &str = "Set the width of the Gupax window";
|
pub const GUPAX_WIDTH: &str = "Set the width of the Gupax window";
|
||||||
pub const GUPAX_HEIGHT: &str = "Set the height of the Gupax window";
|
pub const GUPAX_HEIGHT: &str = "Set the height of the Gupax window";
|
||||||
pub const GUPAX_SCALE: &str = "Set the resolution scaling of the Gupax window (resize window to re-apply scaling)";
|
pub const GUPAX_SCALE: &str =
|
||||||
pub const GUPAX_LOCK_WIDTH: &str = "Automatically match the HEIGHT against the WIDTH in a 4:3 ratio";
|
"Set the resolution scaling of the Gupax window (resize window to re-apply scaling)";
|
||||||
pub const GUPAX_LOCK_HEIGHT: &str = "Automatically match the WIDTH against the HEIGHT in a 4:3 ratio";
|
pub const GUPAX_LOCK_WIDTH: &str =
|
||||||
pub const GUPAX_NO_LOCK: &str = "Allow individual selection of width and height";
|
"Automatically match the HEIGHT against the WIDTH in a 4:3 ratio";
|
||||||
pub const GUPAX_SET: &str = "Set the width/height of the Gupax window to the current values";
|
pub const GUPAX_LOCK_HEIGHT: &str =
|
||||||
pub const GUPAX_TAB: &str = "Set the default tab Gupax starts on";
|
"Automatically match the WIDTH against the HEIGHT in a 4:3 ratio";
|
||||||
pub const GUPAX_TAB_ABOUT: &str = "Set the tab Gupax starts on to: About";
|
pub const GUPAX_NO_LOCK: &str = "Allow individual selection of width and height";
|
||||||
pub const GUPAX_TAB_STATUS: &str = "Set the tab Gupax starts on to: Status";
|
pub const GUPAX_SET: &str = "Set the width/height of the Gupax window to the current values";
|
||||||
pub const GUPAX_TAB_GUPAX: &str = "Set the tab Gupax starts on to: Gupax";
|
pub const GUPAX_TAB: &str = "Set the default tab Gupax starts on";
|
||||||
pub const GUPAX_TAB_P2POOL: &str = "Set the tab Gupax starts on to: P2Pool";
|
pub const GUPAX_TAB_ABOUT: &str = "Set the tab Gupax starts on to: About";
|
||||||
pub const GUPAX_TAB_XMRIG: &str = "Set the tab Gupax starts on to: XMRig";
|
pub const GUPAX_TAB_STATUS: &str = "Set the tab Gupax starts on to: Status";
|
||||||
|
pub const GUPAX_TAB_GUPAX: &str = "Set the tab Gupax starts on to: Gupax";
|
||||||
|
pub const GUPAX_TAB_P2POOL: &str = "Set the tab Gupax starts on to: P2Pool";
|
||||||
|
pub const GUPAX_TAB_XMRIG: &str = "Set the tab Gupax starts on to: XMRig";
|
||||||
|
|
||||||
pub const GUPAX_SIMPLE: &str =
|
pub const GUPAX_SIMPLE: &str = r#"Use simple Gupax settings:
|
||||||
r#"Use simple Gupax settings:
|
|
||||||
- Update button
|
- Update button
|
||||||
- Basic toggles"#;
|
- Basic toggles"#;
|
||||||
pub const GUPAX_ADVANCED: &str =
|
pub const GUPAX_ADVANCED: &str = r#"Use advanced Gupax settings:
|
||||||
r#"Use advanced Gupax settings:
|
|
||||||
- Update button
|
- Update button
|
||||||
- Basic toggles
|
- Basic toggles
|
||||||
- P2Pool/XMRig binary path selector
|
- P2Pool/XMRig binary path selector
|
||||||
|
@ -272,24 +290,24 @@ pub const GUPAX_PATH_XMRIG: &str = "The location of the XMRig binary: Both absol
|
||||||
// P2Pool
|
// P2Pool
|
||||||
pub const P2POOL_MAIN: &str = "Use the P2Pool main-chain. This P2Pool finds blocks faster, but has a higher difficulty. Suitable for miners with more than 50kH/s";
|
pub const P2POOL_MAIN: &str = "Use the P2Pool main-chain. This P2Pool finds blocks faster, but has a higher difficulty. Suitable for miners with more than 50kH/s";
|
||||||
pub const P2POOL_MINI: &str = "Use the P2Pool mini-chain. This P2Pool finds blocks slower, but has a lower difficulty. Suitable for miners with less than 50kH/s";
|
pub const P2POOL_MINI: &str = "Use the P2Pool mini-chain. This P2Pool finds blocks slower, but has a lower difficulty. Suitable for miners with less than 50kH/s";
|
||||||
pub const P2POOL_OUT: &str = "How many out-bound peers to connect to? (you connecting to others)";
|
pub const P2POOL_OUT: &str = "How many out-bound peers to connect to? (you connecting to others)";
|
||||||
pub const P2POOL_IN: &str = "How many in-bound peers to allow? (others connecting to you)";
|
pub const P2POOL_IN: &str = "How many in-bound peers to allow? (others connecting to you)";
|
||||||
pub const P2POOL_LOG: &str = "Verbosity of the console log";
|
pub const P2POOL_LOG: &str = "Verbosity of the console log";
|
||||||
pub const P2POOL_AUTO_NODE: &str = "Automatically ping the remote Monero nodes at Gupax startup";
|
pub const P2POOL_AUTO_NODE: &str = "Automatically ping the remote Monero nodes at Gupax startup";
|
||||||
pub const P2POOL_AUTO_SELECT: &str = "Automatically select the fastest remote Monero node after pinging";
|
pub const P2POOL_AUTO_SELECT: &str =
|
||||||
pub const P2POOL_BACKUP_HOST_SIMPLE: &str =
|
"Automatically select the fastest remote Monero node after pinging";
|
||||||
r#"Automatically switch to the other nodes listed if the current one is down.
|
pub const P2POOL_BACKUP_HOST_SIMPLE: &str = r#"Automatically switch to the other nodes listed if the current one is down.
|
||||||
|
|
||||||
Note: you must ping the remote nodes or this feature will default to only using the currently selected node."#;
|
Note: you must ping the remote nodes or this feature will default to only using the currently selected node."#;
|
||||||
pub const P2POOL_BACKUP_HOST_ADVANCED: &str = "Automatically switch to the other nodes in your list if the current one is down.";
|
pub const P2POOL_BACKUP_HOST_ADVANCED: &str =
|
||||||
pub const P2POOL_SELECT_FASTEST: &str = "Select the fastest remote Monero node";
|
"Automatically switch to the other nodes in your list if the current one is down.";
|
||||||
pub const P2POOL_SELECT_RANDOM: &str = "Select a random remote Monero node";
|
pub const P2POOL_SELECT_FASTEST: &str = "Select the fastest remote Monero node";
|
||||||
pub const P2POOL_SELECT_LAST: &str = "Select the previous remote Monero node";
|
pub const P2POOL_SELECT_RANDOM: &str = "Select a random remote Monero node";
|
||||||
pub const P2POOL_SELECT_NEXT: &str = "Select the next remote Monero node";
|
pub const P2POOL_SELECT_LAST: &str = "Select the previous remote Monero node";
|
||||||
pub const P2POOL_PING: &str = "Ping the built-in remote Monero nodes";
|
pub const P2POOL_SELECT_NEXT: &str = "Select the next remote Monero node";
|
||||||
|
pub const P2POOL_PING: &str = "Ping the built-in remote Monero nodes";
|
||||||
pub const P2POOL_ADDRESS: &str = "You must use a primary Monero address to mine on P2Pool (starts with a 4). It is highly recommended to create a new wallet since addresses are public on P2Pool!";
|
pub const P2POOL_ADDRESS: &str = "You must use a primary Monero address to mine on P2Pool (starts with a 4). It is highly recommended to create a new wallet since addresses are public on P2Pool!";
|
||||||
pub const P2POOL_COMMUNITY_NODE_WARNING: &str =
|
pub const P2POOL_COMMUNITY_NODE_WARNING: &str = r#"TL;DR: Run & use your own Monero Node.
|
||||||
r#"TL;DR: Run & use your own Monero Node.
|
|
||||||
|
|
||||||
Using a Remote Monero Node is convenient but comes at the cost of privacy and reliability.
|
Using a Remote Monero Node is convenient but comes at the cost of privacy and reliability.
|
||||||
|
|
||||||
|
@ -300,17 +318,14 @@ Running and using your own local Monero node improves privacy and ensures your c
|
||||||
For a simple guide, see the [Running a Local Monero Node] section on Gupax's GitHub by clicking this message."#;
|
For a simple guide, see the [Running a Local Monero Node] section on Gupax's GitHub by clicking this message."#;
|
||||||
|
|
||||||
pub const P2POOL_INPUT: &str = "Send a command to P2Pool";
|
pub const P2POOL_INPUT: &str = "Send a command to P2Pool";
|
||||||
pub const P2POOL_ARGUMENTS: &str =
|
pub const P2POOL_ARGUMENTS: &str = r#"WARNING: Use [--no-color] and make sure to set [--data-api <PATH>] & [--local-api] so that the [Status] tab can work!
|
||||||
r#"WARNING: Use [--no-color] and make sure to set [--data-api <PATH>] & [--local-api] so that the [Status] tab can work!
|
|
||||||
|
|
||||||
Start P2Pool with these arguments and override all below settings"#;
|
Start P2Pool with these arguments and override all below settings"#;
|
||||||
pub const P2POOL_SIMPLE: &str =
|
pub const P2POOL_SIMPLE: &str = r#"Use simple P2Pool settings:
|
||||||
r#"Use simple P2Pool settings:
|
|
||||||
- Remote remote Monero node
|
- Remote remote Monero node
|
||||||
- Default P2Pool settings + Mini
|
- Default P2Pool settings + Mini
|
||||||
- Backup host setting"#;
|
- Backup host setting"#;
|
||||||
pub const P2POOL_ADVANCED: &str =
|
pub const P2POOL_ADVANCED: &str = r#"Use advanced P2Pool settings:
|
||||||
r#"Use advanced P2Pool settings:
|
|
||||||
- Terminal input
|
- Terminal input
|
||||||
- Overriding command arguments
|
- Overriding command arguments
|
||||||
- Manual node list
|
- Manual node list
|
||||||
|
@ -328,19 +343,17 @@ pub const P2POOL_PATH_OK: &str = "P2Pool was found at the given PATH";
|
||||||
pub const P2POOL_PATH_EMPTY: &str = "P2Pool PATH is empty! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where P2Pool is located.";
|
pub const P2POOL_PATH_EMPTY: &str = "P2Pool PATH is empty! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where P2Pool is located.";
|
||||||
|
|
||||||
// Node/Pool list
|
// Node/Pool list
|
||||||
pub const LIST_ADD: &str = "Add the current values to the list";
|
pub const LIST_ADD: &str = "Add the current values to the list";
|
||||||
pub const LIST_SAVE: &str = "Save the current values to the already existing entry";
|
pub const LIST_SAVE: &str = "Save the current values to the already existing entry";
|
||||||
pub const LIST_DELETE: &str = "Delete the currently selected entry";
|
pub const LIST_DELETE: &str = "Delete the currently selected entry";
|
||||||
pub const LIST_CLEAR: &str = "Clear all current values";
|
pub const LIST_CLEAR: &str = "Clear all current values";
|
||||||
|
|
||||||
// XMRig
|
// XMRig
|
||||||
pub const XMRIG_SIMPLE: &str =
|
pub const XMRIG_SIMPLE: &str = r#"Use simple XMRig settings:
|
||||||
r#"Use simple XMRig settings:
|
|
||||||
- Mine to local P2Pool (localhost:3333)
|
- Mine to local P2Pool (localhost:3333)
|
||||||
- CPU thread slider
|
- CPU thread slider
|
||||||
- HTTP API @ localhost:18088"#;
|
- HTTP API @ localhost:18088"#;
|
||||||
pub const XMRIG_ADVANCED: &str =
|
pub const XMRIG_ADVANCED: &str = r#"Use advanced XMRig settings:
|
||||||
r#"Use advanced XMRig settings:
|
|
||||||
- Terminal input
|
- Terminal input
|
||||||
- Overriding command arguments
|
- Overriding command arguments
|
||||||
- Custom payout address
|
- Custom payout address
|
||||||
|
@ -350,30 +363,31 @@ r#"Use advanced XMRig settings:
|
||||||
- TLS setting
|
- TLS setting
|
||||||
- Keepalive setting"#;
|
- Keepalive setting"#;
|
||||||
pub const XMRIG_INPUT: &str = "Send a command to XMRig";
|
pub const XMRIG_INPUT: &str = "Send a command to XMRig";
|
||||||
pub const XMRIG_ARGUMENTS: &str =
|
pub const XMRIG_ARGUMENTS: &str = r#"WARNING: Use [--no-color] and make sure to set [--http-host <IP>] & [--http-port <PORT>] so that the [Status] tab can work!
|
||||||
r#"WARNING: Use [--no-color] and make sure to set [--http-host <IP>] & [--http-port <PORT>] so that the [Status] tab can work!
|
|
||||||
|
|
||||||
Start XMRig with these arguments and override all below settings"#;
|
Start XMRig with these arguments and override all below settings"#;
|
||||||
pub const XMRIG_ADDRESS: &str = "Specify which Monero address to payout to. This does nothing if mining to P2Pool since the address being paid out to will be the one P2Pool started with. This doubles as a rig identifier for P2Pool and some pools.";
|
pub const XMRIG_ADDRESS: &str = "Specify which Monero address to payout to. This does nothing if mining to P2Pool since the address being paid out to will be the one P2Pool started with. This doubles as a rig identifier for P2Pool and some pools.";
|
||||||
pub const XMRIG_NAME: &str = "Add a unique name to identify this pool; Only [A-Za-z0-9-_.] and spaces allowed; Max length = 30 characters";
|
pub const XMRIG_NAME: &str = "Add a unique name to identify this pool; Only [A-Za-z0-9-_.] and spaces allowed; Max length = 30 characters";
|
||||||
pub const XMRIG_IP: &str = "Specify the pool IP to connect to with XMRig; It must be a valid IPv4 address or a valid domain name; Max length = 255 characters";
|
pub const XMRIG_IP: &str = "Specify the pool IP to connect to with XMRig; It must be a valid IPv4 address or a valid domain name; Max length = 255 characters";
|
||||||
pub const XMRIG_PORT: &str = "Specify the port of the pool; [1-65535]";
|
pub const XMRIG_PORT: &str = "Specify the port of the pool; [1-65535]";
|
||||||
pub const XMRIG_RIG: &str = "Add an optional rig ID. This will be the name shown on the pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters";
|
pub const XMRIG_RIG: &str = "Add an optional rig ID. This will be the name shown on the pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters";
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
pub const XMRIG_PAUSE: &str = "THIS SETTING IS DISABLED IF SET TO [0]. Pause mining if user is active, resume after";
|
pub const XMRIG_PAUSE: &str =
|
||||||
pub const XMRIG_API_IP: &str = "Specify which IP to bind to for XMRig's HTTP API; If empty: [localhost/127.0.0.1]";
|
"THIS SETTING IS DISABLED IF SET TO [0]. Pause mining if user is active, resume after";
|
||||||
pub const XMRIG_API_PORT: &str = "Specify which port to bind to for XMRig's HTTP API; If empty: [18088]";
|
pub const XMRIG_API_IP: &str =
|
||||||
pub const XMRIG_TLS: &str = "Enable SSL/TLS connections (needs pool support)";
|
"Specify which IP to bind to for XMRig's HTTP API; If empty: [localhost/127.0.0.1]";
|
||||||
pub const XMRIG_KEEPALIVE: &str = "Send keepalive packets to prevent timeout (needs pool support)";
|
pub const XMRIG_API_PORT: &str =
|
||||||
pub const XMRIG_THREADS: &str = "Number of CPU threads to use for mining";
|
"Specify which port to bind to for XMRig's HTTP API; If empty: [18088]";
|
||||||
|
pub const XMRIG_TLS: &str = "Enable SSL/TLS connections (needs pool support)";
|
||||||
|
pub const XMRIG_KEEPALIVE: &str = "Send keepalive packets to prevent timeout (needs pool support)";
|
||||||
|
pub const XMRIG_THREADS: &str = "Number of CPU threads to use for mining";
|
||||||
pub const XMRIG_PATH_NOT_FILE: &str = "XMRig binary not found at the given PATH in the Gupax tab! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
pub const XMRIG_PATH_NOT_FILE: &str = "XMRig binary not found at the given PATH in the Gupax tab! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
||||||
pub const XMRIG_PATH_NOT_VALID: &str = "XMRig binary at the given PATH in the Gupax tab doesn't look like XMRig! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
pub const XMRIG_PATH_NOT_VALID: &str = "XMRig binary at the given PATH in the Gupax tab doesn't look like XMRig! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
||||||
pub const XMRIG_PATH_OK: &str = "XMRig was found at the given PATH";
|
pub const XMRIG_PATH_OK: &str = "XMRig was found at the given PATH";
|
||||||
pub const XMRIG_PATH_EMPTY: &str = "XMRig PATH is empty! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
pub const XMRIG_PATH_EMPTY: &str = "XMRig PATH is empty! To fix: goto the [Gupax Advanced] tab, select [Open] and specify where XMRig is located.";
|
||||||
|
|
||||||
// CLI argument messages
|
// CLI argument messages
|
||||||
pub const ARG_HELP: &str =
|
pub const ARG_HELP: &str = r#"USAGE: ./gupax [--flag]
|
||||||
r#"USAGE: ./gupax [--flag]
|
|
||||||
|
|
||||||
--help Print this help message
|
--help Print this help message
|
||||||
--version Print version and build info
|
--version Print version and build info
|
||||||
|
@ -390,29 +404,16 @@ r#"USAGE: ./gupax [--flag]
|
||||||
To view more detailed console debug information, start Gupax with
|
To view more detailed console debug information, start Gupax with
|
||||||
the environment variable [RUST_LOG] set to a log level like so:
|
the environment variable [RUST_LOG] set to a log level like so:
|
||||||
RUST_LOG=(trace|debug|info|warn|error) ./gupax"#;
|
RUST_LOG=(trace|debug|info|warn|error) ./gupax"#;
|
||||||
pub const ARG_COPYRIGHT: &str =
|
pub const ARG_COPYRIGHT: &str = r#"Gupax is licensed under GPLv3.
|
||||||
r#"Gupax is licensed under GPLv3.
|
|
||||||
For more information, see link below:
|
For more information, see link below:
|
||||||
<https://github.com/hinto-janai/gupax>"#;
|
<https://github.com/hinto-janai/gupax>"#;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Visuals
|
//---------------------------------------------------------------------------------------------------- Visuals
|
||||||
use egui::epaint::{
|
use egui::epaint::{Rounding, Shadow, Stroke};
|
||||||
Rounding,
|
|
||||||
Shadow,
|
|
||||||
Stroke
|
|
||||||
};
|
|
||||||
|
|
||||||
use egui::{
|
use egui::{style::Spacing, Color32, Visuals};
|
||||||
Color32,
|
|
||||||
Visuals,
|
|
||||||
style::Spacing,
|
|
||||||
};
|
|
||||||
|
|
||||||
use egui::style::{
|
use egui::style::{Selection, WidgetVisuals, Widgets};
|
||||||
Selection,
|
|
||||||
Widgets,
|
|
||||||
WidgetVisuals,
|
|
||||||
};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
pub const ACCENT_COLOR: Color32 = Color32::from_rgb(200, 100, 100);
|
pub const ACCENT_COLOR: Color32 = Color32::from_rgb(200, 100, 100);
|
||||||
|
@ -420,89 +421,98 @@ pub const BG: Color32 = Color32::from_gray(20);
|
||||||
|
|
||||||
// This is based off [`Visuals::dark()`].
|
// This is based off [`Visuals::dark()`].
|
||||||
pub static VISUALS: Lazy<Visuals> = Lazy::new(|| {
|
pub static VISUALS: Lazy<Visuals> = Lazy::new(|| {
|
||||||
let selection = Selection {
|
let selection = Selection {
|
||||||
bg_fill: ACCENT_COLOR,
|
bg_fill: ACCENT_COLOR,
|
||||||
stroke: Stroke::new(1.0, Color32::from_gray(255)),
|
stroke: Stroke::new(1.0, Color32::from_gray(255)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Based off default dark() mode.
|
// Based off default dark() mode.
|
||||||
// https://docs.rs/egui/0.24.1/src/egui/style.rs.html#1210
|
// https://docs.rs/egui/0.24.1/src/egui/style.rs.html#1210
|
||||||
let widgets = Widgets {
|
let widgets = Widgets {
|
||||||
noninteractive: WidgetVisuals {
|
noninteractive: WidgetVisuals {
|
||||||
bg_fill: BG,
|
bg_fill: BG,
|
||||||
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines
|
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines
|
||||||
fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color
|
fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color
|
||||||
rounding: Rounding::same(10.0),
|
rounding: Rounding::same(10.0),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
weak_bg_fill: BG,
|
weak_bg_fill: BG,
|
||||||
},
|
},
|
||||||
inactive: WidgetVisuals {
|
inactive: WidgetVisuals {
|
||||||
bg_fill: Color32::from_gray(50),
|
bg_fill: Color32::from_gray(50),
|
||||||
bg_stroke: Default::default(),
|
bg_stroke: Default::default(),
|
||||||
fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text
|
fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text
|
||||||
rounding: Rounding::same(10.0),
|
rounding: Rounding::same(10.0),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
weak_bg_fill: Color32::from_gray(50),
|
weak_bg_fill: Color32::from_gray(50),
|
||||||
},
|
},
|
||||||
hovered: WidgetVisuals {
|
hovered: WidgetVisuals {
|
||||||
bg_fill: Color32::from_gray(80),
|
bg_fill: Color32::from_gray(80),
|
||||||
bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button
|
bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button
|
||||||
fg_stroke: Stroke::new(1.5, Color32::from_gray(240)),
|
fg_stroke: Stroke::new(1.5, Color32::from_gray(240)),
|
||||||
rounding: Rounding::same(10.0),
|
rounding: Rounding::same(10.0),
|
||||||
expansion: 1.0,
|
expansion: 1.0,
|
||||||
weak_bg_fill: Color32::from_gray(80),
|
weak_bg_fill: Color32::from_gray(80),
|
||||||
},
|
},
|
||||||
active: WidgetVisuals {
|
active: WidgetVisuals {
|
||||||
bg_fill: Color32::from_gray(55),
|
bg_fill: Color32::from_gray(55),
|
||||||
bg_stroke: Stroke::new(1.0, Color32::WHITE),
|
bg_stroke: Stroke::new(1.0, Color32::WHITE),
|
||||||
fg_stroke: Stroke::new(2.0, Color32::WHITE),
|
fg_stroke: Stroke::new(2.0, Color32::WHITE),
|
||||||
rounding: Rounding::same(10.0),
|
rounding: Rounding::same(10.0),
|
||||||
expansion: 1.0,
|
expansion: 1.0,
|
||||||
weak_bg_fill: Color32::from_gray(120),
|
weak_bg_fill: Color32::from_gray(120),
|
||||||
},
|
},
|
||||||
open: WidgetVisuals {
|
open: WidgetVisuals {
|
||||||
bg_fill: Color32::from_gray(27),
|
bg_fill: Color32::from_gray(27),
|
||||||
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
|
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
|
||||||
fg_stroke: Stroke::new(1.0, Color32::from_gray(210)),
|
fg_stroke: Stroke::new(1.0, Color32::from_gray(210)),
|
||||||
rounding: Rounding::same(10.0),
|
rounding: Rounding::same(10.0),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
weak_bg_fill: Color32::from_gray(120),
|
weak_bg_fill: Color32::from_gray(120),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://docs.rs/egui/0.24.1/src/egui/style.rs.html#1113
|
// https://docs.rs/egui/0.24.1/src/egui/style.rs.html#1113
|
||||||
Visuals {
|
Visuals {
|
||||||
widgets,
|
widgets,
|
||||||
selection,
|
selection,
|
||||||
hyperlink_color: Color32::from_rgb(90, 170, 255),
|
hyperlink_color: Color32::from_rgb(90, 170, 255),
|
||||||
faint_bg_color: Color32::from_additive_luminance(5), // visible, but barely so
|
faint_bg_color: Color32::from_additive_luminance(5), // visible, but barely so
|
||||||
extreme_bg_color: Color32::from_gray(10), // e.g. TextEdit background
|
extreme_bg_color: Color32::from_gray(10), // e.g. TextEdit background
|
||||||
code_bg_color: Color32::from_gray(64),
|
code_bg_color: Color32::from_gray(64),
|
||||||
warn_fg_color: Color32::from_rgb(255, 143, 0), // orange
|
warn_fg_color: Color32::from_rgb(255, 143, 0), // orange
|
||||||
error_fg_color: Color32::from_rgb(255, 0, 0), // red
|
error_fg_color: Color32::from_rgb(255, 0, 0), // red
|
||||||
window_rounding: Rounding::same(6.0),
|
window_rounding: Rounding::same(6.0),
|
||||||
window_shadow: Shadow::big_dark(),
|
window_shadow: Shadow::big_dark(),
|
||||||
popup_shadow: Shadow::small_dark(),
|
popup_shadow: Shadow::small_dark(),
|
||||||
..Visuals::dark()
|
..Visuals::dark()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TESTS
|
//---------------------------------------------------------------------------------------------------- TESTS
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn gupax_version_is_semver() {
|
fn gupax_version_is_semver() {
|
||||||
assert_eq!(crate::GUPAX_VERSION.len(), 6);
|
assert_eq!(crate::GUPAX_VERSION.len(), 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_app_ratio_is_4_by_3() {
|
fn default_app_ratio_is_4_by_3() {
|
||||||
assert_eq!(format!("{:.3}", crate::APP_MIN_WIDTH/crate::APP_MIN_HEIGHT), "1.333");
|
assert_eq!(
|
||||||
assert_eq!(format!("{:.3}", crate::APP_DEFAULT_WIDTH/crate::APP_DEFAULT_HEIGHT), "1.333");
|
format!("{:.3}", crate::APP_MIN_WIDTH / crate::APP_MIN_HEIGHT),
|
||||||
}
|
"1.333"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
format!(
|
||||||
|
"{:.3}",
|
||||||
|
crate::APP_DEFAULT_WIDTH / crate::APP_DEFAULT_HEIGHT
|
||||||
|
),
|
||||||
|
"1.333"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn git_commit_eq_or_gt_40_chars() {
|
fn git_commit_eq_or_gt_40_chars() {
|
||||||
assert!(crate::COMMIT.len() >= 40);
|
assert!(crate::COMMIT.len() >= 40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2165
src/disk.rs
2165
src/disk.rs
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
12
src/free.rs
12
src/free.rs
|
@ -8,11 +8,11 @@ use crate::constants::*;
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
// Clamp the scaling resolution `f32` to a known good `f32`.
|
// Clamp the scaling resolution `f32` to a known good `f32`.
|
||||||
pub fn clamp_scale(scale: f32) -> f32 {
|
pub fn clamp_scale(scale: f32) -> f32 {
|
||||||
// Make sure it is finite.
|
// Make sure it is finite.
|
||||||
if !scale.is_finite() {
|
if !scale.is_finite() {
|
||||||
return APP_DEFAULT_SCALE;
|
return APP_DEFAULT_SCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp between valid range.
|
// Clamp between valid range.
|
||||||
scale.clamp(APP_MIN_SCALE, APP_MAX_SCALE)
|
scale.clamp(APP_MIN_SCALE, APP_MAX_SCALE)
|
||||||
}
|
}
|
748
src/gupax.rs
748
src/gupax.rs
|
@ -16,299 +16,521 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::State;
|
use crate::State;
|
||||||
|
use crate::{constants::*, macros::*, update::*, ErrorState, Restart, Tab};
|
||||||
use egui::{
|
use egui::{
|
||||||
TextEdit,
|
Button, Checkbox, Label, ProgressBar, RichText, SelectableLabel, Slider, Spinner, TextEdit,
|
||||||
TextStyle,
|
TextStyle, TextStyle::Monospace, Vec2,
|
||||||
TextStyle::Monospace,
|
|
||||||
Checkbox,ProgressBar,Spinner,Button,Label,Slider,
|
|
||||||
SelectableLabel,
|
|
||||||
RichText,
|
|
||||||
Vec2,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
constants::*,
|
|
||||||
update::*,
|
|
||||||
ErrorState,
|
|
||||||
Restart,
|
|
||||||
Tab,
|
|
||||||
macros::*,
|
|
||||||
};
|
|
||||||
use std::{
|
|
||||||
thread,
|
|
||||||
sync::{Arc,Mutex},
|
|
||||||
path::Path,
|
|
||||||
};
|
};
|
||||||
use log::*;
|
use log::*;
|
||||||
use serde::{Serialize,Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{
|
||||||
|
path::Path,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- FileWindow
|
//---------------------------------------------------------------------------------------------------- FileWindow
|
||||||
// Struct for writing/reading the path state.
|
// Struct for writing/reading the path state.
|
||||||
// The opened file picker is started in a new
|
// The opened file picker is started in a new
|
||||||
// thread so main() needs to be in sync.
|
// thread so main() needs to be in sync.
|
||||||
pub struct FileWindow {
|
pub struct FileWindow {
|
||||||
thread: bool, // Is there already a FileWindow thread?
|
thread: bool, // Is there already a FileWindow thread?
|
||||||
picked_p2pool: bool, // Did the user pick a path for p2pool?
|
picked_p2pool: bool, // Did the user pick a path for p2pool?
|
||||||
picked_xmrig: bool, // Did the user pick a path for xmrig?
|
picked_xmrig: bool, // Did the user pick a path for xmrig?
|
||||||
p2pool_path: String, // The picked p2pool path
|
p2pool_path: String, // The picked p2pool path
|
||||||
xmrig_path: String, // The picked p2pool path
|
xmrig_path: String, // The picked p2pool path
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileWindow {
|
impl FileWindow {
|
||||||
pub fn new() -> Arc<Mutex<Self>> {
|
pub fn new() -> Arc<Mutex<Self>> {
|
||||||
arc_mut!(Self {
|
arc_mut!(Self {
|
||||||
thread: false,
|
thread: false,
|
||||||
picked_p2pool: false,
|
picked_p2pool: false,
|
||||||
picked_xmrig: false,
|
picked_xmrig: false,
|
||||||
p2pool_path: String::new(),
|
p2pool_path: String::new(),
|
||||||
xmrig_path: String::new(),
|
xmrig_path: String::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum FileType {
|
pub enum FileType {
|
||||||
P2pool,
|
P2pool,
|
||||||
Xmrig,
|
Xmrig,
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Ratio Lock
|
//---------------------------------------------------------------------------------------------------- Ratio Lock
|
||||||
// Enum for the lock ratio in the advanced tab.
|
// Enum for the lock ratio in the advanced tab.
|
||||||
#[derive(Clone,Copy,Eq,PartialEq,Debug,Deserialize,Serialize)]
|
#[derive(Clone, Copy, Eq, PartialEq, Debug, Deserialize, Serialize)]
|
||||||
pub enum Ratio {
|
pub enum Ratio {
|
||||||
Width,
|
Width,
|
||||||
Height,
|
Height,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Gupax
|
//---------------------------------------------------------------------------------------------------- Gupax
|
||||||
impl crate::disk::Gupax {
|
impl crate::disk::Gupax {
|
||||||
#[inline(always)] // called once
|
#[inline(always)] // called once
|
||||||
pub fn show(
|
pub fn show(
|
||||||
&mut self,
|
&mut self,
|
||||||
og: &Arc<Mutex<State>>,
|
og: &Arc<Mutex<State>>,
|
||||||
state_path: &Path,
|
state_path: &Path,
|
||||||
update: &Arc<Mutex<Update>>,
|
update: &Arc<Mutex<Update>>,
|
||||||
file_window: &Arc<Mutex<FileWindow>>,
|
file_window: &Arc<Mutex<FileWindow>>,
|
||||||
error_state: &mut ErrorState,
|
error_state: &mut ErrorState,
|
||||||
restart: &Arc<Mutex<Restart>>,
|
restart: &Arc<Mutex<Restart>>,
|
||||||
width: f32,
|
width: f32,
|
||||||
height: f32,
|
height: f32,
|
||||||
frame: &mut eframe::Frame,
|
frame: &mut eframe::Frame,
|
||||||
_ctx: &egui::Context,
|
_ctx: &egui::Context,
|
||||||
ui: &mut egui::Ui
|
ui: &mut egui::Ui,
|
||||||
) {
|
) {
|
||||||
// Update button + Progress bar
|
// Update button + Progress bar
|
||||||
debug!("Gupax Tab | Rendering [Update] button + progress bar");
|
debug!("Gupax Tab | Rendering [Update] button + progress bar");
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let button = if self.simple { height/5.0 } else { height/15.0 };
|
let button = if self.simple {
|
||||||
let height = if self.simple { height/5.0 } else { height/10.0 };
|
height / 5.0
|
||||||
let width = width - SPACE;
|
} else {
|
||||||
let updating = *lock2!(update,updating);
|
height / 15.0
|
||||||
ui.vertical(|ui| {
|
};
|
||||||
// If [Gupax] is being built for a Linux distro,
|
let height = if self.simple {
|
||||||
// disable built-in updating completely.
|
height / 5.0
|
||||||
#[cfg(feature = "distro")]
|
} else {
|
||||||
ui.set_enabled(false);
|
height / 10.0
|
||||||
#[cfg(feature = "distro")]
|
};
|
||||||
ui.add_sized([width, button], Button::new("Updates are disabled")).on_disabled_hover_text(DISTRO_NO_UPDATE);
|
let width = width - SPACE;
|
||||||
#[cfg(not(feature = "distro"))]
|
let updating = *lock2!(update, updating);
|
||||||
ui.set_enabled(!updating);
|
ui.vertical(|ui| {
|
||||||
#[cfg(not(feature = "distro"))]
|
// If [Gupax] is being built for a Linux distro,
|
||||||
if ui.add_sized([width, button], Button::new("Check for updates")).on_hover_text(GUPAX_UPDATE).clicked() {
|
// disable built-in updating completely.
|
||||||
Update::spawn_thread(og, self, state_path, update, error_state, restart);
|
#[cfg(feature = "distro")]
|
||||||
}
|
ui.set_enabled(false);
|
||||||
});
|
#[cfg(feature = "distro")]
|
||||||
ui.vertical(|ui| {
|
ui.add_sized([width, button], Button::new("Updates are disabled"))
|
||||||
ui.set_enabled(updating);
|
.on_disabled_hover_text(DISTRO_NO_UPDATE);
|
||||||
let prog = *lock2!(update,prog);
|
#[cfg(not(feature = "distro"))]
|
||||||
let msg = format!("{}\n{}{}", *lock2!(update,msg), prog, "%");
|
ui.set_enabled(!updating);
|
||||||
ui.add_sized([width, height*1.4], Label::new(RichText::new(msg)));
|
#[cfg(not(feature = "distro"))]
|
||||||
let height = height/2.0;
|
if ui
|
||||||
if updating {
|
.add_sized([width, button], Button::new("Check for updates"))
|
||||||
ui.add_sized([width, height], Spinner::new().size(height));
|
.on_hover_text(GUPAX_UPDATE)
|
||||||
} else {
|
.clicked()
|
||||||
ui.add_sized([width, height], Label::new("..."));
|
{
|
||||||
}
|
Update::spawn_thread(og, self, state_path, update, error_state, restart);
|
||||||
ui.add_sized([width, height], ProgressBar::new(lock2!(update,prog).round() / 100.0));
|
}
|
||||||
});
|
});
|
||||||
});
|
ui.vertical(|ui| {
|
||||||
|
ui.set_enabled(updating);
|
||||||
|
let prog = *lock2!(update, prog);
|
||||||
|
let msg = format!("{}\n{}{}", *lock2!(update, msg), prog, "%");
|
||||||
|
ui.add_sized([width, height * 1.4], Label::new(RichText::new(msg)));
|
||||||
|
let height = height / 2.0;
|
||||||
|
if updating {
|
||||||
|
ui.add_sized([width, height], Spinner::new().size(height));
|
||||||
|
} else {
|
||||||
|
ui.add_sized([width, height], Label::new("..."));
|
||||||
|
}
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
ProgressBar::new(lock2!(update, prog).round() / 100.0),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
debug!("Gupax Tab | Rendering bool buttons");
|
debug!("Gupax Tab | Rendering bool buttons");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = (width - SPACE*12.0)/6.0;
|
let width = (width - SPACE * 12.0) / 6.0;
|
||||||
let height = if self.simple { height/10.0 } else { height/15.0 };
|
let height = if self.simple {
|
||||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Small);
|
height / 10.0
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.update_via_tor, "Update via Tor")).on_hover_text(GUPAX_UPDATE_VIA_TOR);
|
} else {
|
||||||
ui.separator();
|
height / 15.0
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_update, "Auto-Update")).on_hover_text(GUPAX_AUTO_UPDATE);
|
};
|
||||||
ui.separator();
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Small);
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_p2pool, "Auto-P2Pool")).on_hover_text(GUPAX_AUTO_P2POOL);
|
ui.add_sized(
|
||||||
ui.separator();
|
[width, height],
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_xmrig, "Auto-XMRig")).on_hover_text(GUPAX_AUTO_XMRIG);
|
Checkbox::new(&mut self.update_via_tor, "Update via Tor"),
|
||||||
ui.separator();
|
)
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.ask_before_quit, "Ask before quit")).on_hover_text(GUPAX_ASK_BEFORE_QUIT);
|
.on_hover_text(GUPAX_UPDATE_VIA_TOR);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.save_before_quit, "Save before quit")).on_hover_text(GUPAX_SAVE_BEFORE_QUIT);
|
ui.add_sized(
|
||||||
});
|
[width, height],
|
||||||
});
|
Checkbox::new(&mut self.auto_update, "Auto-Update"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_AUTO_UPDATE);
|
||||||
|
ui.separator();
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Checkbox::new(&mut self.auto_p2pool, "Auto-P2Pool"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_AUTO_P2POOL);
|
||||||
|
ui.separator();
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Checkbox::new(&mut self.auto_xmrig, "Auto-XMRig"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_AUTO_XMRIG);
|
||||||
|
ui.separator();
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Checkbox::new(&mut self.ask_before_quit, "Ask before quit"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_ASK_BEFORE_QUIT);
|
||||||
|
ui.separator();
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Checkbox::new(&mut self.save_before_quit, "Save before quit"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_SAVE_BEFORE_QUIT);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if self.simple { return }
|
if self.simple {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
debug!("Gupax Tab | Rendering P2Pool/XMRig path selection");
|
debug!("Gupax Tab | Rendering P2Pool/XMRig path selection");
|
||||||
// P2Pool/XMRig binary path selection
|
// P2Pool/XMRig binary path selection
|
||||||
let height = height/28.0;
|
let height = height / 28.0;
|
||||||
let text_edit = (ui.available_width()/10.0)-SPACE;
|
let text_edit = (ui.available_width() / 10.0) - SPACE;
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.add_sized([ui.available_width(), height/2.0], Label::new(RichText::new("P2Pool/XMRig PATHs").underline().color(LIGHT_GRAY))).on_hover_text("Gupax is online");
|
ui.add_sized(
|
||||||
ui.separator();
|
[ui.available_width(), height / 2.0],
|
||||||
ui.horizontal(|ui| {
|
Label::new(
|
||||||
if self.p2pool_path.is_empty() {
|
RichText::new("P2Pool/XMRig PATHs")
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ➖").color(LIGHT_GRAY))).on_hover_text(P2POOL_PATH_EMPTY);
|
.underline()
|
||||||
} else if !Self::path_is_file(&self.p2pool_path) {
|
.color(LIGHT_GRAY),
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_FILE);
|
),
|
||||||
} else if !crate::update::check_p2pool_path(&self.p2pool_path) {
|
)
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ❌").color(RED))).on_hover_text(P2POOL_PATH_NOT_VALID);
|
.on_hover_text("Gupax is online");
|
||||||
} else {
|
ui.separator();
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new("P2Pool Binary Path ✔").color(GREEN))).on_hover_text(P2POOL_PATH_OK);
|
ui.horizontal(|ui| {
|
||||||
}
|
if self.p2pool_path.is_empty() {
|
||||||
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
|
ui.add_sized(
|
||||||
ui.set_enabled(!lock!(file_window).thread);
|
[text_edit, height],
|
||||||
if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() {
|
Label::new(RichText::new("P2Pool Binary Path ➖").color(LIGHT_GRAY)),
|
||||||
Self::spawn_file_window_thread(file_window, FileType::P2pool);
|
)
|
||||||
}
|
.on_hover_text(P2POOL_PATH_EMPTY);
|
||||||
ui.add_sized([ui.available_width(), height], TextEdit::singleline(&mut self.p2pool_path)).on_hover_text(GUPAX_PATH_P2POOL);
|
} else if !Self::path_is_file(&self.p2pool_path) {
|
||||||
});
|
ui.add_sized(
|
||||||
ui.horizontal(|ui| {
|
[text_edit, height],
|
||||||
if self.xmrig_path.is_empty() {
|
Label::new(RichText::new("P2Pool Binary Path ❌").color(RED)),
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ➖").color(LIGHT_GRAY))).on_hover_text(XMRIG_PATH_EMPTY);
|
)
|
||||||
} else if !Self::path_is_file(&self.xmrig_path) {
|
.on_hover_text(P2POOL_PATH_NOT_FILE);
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_FILE);
|
} else if !crate::update::check_p2pool_path(&self.p2pool_path) {
|
||||||
} else if !crate::update::check_xmrig_path(&self.xmrig_path) {
|
ui.add_sized(
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))).on_hover_text(XMRIG_PATH_NOT_VALID);
|
[text_edit, height],
|
||||||
} else {
|
Label::new(RichText::new("P2Pool Binary Path ❌").color(RED)),
|
||||||
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN))).on_hover_text(XMRIG_PATH_OK);
|
)
|
||||||
}
|
.on_hover_text(P2POOL_PATH_NOT_VALID);
|
||||||
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
|
} else {
|
||||||
ui.set_enabled(!lock!(file_window).thread);
|
ui.add_sized(
|
||||||
if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() {
|
[text_edit, height],
|
||||||
Self::spawn_file_window_thread(file_window, FileType::Xmrig);
|
Label::new(RichText::new("P2Pool Binary Path ✔").color(GREEN)),
|
||||||
}
|
)
|
||||||
ui.add_sized([ui.available_width(), height], TextEdit::singleline(&mut self.xmrig_path)).on_hover_text(GUPAX_PATH_XMRIG);
|
.on_hover_text(P2POOL_PATH_OK);
|
||||||
});
|
}
|
||||||
});
|
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
|
||||||
let mut guard = lock!(file_window);
|
ui.set_enabled(!lock!(file_window).thread);
|
||||||
if guard.picked_p2pool { self.p2pool_path = guard.p2pool_path.clone(); guard.picked_p2pool = false; }
|
if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() {
|
||||||
if guard.picked_xmrig { self.xmrig_path = guard.xmrig_path.clone(); guard.picked_xmrig = false; }
|
Self::spawn_file_window_thread(file_window, FileType::P2pool);
|
||||||
drop(guard);
|
}
|
||||||
|
ui.add_sized(
|
||||||
|
[ui.available_width(), height],
|
||||||
|
TextEdit::singleline(&mut self.p2pool_path),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_PATH_P2POOL);
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if self.xmrig_path.is_empty() {
|
||||||
|
ui.add_sized(
|
||||||
|
[text_edit, height],
|
||||||
|
Label::new(RichText::new(" XMRig Binary Path ➖").color(LIGHT_GRAY)),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_PATH_EMPTY);
|
||||||
|
} else if !Self::path_is_file(&self.xmrig_path) {
|
||||||
|
ui.add_sized(
|
||||||
|
[text_edit, height],
|
||||||
|
Label::new(RichText::new(" XMRig Binary Path ❌").color(RED)),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_PATH_NOT_FILE);
|
||||||
|
} else if !crate::update::check_xmrig_path(&self.xmrig_path) {
|
||||||
|
ui.add_sized(
|
||||||
|
[text_edit, height],
|
||||||
|
Label::new(RichText::new(" XMRig Binary Path ❌").color(RED)),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_PATH_NOT_VALID);
|
||||||
|
} else {
|
||||||
|
ui.add_sized(
|
||||||
|
[text_edit, height],
|
||||||
|
Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN)),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_PATH_OK);
|
||||||
|
}
|
||||||
|
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
|
||||||
|
ui.set_enabled(!lock!(file_window).thread);
|
||||||
|
if ui.button("Open").on_hover_text(GUPAX_SELECT).clicked() {
|
||||||
|
Self::spawn_file_window_thread(file_window, FileType::Xmrig);
|
||||||
|
}
|
||||||
|
ui.add_sized(
|
||||||
|
[ui.available_width(), height],
|
||||||
|
TextEdit::singleline(&mut self.xmrig_path),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_PATH_XMRIG);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let mut guard = lock!(file_window);
|
||||||
|
if guard.picked_p2pool {
|
||||||
|
self.p2pool_path = guard.p2pool_path.clone();
|
||||||
|
guard.picked_p2pool = false;
|
||||||
|
}
|
||||||
|
if guard.picked_xmrig {
|
||||||
|
self.xmrig_path = guard.xmrig_path.clone();
|
||||||
|
guard.picked_xmrig = false;
|
||||||
|
}
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
let height = ui.available_height()/6.0;
|
let height = ui.available_height() / 6.0;
|
||||||
|
|
||||||
// Saved [Tab]
|
// Saved [Tab]
|
||||||
debug!("Gupax Tab | Rendering [Tab] selector");
|
debug!("Gupax Tab | Rendering [Tab] selector");
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = (width/5.0)-(SPACE*1.93);
|
let width = (width / 5.0) - (SPACE * 1.93);
|
||||||
ui.add_sized([ui.available_width(), height/2.0], Label::new(RichText::new("Default Tab").underline().color(LIGHT_GRAY))).on_hover_text(GUPAX_TAB);
|
ui.add_sized(
|
||||||
ui.separator();
|
[ui.available_width(), height / 2.0],
|
||||||
ui.horizontal(|ui| {
|
Label::new(RichText::new("Default Tab").underline().color(LIGHT_GRAY)),
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::About, "About")).on_hover_text(GUPAX_TAB_ABOUT).clicked() { self.tab = Tab::About; }
|
)
|
||||||
ui.separator();
|
.on_hover_text(GUPAX_TAB);
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::Status, "Status")).on_hover_text(GUPAX_TAB_STATUS).clicked() { self.tab = Tab::Status; }
|
ui.separator();
|
||||||
ui.separator();
|
ui.horizontal(|ui| {
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::Gupax, "Gupax")).on_hover_text(GUPAX_TAB_GUPAX).clicked() { self.tab = Tab::Gupax; }
|
if ui
|
||||||
ui.separator();
|
.add_sized(
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::P2pool, "P2Pool")).on_hover_text(GUPAX_TAB_P2POOL).clicked() { self.tab = Tab::P2pool; }
|
[width, height],
|
||||||
ui.separator();
|
SelectableLabel::new(self.tab == Tab::About, "About"),
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.tab == Tab::Xmrig, "XMRig")).on_hover_text(GUPAX_TAB_XMRIG).clicked() { self.tab = Tab::Xmrig; }
|
)
|
||||||
})});
|
.on_hover_text(GUPAX_TAB_ABOUT)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.tab = Tab::About;
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.tab == Tab::Status, "Status"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_TAB_STATUS)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.tab = Tab::Status;
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.tab == Tab::Gupax, "Gupax"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_TAB_GUPAX)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.tab = Tab::Gupax;
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.tab == Tab::P2pool, "P2Pool"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_TAB_P2POOL)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.tab = Tab::P2pool;
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.tab == Tab::Xmrig, "XMRig"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_TAB_XMRIG)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.tab = Tab::Xmrig;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
// Gupax App resolution sliders
|
// Gupax App resolution sliders
|
||||||
debug!("Gupax Tab | Rendering resolution sliders");
|
debug!("Gupax Tab | Rendering resolution sliders");
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.add_sized([ui.available_width(), height/2.0], Label::new(RichText::new("Width/Height Adjust").underline().color(LIGHT_GRAY))).on_hover_text(GUPAX_ADJUST);
|
ui.add_sized(
|
||||||
ui.separator();
|
[ui.available_width(), height / 2.0],
|
||||||
ui.vertical(|ui| {
|
Label::new(
|
||||||
let width = width/10.0;
|
RichText::new("Width/Height Adjust")
|
||||||
ui.spacing_mut().icon_width = width / 25.0;
|
.underline()
|
||||||
ui.spacing_mut().slider_width = width*7.6;
|
.color(LIGHT_GRAY),
|
||||||
match self.ratio {
|
),
|
||||||
Ratio::None => (),
|
)
|
||||||
Ratio::Width => {
|
.on_hover_text(GUPAX_ADJUST);
|
||||||
let width = self.selected_width as f64;
|
ui.separator();
|
||||||
let height = (width / 1.333).round();
|
ui.vertical(|ui| {
|
||||||
self.selected_height = height as u16;
|
let width = width / 10.0;
|
||||||
},
|
ui.spacing_mut().icon_width = width / 25.0;
|
||||||
Ratio::Height => {
|
ui.spacing_mut().slider_width = width * 7.6;
|
||||||
let height = self.selected_height as f64;
|
match self.ratio {
|
||||||
let width = (height * 1.333).round();
|
Ratio::None => (),
|
||||||
self.selected_width = width as u16;
|
Ratio::Width => {
|
||||||
},
|
let width = self.selected_width as f64;
|
||||||
}
|
let height = (width / 1.333).round();
|
||||||
let height = height/3.5;
|
self.selected_height = height as u16;
|
||||||
ui.horizontal(|ui| {
|
}
|
||||||
ui.set_enabled(self.ratio != Ratio::Height);
|
Ratio::Height => {
|
||||||
ui.add_sized([width, height], Label::new(format!(" Width [{}-{}]:", APP_MIN_WIDTH as u16, APP_MAX_WIDTH as u16)));
|
let height = self.selected_height as f64;
|
||||||
ui.add_sized([width, height], Slider::new(&mut self.selected_width, APP_MIN_WIDTH as u16..=APP_MAX_WIDTH as u16)).on_hover_text(GUPAX_WIDTH);
|
let width = (height * 1.333).round();
|
||||||
});
|
self.selected_width = width as u16;
|
||||||
ui.horizontal(|ui| {
|
}
|
||||||
ui.set_enabled(self.ratio != Ratio::Width);
|
}
|
||||||
ui.add_sized([width, height], Label::new(format!("Height [{}-{}]:", APP_MIN_HEIGHT as u16, APP_MAX_HEIGHT as u16)));
|
let height = height / 3.5;
|
||||||
ui.add_sized([width, height], Slider::new(&mut self.selected_height, APP_MIN_HEIGHT as u16..=APP_MAX_HEIGHT as u16)).on_hover_text(GUPAX_HEIGHT);
|
ui.horizontal(|ui| {
|
||||||
});
|
ui.set_enabled(self.ratio != Ratio::Height);
|
||||||
ui.horizontal(|ui| {
|
ui.add_sized(
|
||||||
ui.add_sized([width, height], Label::new(format!("Scaling [{APP_MIN_SCALE}..{APP_MAX_SCALE}]:")));
|
[width, height],
|
||||||
ui.add_sized([width, height], Slider::new(&mut self.selected_scale, APP_MIN_SCALE..=APP_MAX_SCALE).step_by(0.1)).on_hover_text(GUPAX_SCALE);
|
Label::new(format!(
|
||||||
});
|
" Width [{}-{}]:",
|
||||||
});
|
APP_MIN_WIDTH as u16, APP_MAX_WIDTH as u16
|
||||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Button);
|
)),
|
||||||
ui.separator();
|
);
|
||||||
// Width/Height locks
|
ui.add_sized(
|
||||||
ui.horizontal(|ui| {
|
[width, height],
|
||||||
use Ratio::*;
|
Slider::new(
|
||||||
let width = (width/4.0)-(SPACE*1.5);
|
&mut self.selected_width,
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.ratio == Width, "Lock to width")).on_hover_text(GUPAX_LOCK_WIDTH).clicked() { self.ratio = Width; }
|
APP_MIN_WIDTH as u16..=APP_MAX_WIDTH as u16,
|
||||||
ui.separator();
|
),
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.ratio == Height, "Lock to height")).on_hover_text(GUPAX_LOCK_HEIGHT).clicked() { self.ratio = Height; }
|
)
|
||||||
ui.separator();
|
.on_hover_text(GUPAX_WIDTH);
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.ratio == None, "No lock")).on_hover_text(GUPAX_NO_LOCK).clicked() { self.ratio = None; }
|
});
|
||||||
if ui.add_sized([width, height], Button::new("Set")).on_hover_text(GUPAX_SET).clicked() {
|
ui.horizontal(|ui| {
|
||||||
let size = Vec2::new(self.selected_width as f32, self.selected_height as f32);
|
ui.set_enabled(self.ratio != Ratio::Width);
|
||||||
ui.ctx().send_viewport_cmd(egui::viewport::ViewportCommand::InnerSize(size));
|
ui.add_sized(
|
||||||
}
|
[width, height],
|
||||||
})});
|
Label::new(format!(
|
||||||
}
|
"Height [{}-{}]:",
|
||||||
|
APP_MIN_HEIGHT as u16, APP_MAX_HEIGHT as u16
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Slider::new(
|
||||||
|
&mut self.selected_height,
|
||||||
|
APP_MIN_HEIGHT as u16..=APP_MAX_HEIGHT as u16,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_HEIGHT);
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Label::new(format!("Scaling [{APP_MIN_SCALE}..{APP_MAX_SCALE}]:")),
|
||||||
|
);
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Slider::new(&mut self.selected_scale, APP_MIN_SCALE..=APP_MAX_SCALE)
|
||||||
|
.step_by(0.1),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_SCALE);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.style_mut().override_text_style = Some(egui::TextStyle::Button);
|
||||||
|
ui.separator();
|
||||||
|
// Width/Height locks
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
use Ratio::*;
|
||||||
|
let width = (width / 4.0) - (SPACE * 1.5);
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.ratio == Width, "Lock to width"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_LOCK_WIDTH)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.ratio = Width;
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.ratio == Height, "Lock to height"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_LOCK_HEIGHT)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.ratio = Height;
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if ui
|
||||||
|
.add_sized(
|
||||||
|
[width, height],
|
||||||
|
SelectableLabel::new(self.ratio == None, "No lock"),
|
||||||
|
)
|
||||||
|
.on_hover_text(GUPAX_NO_LOCK)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.ratio = None;
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.add_sized([width, height], Button::new("Set"))
|
||||||
|
.on_hover_text(GUPAX_SET)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
let size = Vec2::new(self.selected_width as f32, self.selected_height as f32);
|
||||||
|
ui.ctx()
|
||||||
|
.send_viewport_cmd(egui::viewport::ViewportCommand::InnerSize(size));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if a path is a valid path to a file.
|
// Checks if a path is a valid path to a file.
|
||||||
pub fn path_is_file(path: &str) -> bool {
|
pub fn path_is_file(path: &str) -> bool {
|
||||||
let path = path.to_string();
|
let path = path.to_string();
|
||||||
match crate::disk::into_absolute_path(path) {
|
match crate::disk::into_absolute_path(path) {
|
||||||
Ok(path) => path.is_file(),
|
Ok(path) => path.is_file(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn spawn_file_window_thread(file_window: &Arc<Mutex<FileWindow>>, file_type: FileType) {
|
fn spawn_file_window_thread(file_window: &Arc<Mutex<FileWindow>>, file_type: FileType) {
|
||||||
use FileType::*;
|
use FileType::*;
|
||||||
let name = match file_type {
|
let name = match file_type {
|
||||||
P2pool => "P2Pool",
|
P2pool => "P2Pool",
|
||||||
Xmrig => "XMRig",
|
Xmrig => "XMRig",
|
||||||
};
|
};
|
||||||
let file_window = file_window.clone();
|
let file_window = file_window.clone();
|
||||||
lock!(file_window).thread = true;
|
lock!(file_window).thread = true;
|
||||||
thread::spawn(move|| {
|
thread::spawn(move || {
|
||||||
match rfd::FileDialog::new().set_title(&format!("Select {} Binary for Gupax", name)).pick_file() {
|
match rfd::FileDialog::new()
|
||||||
Some(path) => {
|
.set_title(&format!("Select {} Binary for Gupax", name))
|
||||||
info!("Gupax | Path selected for {} ... {}", name, path.display());
|
.pick_file()
|
||||||
match file_type {
|
{
|
||||||
P2pool => { lock!(file_window).p2pool_path = path.display().to_string(); lock!(file_window).picked_p2pool = true; },
|
Some(path) => {
|
||||||
Xmrig => { lock!(file_window).xmrig_path = path.display().to_string(); lock!(file_window).picked_xmrig = true; },
|
info!("Gupax | Path selected for {} ... {}", name, path.display());
|
||||||
};
|
match file_type {
|
||||||
},
|
P2pool => {
|
||||||
None => info!("Gupax | No path selected for {}", name),
|
lock!(file_window).p2pool_path = path.display().to_string();
|
||||||
};
|
lock!(file_window).picked_p2pool = true;
|
||||||
lock!(file_window).thread = false;
|
}
|
||||||
});
|
Xmrig => {
|
||||||
}
|
lock!(file_window).xmrig_path = path.display().to_string();
|
||||||
|
lock!(file_window).picked_xmrig = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
None => info!("Gupax | No path selected for {}", name),
|
||||||
|
};
|
||||||
|
lock!(file_window).thread = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
4372
src/helper.rs
4372
src/helper.rs
File diff suppressed because it is too large
Load diff
632
src/human.rs
632
src/human.rs
|
@ -30,69 +30,74 @@ use std::time::Duration;
|
||||||
pub struct HumanTime(Duration);
|
pub struct HumanTime(Duration);
|
||||||
|
|
||||||
impl Default for HumanTime {
|
impl Default for HumanTime {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HumanTime {
|
impl HumanTime {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn new() -> HumanTime {
|
pub const fn new() -> HumanTime {
|
||||||
HumanTime(ZERO_SECONDS)
|
HumanTime(ZERO_SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn into_human(d: Duration) -> HumanTime {
|
pub const fn into_human(d: Duration) -> HumanTime {
|
||||||
HumanTime(d)
|
HumanTime(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_u64(u: u64) -> HumanTime {
|
pub const fn from_u64(u: u64) -> HumanTime {
|
||||||
HumanTime(Duration::from_secs(u))
|
HumanTime(Duration::from_secs(u))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn plural(f: &mut std::fmt::Formatter, started: &mut bool, name: &str, value: u64) -> std::fmt::Result {
|
fn plural(
|
||||||
if value > 0 {
|
f: &mut std::fmt::Formatter,
|
||||||
if *started {
|
started: &mut bool,
|
||||||
f.write_str(", ")?;
|
name: &str,
|
||||||
}
|
value: u64,
|
||||||
write!(f, "{} {}", value, name)?;
|
) -> std::fmt::Result {
|
||||||
if value > 1 {
|
if value > 0 {
|
||||||
f.write_str("s")?;
|
if *started {
|
||||||
}
|
f.write_str(", ")?;
|
||||||
*started = true;
|
}
|
||||||
}
|
write!(f, "{} {}", value, name)?;
|
||||||
Ok(())
|
if value > 1 {
|
||||||
}
|
f.write_str("s")?;
|
||||||
|
}
|
||||||
|
*started = true;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for HumanTime {
|
impl std::fmt::Display for HumanTime {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
let secs = self.0.as_secs();
|
let secs = self.0.as_secs();
|
||||||
if secs == 0 {
|
if secs == 0 {
|
||||||
f.write_str("0 seconds")?;
|
f.write_str("0 seconds")?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let years = secs / 31_557_600; // 365.25d
|
let years = secs / 31_557_600; // 365.25d
|
||||||
let ydays = secs % 31_557_600;
|
let ydays = secs % 31_557_600;
|
||||||
let months = ydays / 2_630_016; // 30.44d
|
let months = ydays / 2_630_016; // 30.44d
|
||||||
let mdays = ydays % 2_630_016;
|
let mdays = ydays % 2_630_016;
|
||||||
let days = mdays / 86400;
|
let days = mdays / 86400;
|
||||||
let day_secs = mdays % 86400;
|
let day_secs = mdays % 86400;
|
||||||
let hours = day_secs / 3600;
|
let hours = day_secs / 3600;
|
||||||
let minutes = day_secs % 3600 / 60;
|
let minutes = day_secs % 3600 / 60;
|
||||||
let seconds = day_secs % 60;
|
let seconds = day_secs % 60;
|
||||||
|
|
||||||
let started = &mut false;
|
let started = &mut false;
|
||||||
Self::plural(f, started, "year", years)?;
|
Self::plural(f, started, "year", years)?;
|
||||||
Self::plural(f, started, "month", months)?;
|
Self::plural(f, started, "month", months)?;
|
||||||
Self::plural(f, started, "day", days)?;
|
Self::plural(f, started, "day", days)?;
|
||||||
Self::plural(f, started, "hour", hours)?;
|
Self::plural(f, started, "hour", hours)?;
|
||||||
Self::plural(f, started, "minute", minutes)?;
|
Self::plural(f, started, "minute", minutes)?;
|
||||||
Self::plural(f, started, "second", seconds)?;
|
Self::plural(f, started, "second", seconds)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- [HumanNumber]
|
//---------------------------------------------------------------------------------------------------- [HumanNumber]
|
||||||
|
@ -107,249 +112,304 @@ impl std::fmt::Display for HumanTime {
|
||||||
pub struct HumanNumber(String);
|
pub struct HumanNumber(String);
|
||||||
|
|
||||||
impl std::fmt::Display for HumanNumber {
|
impl std::fmt::Display for HumanNumber {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(f, "{}", &self.0)
|
write!(f, "{}", &self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HumanNumber {
|
impl HumanNumber {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unknown() -> Self {
|
pub fn unknown() -> Self {
|
||||||
Self("???".to_string())
|
Self("???".to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_str(s: &str) -> Self {
|
pub fn from_str(s: &str) -> Self {
|
||||||
Self(s.to_string())
|
Self(s.to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_hashrate(f: f32) -> Self {
|
pub fn to_hashrate(f: f32) -> Self {
|
||||||
Self(format!("{} H/s", Self::from_f32(f)))
|
Self(format!("{} H/s", Self::from_f32(f)))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_percent(f: f32) -> Self {
|
pub fn to_percent(f: f32) -> Self {
|
||||||
if f < 0.01 {
|
if f < 0.01 {
|
||||||
Self("0%".to_string())
|
Self("0%".to_string())
|
||||||
} else {
|
} else {
|
||||||
Self(format!("{:.2}%", f))
|
Self(format!("{:.2}%", f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_percent_3_point(f: f32) -> Self {
|
pub fn to_percent_3_point(f: f32) -> Self {
|
||||||
Self(format!("{:.3}%", f))
|
Self(format!("{:.3}%", f))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_percent_no_fmt(f: f32) -> Self {
|
pub fn to_percent_no_fmt(f: f32) -> Self {
|
||||||
Self(format!("{}%", f))
|
Self(format!("{}%", f))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64_to_percent_3_point(f: f64) -> Self {
|
pub fn from_f64_to_percent_3_point(f: f64) -> Self {
|
||||||
Self(format!("{:.3}%", f))
|
Self(format!("{:.3}%", f))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64_to_percent_6_point(f: f64) -> Self {
|
pub fn from_f64_to_percent_6_point(f: f64) -> Self {
|
||||||
Self(format!("{:.6}%", f))
|
Self(format!("{:.6}%", f))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64_to_percent_9_point(f: f64) -> Self {
|
pub fn from_f64_to_percent_9_point(f: f64) -> Self {
|
||||||
Self(format!("{:.9}%", f))
|
Self(format!("{:.9}%", f))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64_to_percent_no_fmt(f: f64) -> Self {
|
pub fn from_f64_to_percent_no_fmt(f: f64) -> Self {
|
||||||
Self(format!("{}%", f))
|
Self(format!("{}%", f))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f32(f: f32) -> Self {
|
pub fn from_f32(f: f32) -> Self {
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
buf.write_formatted(&(f as u64), &LOCALE);
|
buf.write_formatted(&(f as u64), &LOCALE);
|
||||||
Self(buf.as_str().to_string())
|
Self(buf.as_str().to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64(f: f64) -> Self {
|
pub fn from_f64(f: f64) -> Self {
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
buf.write_formatted(&(f as u128), &LOCALE);
|
buf.write_formatted(&(f as u128), &LOCALE);
|
||||||
Self(buf.as_str().to_string())
|
Self(buf.as_str().to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u16(u: u16) -> Self {
|
pub fn from_u16(u: u16) -> Self {
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
buf.write_formatted(&u, &LOCALE);
|
buf.write_formatted(&u, &LOCALE);
|
||||||
Self(buf.as_str().to_string())
|
Self(buf.as_str().to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u32(u: u32) -> Self {
|
pub fn from_u32(u: u32) -> Self {
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
buf.write_formatted(&u, &LOCALE);
|
buf.write_formatted(&u, &LOCALE);
|
||||||
Self(buf.as_str().to_string())
|
Self(buf.as_str().to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u64(u: u64) -> Self {
|
pub fn from_u64(u: u64) -> Self {
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
buf.write_formatted(&u, &LOCALE);
|
buf.write_formatted(&u, &LOCALE);
|
||||||
Self(buf.as_str().to_string())
|
Self(buf.as_str().to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u128(u: u128) -> Self {
|
pub fn from_u128(u: u128) -> Self {
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
buf.write_formatted(&u, &LOCALE);
|
buf.write_formatted(&u, &LOCALE);
|
||||||
Self(buf.as_str().to_string())
|
Self(buf.as_str().to_string())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_hashrate(array: [Option<f32>; 3]) -> Self {
|
pub fn from_hashrate(array: [Option<f32>; 3]) -> Self {
|
||||||
let mut string = "[".to_string();
|
let mut string = "[".to_string();
|
||||||
let mut buf = num_format::Buffer::new();
|
let mut buf = num_format::Buffer::new();
|
||||||
|
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
for i in array {
|
for i in array {
|
||||||
match i {
|
match i {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
let f = f as u128;
|
let f = f as u128;
|
||||||
buf.write_formatted(&f, &LOCALE);
|
buf.write_formatted(&f, &LOCALE);
|
||||||
string.push_str(buf.as_str());
|
string.push_str(buf.as_str());
|
||||||
string.push_str(" H/s");
|
string.push_str(" H/s");
|
||||||
},
|
}
|
||||||
None => string.push_str("??? H/s"),
|
None => string.push_str("??? H/s"),
|
||||||
}
|
}
|
||||||
if n != 2 {
|
if n != 2 {
|
||||||
string.push_str(", ");
|
string.push_str(", ");
|
||||||
n += 1;
|
n += 1;
|
||||||
} else {
|
} else {
|
||||||
string.push(']');
|
string.push(']');
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self(string)
|
Self(string)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_load(array: [Option<f32>; 3]) -> Self {
|
pub fn from_load(array: [Option<f32>; 3]) -> Self {
|
||||||
let mut string = "[".to_string();
|
let mut string = "[".to_string();
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
for i in array {
|
for i in array {
|
||||||
match i {
|
match i {
|
||||||
Some(f) => string.push_str(format!("{:.2}", f).as_str()),
|
Some(f) => string.push_str(format!("{:.2}", f).as_str()),
|
||||||
None => string.push_str("???"),
|
None => string.push_str("???"),
|
||||||
}
|
}
|
||||||
if n != 2 {
|
if n != 2 {
|
||||||
string.push_str(", ");
|
string.push_str(", ");
|
||||||
n += 1;
|
n += 1;
|
||||||
} else {
|
} else {
|
||||||
string.push(']');
|
string.push(']');
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self(string)
|
Self(string)
|
||||||
}
|
}
|
||||||
// [1_000_000] -> [1.000 MH/s]
|
// [1_000_000] -> [1.000 MH/s]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u64_to_megahash_3_point(hash: u64) -> Self {
|
pub fn from_u64_to_megahash_3_point(hash: u64) -> Self {
|
||||||
let hash = (hash as f64)/1_000_000.0;
|
let hash = (hash as f64) / 1_000_000.0;
|
||||||
let hash = format!("{:.3} MH/s", hash);
|
let hash = format!("{:.3} MH/s", hash);
|
||||||
Self(hash)
|
Self(hash)
|
||||||
}
|
}
|
||||||
// [1_000_000_000] -> [1.000 GH/s]
|
// [1_000_000_000] -> [1.000 GH/s]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u64_to_gigahash_3_point(hash: u64) -> Self {
|
pub fn from_u64_to_gigahash_3_point(hash: u64) -> Self {
|
||||||
let hash = (hash as f64)/1_000_000_000.0;
|
let hash = (hash as f64) / 1_000_000_000.0;
|
||||||
let hash = format!("{:.3} GH/s", hash);
|
let hash = format!("{:.3} GH/s", hash);
|
||||||
Self(hash)
|
Self(hash)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64_12_point(f: f64) -> Self {
|
pub fn from_f64_12_point(f: f64) -> Self {
|
||||||
let f = format!("{:.12}", f);
|
let f = format!("{:.12}", f);
|
||||||
Self(f)
|
Self(f)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_f64_no_fmt(f: f64) -> Self {
|
pub fn from_f64_no_fmt(f: f64) -> Self {
|
||||||
let f = format!("{}", f);
|
let f = format!("{}", f);
|
||||||
Self(f)
|
Self(f)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
self.0.as_str()
|
self.0.as_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TESTS
|
//---------------------------------------------------------------------------------------------------- TESTS
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn human_number() {
|
fn human_number() {
|
||||||
use crate::human::HumanNumber;
|
use crate::human::HumanNumber;
|
||||||
assert!(HumanNumber::to_percent(0.001).to_string() == "0%");
|
assert!(HumanNumber::to_percent(0.001).to_string() == "0%");
|
||||||
assert!(HumanNumber::to_percent(12.123123123123).to_string() == "12.12%");
|
assert!(HumanNumber::to_percent(12.123123123123).to_string() == "12.12%");
|
||||||
assert!(HumanNumber::to_percent_3_point(0.001).to_string() == "0.001%");
|
assert!(HumanNumber::to_percent_3_point(0.001).to_string() == "0.001%");
|
||||||
assert!(HumanNumber::from_hashrate([Some(123.1), Some(11111.1), None]).to_string() == "[123 H/s, 11,111 H/s, ??? H/s]");
|
assert!(
|
||||||
assert!(HumanNumber::from_hashrate([None, Some(1.123), Some(123123.312)]).to_string() == "[??? H/s, 1 H/s, 123,123 H/s]");
|
HumanNumber::from_hashrate([Some(123.1), Some(11111.1), None]).to_string()
|
||||||
assert!(HumanNumber::from_load([Some(123.1234), Some(321.321), None]).to_string() == "[123.12, 321.32, ???]");
|
== "[123 H/s, 11,111 H/s, ??? H/s]"
|
||||||
assert!(HumanNumber::from_load([None, Some(4321.43), Some(1234.1)]).to_string() == "[???, 4321.43, 1234.10]");
|
);
|
||||||
assert!(HumanNumber::from_f32(123_123.123123123).to_string() == "123,123");
|
assert!(
|
||||||
assert!(HumanNumber::from_f64(123_123_123.123123123123123).to_string() == "123,123,123");
|
HumanNumber::from_hashrate([None, Some(1.123), Some(123123.312)]).to_string()
|
||||||
assert!(HumanNumber::from_u16(1_000).to_string() == "1,000");
|
== "[??? H/s, 1 H/s, 123,123 H/s]"
|
||||||
assert!(HumanNumber::from_u16(65_535).to_string() == "65,535");
|
);
|
||||||
assert!(HumanNumber::from_u32(65_536).to_string() == "65,536");
|
assert!(
|
||||||
assert!(HumanNumber::from_u32(100_000).to_string() == "100,000");
|
HumanNumber::from_load([Some(123.1234), Some(321.321), None]).to_string()
|
||||||
assert!(HumanNumber::from_u32(1_000_000).to_string() == "1,000,000");
|
== "[123.12, 321.32, ???]"
|
||||||
assert!(HumanNumber::from_u32(10_000_000).to_string() == "10,000,000");
|
);
|
||||||
assert!(HumanNumber::from_u32(100_000_000).to_string() == "100,000,000");
|
assert!(
|
||||||
assert!(HumanNumber::from_u32(1_000_000_000).to_string() == "1,000,000,000");
|
HumanNumber::from_load([None, Some(4321.43), Some(1234.1)]).to_string()
|
||||||
assert!(HumanNumber::from_u32(4_294_967_295).to_string() == "4,294,967,295");
|
== "[???, 4321.43, 1234.10]"
|
||||||
assert!(HumanNumber::from_u64(4_294_967_296).to_string() == "4,294,967,296");
|
);
|
||||||
assert!(HumanNumber::from_u64(10_000_000_000).to_string() == "10,000,000,000");
|
assert!(HumanNumber::from_f32(123_123.123123123).to_string() == "123,123");
|
||||||
assert!(HumanNumber::from_u64(100_000_000_000).to_string() == "100,000,000,000");
|
assert!(HumanNumber::from_f64(123_123_123.123123123123123).to_string() == "123,123,123");
|
||||||
assert!(HumanNumber::from_u64(1_000_000_000_000).to_string() == "1,000,000,000,000");
|
assert!(HumanNumber::from_u16(1_000).to_string() == "1,000");
|
||||||
assert!(HumanNumber::from_u64(10_000_000_000_000).to_string() == "10,000,000,000,000");
|
assert!(HumanNumber::from_u16(65_535).to_string() == "65,535");
|
||||||
assert!(HumanNumber::from_u64(100_000_000_000_000).to_string() == "100,000,000,000,000");
|
assert!(HumanNumber::from_u32(65_536).to_string() == "65,536");
|
||||||
assert!(HumanNumber::from_u64(1_000_000_000_000_000).to_string() == "1,000,000,000,000,000");
|
assert!(HumanNumber::from_u32(100_000).to_string() == "100,000");
|
||||||
assert!(HumanNumber::from_u64(10_000_000_000_000_000).to_string() == "10,000,000,000,000,000");
|
assert!(HumanNumber::from_u32(1_000_000).to_string() == "1,000,000");
|
||||||
assert!(HumanNumber::from_u64(18_446_744_073_709_551_615).to_string() == "18,446,744,073,709,551,615");
|
assert!(HumanNumber::from_u32(10_000_000).to_string() == "10,000,000");
|
||||||
assert!(HumanNumber::from_u128(18_446_744_073_709_551_616).to_string() == "18,446,744,073,709,551,616");
|
assert!(HumanNumber::from_u32(100_000_000).to_string() == "100,000,000");
|
||||||
assert!(HumanNumber::from_u128(100_000_000_000_000_000_000).to_string() == "100,000,000,000,000,000,000");
|
assert!(HumanNumber::from_u32(1_000_000_000).to_string() == "1,000,000,000");
|
||||||
assert_eq!(
|
assert!(HumanNumber::from_u32(4_294_967_295).to_string() == "4,294,967,295");
|
||||||
HumanNumber::from_u128(340_282_366_920_938_463_463_374_607_431_768_211_455).to_string(),
|
assert!(HumanNumber::from_u64(4_294_967_296).to_string() == "4,294,967,296");
|
||||||
"340,282,366,920,938,463,463,374,607,431,768,211,455",
|
assert!(HumanNumber::from_u64(10_000_000_000).to_string() == "10,000,000,000");
|
||||||
);
|
assert!(HumanNumber::from_u64(100_000_000_000).to_string() == "100,000,000,000");
|
||||||
assert!(HumanNumber::from_u64_to_gigahash_3_point(1_000_000_000).to_string() == "1.000 GH/s");
|
assert!(HumanNumber::from_u64(1_000_000_000_000).to_string() == "1,000,000,000,000");
|
||||||
}
|
assert!(HumanNumber::from_u64(10_000_000_000_000).to_string() == "10,000,000,000,000");
|
||||||
|
assert!(HumanNumber::from_u64(100_000_000_000_000).to_string() == "100,000,000,000,000");
|
||||||
|
assert!(
|
||||||
|
HumanNumber::from_u64(1_000_000_000_000_000).to_string() == "1,000,000,000,000,000"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
HumanNumber::from_u64(10_000_000_000_000_000).to_string() == "10,000,000,000,000,000"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
HumanNumber::from_u64(18_446_744_073_709_551_615).to_string()
|
||||||
|
== "18,446,744,073,709,551,615"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
HumanNumber::from_u128(18_446_744_073_709_551_616).to_string()
|
||||||
|
== "18,446,744,073,709,551,616"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
HumanNumber::from_u128(100_000_000_000_000_000_000).to_string()
|
||||||
|
== "100,000,000,000,000,000,000"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
HumanNumber::from_u128(340_282_366_920_938_463_463_374_607_431_768_211_455).to_string(),
|
||||||
|
"340,282,366,920,938,463,463,374,607,431,768,211,455",
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
HumanNumber::from_u64_to_gigahash_3_point(1_000_000_000).to_string() == "1.000 GH/s"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn human_time() {
|
fn human_time() {
|
||||||
use crate::human::HumanTime;
|
use crate::human::HumanTime;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(0)).to_string() == "0 seconds");
|
assert!(HumanTime::into_human(Duration::from_secs(0)).to_string() == "0 seconds");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(1)).to_string() == "1 second");
|
assert!(HumanTime::into_human(Duration::from_secs(1)).to_string() == "1 second");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(2)).to_string() == "2 seconds");
|
assert!(HumanTime::into_human(Duration::from_secs(2)).to_string() == "2 seconds");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(59)).to_string() == "59 seconds");
|
assert!(HumanTime::into_human(Duration::from_secs(59)).to_string() == "59 seconds");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(60)).to_string() == "1 minute");
|
assert!(HumanTime::into_human(Duration::from_secs(60)).to_string() == "1 minute");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(61)).to_string() == "1 minute, 1 second");
|
assert!(HumanTime::into_human(Duration::from_secs(61)).to_string() == "1 minute, 1 second");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(62)).to_string() == "1 minute, 2 seconds");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(120)).to_string() == "2 minutes");
|
HumanTime::into_human(Duration::from_secs(62)).to_string() == "1 minute, 2 seconds"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(121)).to_string() == "2 minutes, 1 second");
|
);
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(122)).to_string() == "2 minutes, 2 seconds");
|
assert!(HumanTime::into_human(Duration::from_secs(120)).to_string() == "2 minutes");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(179)).to_string() == "2 minutes, 59 seconds");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3599)).to_string() == "59 minutes, 59 seconds");
|
HumanTime::into_human(Duration::from_secs(121)).to_string() == "2 minutes, 1 second"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3600)).to_string() == "1 hour");
|
);
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3601)).to_string() == "1 hour, 1 second");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3602)).to_string() == "1 hour, 2 seconds");
|
HumanTime::into_human(Duration::from_secs(122)).to_string() == "2 minutes, 2 seconds"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3660)).to_string() == "1 hour, 1 minute");
|
);
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3720)).to_string() == "1 hour, 2 minutes");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(86399)).to_string() == "23 hours, 59 minutes, 59 seconds");
|
HumanTime::into_human(Duration::from_secs(179)).to_string() == "2 minutes, 59 seconds"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(86400)).to_string() == "1 day");
|
);
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(86401)).to_string() == "1 day, 1 second");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(86402)).to_string() == "1 day, 2 seconds");
|
HumanTime::into_human(Duration::from_secs(3599)).to_string()
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(86460)).to_string() == "1 day, 1 minute");
|
== "59 minutes, 59 seconds"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(86520)).to_string() == "1 day, 2 minutes");
|
);
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(90000)).to_string() == "1 day, 1 hour");
|
assert!(HumanTime::into_human(Duration::from_secs(3600)).to_string() == "1 hour");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(93600)).to_string() == "1 day, 2 hours");
|
assert!(HumanTime::into_human(Duration::from_secs(3601)).to_string() == "1 hour, 1 second");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(604799)).to_string() == "6 days, 23 hours, 59 minutes, 59 seconds");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(604800)).to_string() == "7 days");
|
HumanTime::into_human(Duration::from_secs(3602)).to_string() == "1 hour, 2 seconds"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(2630016)).to_string() == "1 month");
|
);
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(3234815)).to_string() == "1 month, 6 days, 23 hours, 59 minutes, 59 seconds");
|
assert!(HumanTime::into_human(Duration::from_secs(3660)).to_string() == "1 hour, 1 minute");
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(5260032)).to_string() == "2 months");
|
assert!(
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(31557600)).to_string() == "1 year");
|
HumanTime::into_human(Duration::from_secs(3720)).to_string() == "1 hour, 2 minutes"
|
||||||
assert!(HumanTime::into_human(Duration::from_secs(63115200)).to_string() == "2 years");
|
);
|
||||||
assert_eq!(
|
assert!(
|
||||||
HumanTime::into_human(Duration::from_secs(18446744073709551615)).to_string(),
|
HumanTime::into_human(Duration::from_secs(86399)).to_string()
|
||||||
"584542046090 years, 7 months, 15 days, 17 hours, 5 minutes, 3 seconds",
|
== "23 hours, 59 minutes, 59 seconds"
|
||||||
);
|
);
|
||||||
}
|
assert!(HumanTime::into_human(Duration::from_secs(86400)).to_string() == "1 day");
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(86401)).to_string() == "1 day, 1 second");
|
||||||
|
assert!(
|
||||||
|
HumanTime::into_human(Duration::from_secs(86402)).to_string() == "1 day, 2 seconds"
|
||||||
|
);
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(86460)).to_string() == "1 day, 1 minute");
|
||||||
|
assert!(
|
||||||
|
HumanTime::into_human(Duration::from_secs(86520)).to_string() == "1 day, 2 minutes"
|
||||||
|
);
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(90000)).to_string() == "1 day, 1 hour");
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(93600)).to_string() == "1 day, 2 hours");
|
||||||
|
assert!(
|
||||||
|
HumanTime::into_human(Duration::from_secs(604799)).to_string()
|
||||||
|
== "6 days, 23 hours, 59 minutes, 59 seconds"
|
||||||
|
);
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(604800)).to_string() == "7 days");
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(2630016)).to_string() == "1 month");
|
||||||
|
assert!(
|
||||||
|
HumanTime::into_human(Duration::from_secs(3234815)).to_string()
|
||||||
|
== "1 month, 6 days, 23 hours, 59 minutes, 59 seconds"
|
||||||
|
);
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(5260032)).to_string() == "2 months");
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(31557600)).to_string() == "1 year");
|
||||||
|
assert!(HumanTime::into_human(Duration::from_secs(63115200)).to_string() == "2 years");
|
||||||
|
assert_eq!(
|
||||||
|
HumanTime::into_human(Duration::from_secs(18446744073709551615)).to_string(),
|
||||||
|
"584542046090 years, 7 months, 15 days, 17 hours, 5 minutes, 3 seconds",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,83 +39,81 @@
|
||||||
|
|
||||||
// Locks and unwraps an [Arc<Mutex<T>]
|
// Locks and unwraps an [Arc<Mutex<T>]
|
||||||
macro_rules! lock {
|
macro_rules! lock {
|
||||||
($arc_mutex:expr) => {
|
($arc_mutex:expr) => {
|
||||||
$arc_mutex.lock().unwrap()
|
$arc_mutex.lock().unwrap()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use lock;
|
pub(crate) use lock;
|
||||||
|
|
||||||
// Locks and unwraps a field of a struct, both of them being [Arc<Mutex>]
|
// Locks and unwraps a field of a struct, both of them being [Arc<Mutex>]
|
||||||
// Yes, I know this is bad code.
|
// Yes, I know this is bad code.
|
||||||
macro_rules! lock2 {
|
macro_rules! lock2 {
|
||||||
($arc_mutex:expr, $arc_mutex_two:ident) => {
|
($arc_mutex:expr, $arc_mutex_two:ident) => {
|
||||||
$arc_mutex.lock().unwrap().$arc_mutex_two.lock().unwrap()
|
$arc_mutex.lock().unwrap().$arc_mutex_two.lock().unwrap()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use lock2;
|
pub(crate) use lock2;
|
||||||
|
|
||||||
// Creates a new [Arc<Mutex<T>]
|
// Creates a new [Arc<Mutex<T>]
|
||||||
macro_rules! arc_mut {
|
macro_rules! arc_mut {
|
||||||
($arc_mutex:expr) => {
|
($arc_mutex:expr) => {
|
||||||
std::sync::Arc::new(std::sync::Mutex::new($arc_mutex))
|
std::sync::Arc::new(std::sync::Mutex::new($arc_mutex))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use arc_mut;
|
pub(crate) use arc_mut;
|
||||||
|
|
||||||
// Sleeps a [std::thread] using milliseconds
|
// Sleeps a [std::thread] using milliseconds
|
||||||
macro_rules! sleep {
|
macro_rules! sleep {
|
||||||
($millis:expr) => {
|
($millis:expr) => {
|
||||||
std::thread::sleep(std::time::Duration::from_millis($millis))
|
std::thread::sleep(std::time::Duration::from_millis($millis))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use sleep;
|
pub(crate) use sleep;
|
||||||
|
|
||||||
// Flips a [bool] in place
|
// Flips a [bool] in place
|
||||||
macro_rules! flip {
|
macro_rules! flip {
|
||||||
($b:expr) => {
|
($b:expr) => {
|
||||||
match $b {
|
match $b {
|
||||||
true|false => $b = !$b,
|
true | false => $b = !$b,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use flip;
|
pub(crate) use flip;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TESTS
|
//---------------------------------------------------------------------------------------------------- TESTS
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn lock() {
|
fn lock() {
|
||||||
use std::sync::{Arc,Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
let arc_mutex = Arc::new(Mutex::new(false));
|
let arc_mutex = Arc::new(Mutex::new(false));
|
||||||
*lock!(arc_mutex) = true;
|
*lock!(arc_mutex) = true;
|
||||||
assert!(*lock!(arc_mutex) == true);
|
assert!(*lock!(arc_mutex) == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lock2() {
|
fn lock2() {
|
||||||
struct Ab {
|
struct Ab {
|
||||||
a: Arc<Mutex<bool>>,
|
a: Arc<Mutex<bool>>,
|
||||||
}
|
}
|
||||||
use std::sync::{Arc,Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
let arc_mutex = Arc::new(Mutex::new(
|
let arc_mutex = Arc::new(Mutex::new(Ab {
|
||||||
Ab {
|
a: Arc::new(Mutex::new(false)),
|
||||||
a: Arc::new(Mutex::new(false)),
|
}));
|
||||||
}
|
*lock2!(arc_mutex, a) = true;
|
||||||
));
|
assert!(*lock2!(arc_mutex, a) == true);
|
||||||
*lock2!(arc_mutex,a) = true;
|
}
|
||||||
assert!(*lock2!(arc_mutex,a) == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn arc_mut() {
|
fn arc_mut() {
|
||||||
let a = arc_mut!(false);
|
let a = arc_mut!(false);
|
||||||
assert!(*lock!(a) == false);
|
assert!(*lock!(a) == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flip() {
|
fn flip() {
|
||||||
let mut b = true;
|
let mut b = true;
|
||||||
flip!(b);
|
flip!(b);
|
||||||
assert!(b == false);
|
assert!(b == false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3431
src/main.rs
3431
src/main.rs
File diff suppressed because it is too large
Load diff
912
src/node.rs
912
src/node.rs
File diff suppressed because it is too large
Load diff
643
src/p2pool.rs
643
src/p2pool.rs
|
@ -15,247 +15,319 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::regex::REGEXES;
|
||||||
Regexes,
|
use crate::{constants::*, disk::*, helper::*, macros::*, node::*, Regexes};
|
||||||
constants::*,
|
|
||||||
disk::*,
|
|
||||||
node::*,
|
|
||||||
helper::*,
|
|
||||||
macros::*,
|
|
||||||
};
|
|
||||||
use egui::{
|
use egui::{
|
||||||
TextEdit,SelectableLabel,ComboBox,Label,Button,
|
Button, Checkbox, Color32, ComboBox, Hyperlink, Label, ProgressBar, RichText, SelectableLabel,
|
||||||
Color32,RichText,Slider,Checkbox,ProgressBar,Spinner,
|
Slider, Spinner, TextEdit, TextStyle::*,
|
||||||
TextStyle::*,Hyperlink
|
|
||||||
};
|
};
|
||||||
use std::sync::{Arc,Mutex};
|
|
||||||
use regex::Regex;
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use crate::regex::{
|
use regex::Regex;
|
||||||
REGEXES,
|
use std::sync::{Arc, Mutex};
|
||||||
};
|
|
||||||
|
|
||||||
impl crate::disk::P2pool {
|
impl crate::disk::P2pool {
|
||||||
#[inline(always)] // called once
|
#[inline(always)] // called once
|
||||||
pub fn show(
|
pub fn show(
|
||||||
&mut self,
|
&mut self,
|
||||||
node_vec: &mut Vec<(String,
|
node_vec: &mut Vec<(String, Node)>,
|
||||||
Node)>,
|
_og: &Arc<Mutex<State>>,
|
||||||
_og: &Arc<Mutex<State>>,
|
ping: &Arc<Mutex<Ping>>,
|
||||||
ping: &Arc<Mutex<Ping>>,
|
process: &Arc<Mutex<Process>>,
|
||||||
process: &Arc<Mutex<Process>>,
|
api: &Arc<Mutex<PubP2poolApi>>,
|
||||||
api: &Arc<Mutex<PubP2poolApi>>,
|
buffer: &mut String,
|
||||||
buffer: &mut String,
|
width: f32,
|
||||||
width: f32,
|
height: f32,
|
||||||
height: f32,
|
_ctx: &egui::Context,
|
||||||
_ctx: &egui::Context,
|
ui: &mut egui::Ui,
|
||||||
ui: &mut egui::Ui
|
) {
|
||||||
) {
|
let text_edit = height / 25.0;
|
||||||
let text_edit = height / 25.0;
|
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
debug!("P2Pool Tab | Rendering [Console]");
|
||||||
debug!("P2Pool Tab | Rendering [Console]");
|
ui.group(|ui| {
|
||||||
ui.group(|ui| {
|
if self.simple {
|
||||||
if self.simple {
|
let height = height / 2.8;
|
||||||
let height = height / 2.8;
|
let width = width - SPACE;
|
||||||
let width = width - SPACE;
|
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
egui::ScrollArea::vertical()
|
||||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
.stick_to_bottom(true)
|
||||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
.max_width(width)
|
||||||
});
|
.max_height(height)
|
||||||
});
|
.auto_shrink([false; 2])
|
||||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
.show_viewport(ui, |ui, _| {
|
||||||
} else {
|
ui.add_sized(
|
||||||
let height = height / 2.8;
|
[width, height],
|
||||||
let width = width - SPACE;
|
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
);
|
||||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
});
|
||||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
});
|
||||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||||
});
|
} else {
|
||||||
});
|
let height = height / 2.8;
|
||||||
ui.separator();
|
let width = width - SPACE;
|
||||||
let response = ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(buffer), r#"Type a command (e.g "help" or "status") and press Enter"#)).on_hover_text(P2POOL_INPUT);
|
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||||
// If the user pressed enter, dump buffer contents into the process STDIN
|
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||||
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
egui::ScrollArea::vertical()
|
||||||
response.request_focus(); // Get focus back
|
.stick_to_bottom(true)
|
||||||
let buffer = std::mem::take(buffer); // Take buffer
|
.max_width(width)
|
||||||
let mut process = lock!(process); // Lock
|
.max_height(height)
|
||||||
if process.is_alive() { process.input.push(buffer); } // Push only if alive
|
.auto_shrink([false; 2])
|
||||||
}
|
.show_viewport(ui, |ui, _| {
|
||||||
}
|
ui.add_sized(
|
||||||
});
|
[width, height],
|
||||||
|
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.separator();
|
||||||
|
let response = ui
|
||||||
|
.add_sized(
|
||||||
|
[width, text_edit],
|
||||||
|
TextEdit::hint_text(
|
||||||
|
TextEdit::singleline(buffer),
|
||||||
|
r#"Type a command (e.g "help" or "status") and press Enter"#,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.on_hover_text(P2POOL_INPUT);
|
||||||
|
// If the user pressed enter, dump buffer contents into the process STDIN
|
||||||
|
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||||
|
response.request_focus(); // Get focus back
|
||||||
|
let buffer = std::mem::take(buffer); // Take buffer
|
||||||
|
let mut process = lock!(process); // Lock
|
||||||
|
if process.is_alive() {
|
||||||
|
process.input.push(buffer);
|
||||||
|
} // Push only if alive
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Args
|
//---------------------------------------------------------------------------------------------------- Args
|
||||||
if !self.simple {
|
if !self.simple {
|
||||||
debug!("P2Pool Tab | Rendering [Arguments]");
|
debug!("P2Pool Tab | Rendering [Arguments]");
|
||||||
ui.group(|ui| { ui.horizontal(|ui| {
|
ui.group(|ui| {
|
||||||
let width = (width/10.0) - SPACE;
|
ui.horizontal(|ui| {
|
||||||
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
|
let width = (width / 10.0) - SPACE;
|
||||||
ui.add_sized([ui.available_width(), text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.arguments), r#"--wallet <...> --host <...>"#)).on_hover_text(P2POOL_ARGUMENTS);
|
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
|
||||||
self.arguments.truncate(1024);
|
ui.add_sized(
|
||||||
})});
|
[ui.available_width(), text_edit],
|
||||||
ui.set_enabled(self.arguments.is_empty());
|
TextEdit::hint_text(
|
||||||
}
|
TextEdit::singleline(&mut self.arguments),
|
||||||
|
r#"--wallet <...> --host <...>"#,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.on_hover_text(P2POOL_ARGUMENTS);
|
||||||
|
self.arguments.truncate(1024);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
ui.set_enabled(self.arguments.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Address
|
//---------------------------------------------------------------------------------------------------- Address
|
||||||
debug!("P2Pool Tab | Rendering [Address]");
|
debug!("P2Pool Tab | Rendering [Address]");
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = width - SPACE;
|
let width = width - SPACE;
|
||||||
ui.spacing_mut().text_edit_width = (width)-(SPACE*3.0);
|
ui.spacing_mut().text_edit_width = (width) - (SPACE * 3.0);
|
||||||
let text;
|
let text;
|
||||||
let color;
|
let color;
|
||||||
let len = format!("{:02}", self.address.len());
|
let len = format!("{:02}", self.address.len());
|
||||||
if self.address.is_empty() {
|
if self.address.is_empty() {
|
||||||
text = format!("Monero Address [{}/95] ➖", len);
|
text = format!("Monero Address [{}/95] ➖", len);
|
||||||
color = Color32::LIGHT_GRAY;
|
color = Color32::LIGHT_GRAY;
|
||||||
} else if Regexes::addr_ok(&self.address) {
|
} else if Regexes::addr_ok(&self.address) {
|
||||||
text = format!("Monero Address [{}/95] ✔", len);
|
text = format!("Monero Address [{}/95] ✔", len);
|
||||||
color = Color32::from_rgb(100, 230, 100);
|
color = Color32::from_rgb(100, 230, 100);
|
||||||
} else {
|
} else {
|
||||||
text = format!("Monero Address [{}/95] ❌", len);
|
text = format!("Monero Address [{}/95] ❌", len);
|
||||||
color = Color32::from_rgb(230, 50, 50);
|
color = Color32::from_rgb(230, 50, 50);
|
||||||
}
|
}
|
||||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
ui.add_sized(
|
||||||
ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(P2POOL_ADDRESS);
|
[width, text_edit],
|
||||||
self.address.truncate(95);
|
Label::new(RichText::new(text).color(color)),
|
||||||
});
|
);
|
||||||
|
ui.add_sized(
|
||||||
|
[width, text_edit],
|
||||||
|
TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4..."),
|
||||||
|
)
|
||||||
|
.on_hover_text(P2POOL_ADDRESS);
|
||||||
|
self.address.truncate(95);
|
||||||
|
});
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Simple
|
//---------------------------------------------------------------------------------------------------- Simple
|
||||||
let height = ui.available_height();
|
let height = ui.available_height();
|
||||||
if self.simple {
|
if self.simple {
|
||||||
// [Node]
|
// [Node]
|
||||||
let height = height / 6.5;
|
let height = height / 6.5;
|
||||||
ui.spacing_mut().slider_width = width - 8.0;
|
ui.spacing_mut().slider_width = width - 8.0;
|
||||||
ui.spacing_mut().icon_width = width / 25.0;
|
ui.spacing_mut().icon_width = width / 25.0;
|
||||||
|
|
||||||
// [Auto-select] if we haven't already.
|
// [Auto-select] if we haven't already.
|
||||||
// Using [Arc<Mutex<Ping>>] as an intermediary here
|
// Using [Arc<Mutex<Ping>>] as an intermediary here
|
||||||
// saves me the hassle of wrapping [state: State] completely
|
// saves me the hassle of wrapping [state: State] completely
|
||||||
// and [.lock().unwrap()]ing it everywhere.
|
// and [.lock().unwrap()]ing it everywhere.
|
||||||
// Two atomic bools = enough to represent this data
|
// Two atomic bools = enough to represent this data
|
||||||
debug!("P2Pool Tab | Running [auto-select] check");
|
debug!("P2Pool Tab | Running [auto-select] check");
|
||||||
if self.auto_select {
|
if self.auto_select {
|
||||||
let mut ping = lock!(ping);
|
let mut ping = lock!(ping);
|
||||||
// If we haven't auto_selected yet, auto-select and turn it off
|
// If we haven't auto_selected yet, auto-select and turn it off
|
||||||
if ping.pinged && !ping.auto_selected {
|
if ping.pinged && !ping.auto_selected {
|
||||||
self.node = ping.fastest.to_string();
|
self.node = ping.fastest.to_string();
|
||||||
ping.auto_selected = true;
|
ping.auto_selected = true;
|
||||||
}
|
}
|
||||||
drop(ping);
|
drop(ping);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
debug!("P2Pool Tab | Rendering [Ping List]");
|
||||||
|
// [Ping List]
|
||||||
|
let mut ms = 0;
|
||||||
|
let mut color = Color32::LIGHT_GRAY;
|
||||||
|
if lock!(ping).pinged {
|
||||||
|
for data in lock!(ping).nodes.iter() {
|
||||||
|
if data.ip == self.node {
|
||||||
|
ms = data.ms;
|
||||||
|
color = data.color;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug!("P2Pool Tab | Rendering [ComboBox] of Remote Nodes");
|
||||||
|
let ip_location = crate::node::format_ip_location(&self.node, false);
|
||||||
|
let text = RichText::new(format!(" ⏺ {}ms | {}", ms, ip_location)).color(color);
|
||||||
|
ComboBox::from_id_source("remote_nodes")
|
||||||
|
.selected_text(text)
|
||||||
|
.width(width)
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
for data in lock!(ping).nodes.iter() {
|
||||||
|
let ms = crate::node::format_ms(data.ms);
|
||||||
|
let ip_location = crate::node::format_ip_location(data.ip, true);
|
||||||
|
let text = RichText::new(format!(" ⏺ {} | {}", ms, ip_location))
|
||||||
|
.color(data.color);
|
||||||
|
ui.selectable_value(&mut self.node, data.ip.to_string(), text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
debug!("P2Pool Tab | Rendering [Ping List]");
|
ui.add_space(5.0);
|
||||||
// [Ping List]
|
|
||||||
let mut ms = 0;
|
|
||||||
let mut color = Color32::LIGHT_GRAY;
|
|
||||||
if lock!(ping).pinged {
|
|
||||||
for data in lock!(ping).nodes.iter() {
|
|
||||||
if data.ip == self.node {
|
|
||||||
ms = data.ms;
|
|
||||||
color = data.color;
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug!("P2Pool Tab | Rendering [ComboBox] of Remote Nodes");
|
|
||||||
let ip_location = crate::node::format_ip_location(&self.node, false);
|
|
||||||
let text = RichText::new(format!(" ⏺ {}ms | {}", ms, ip_location)).color(color);
|
|
||||||
ComboBox::from_id_source("remote_nodes").selected_text(text).width(width).show_ui(ui, |ui| {
|
|
||||||
for data in lock!(ping).nodes.iter() {
|
|
||||||
let ms = crate::node::format_ms(data.ms);
|
|
||||||
let ip_location = crate::node::format_ip_location(data.ip, true);
|
|
||||||
let text = RichText::new(format!(" ⏺ {} | {}", ms, ip_location)).color(data.color);
|
|
||||||
ui.selectable_value(&mut self.node, data.ip.to_string(), text);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.add_space(5.0);
|
debug!("P2Pool Tab | Rendering [Select fastest ... Ping] buttons");
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
let width = (width / 5.0) - 6.0;
|
||||||
|
// [Select random node]
|
||||||
|
if ui
|
||||||
|
.add_sized([width, height], Button::new("Select random node"))
|
||||||
|
.on_hover_text(P2POOL_SELECT_RANDOM)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.node = RemoteNode::get_random(&self.node);
|
||||||
|
}
|
||||||
|
// [Select fastest node]
|
||||||
|
if ui
|
||||||
|
.add_sized([width, height], Button::new("Select fastest node"))
|
||||||
|
.on_hover_text(P2POOL_SELECT_FASTEST)
|
||||||
|
.clicked()
|
||||||
|
&& lock!(ping).pinged
|
||||||
|
{
|
||||||
|
self.node = lock!(ping).fastest.to_string();
|
||||||
|
}
|
||||||
|
// [Ping Button]
|
||||||
|
ui.add_enabled_ui(!lock!(ping).pinging, |ui| {
|
||||||
|
if ui
|
||||||
|
.add_sized([width, height], Button::new("Ping remote nodes"))
|
||||||
|
.on_hover_text(P2POOL_PING)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
Ping::spawn_thread(ping);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// [Last <-]
|
||||||
|
if ui
|
||||||
|
.add_sized([width, height], Button::new("⬅ Last"))
|
||||||
|
.on_hover_text(P2POOL_SELECT_LAST)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
let ping = lock!(ping);
|
||||||
|
match ping.pinged {
|
||||||
|
true => {
|
||||||
|
self.node = RemoteNode::get_last_from_ping(&self.node, &ping.nodes)
|
||||||
|
}
|
||||||
|
false => self.node = RemoteNode::get_last(&self.node),
|
||||||
|
}
|
||||||
|
drop(ping);
|
||||||
|
}
|
||||||
|
// [Next ->]
|
||||||
|
if ui
|
||||||
|
.add_sized([width, height], Button::new("Next ➡"))
|
||||||
|
.on_hover_text(P2POOL_SELECT_NEXT)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
let ping = lock!(ping);
|
||||||
|
match ping.pinged {
|
||||||
|
true => {
|
||||||
|
self.node = RemoteNode::get_next_from_ping(&self.node, &ping.nodes)
|
||||||
|
}
|
||||||
|
false => self.node = RemoteNode::get_next(&self.node),
|
||||||
|
}
|
||||||
|
drop(ping);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
debug!("P2Pool Tab | Rendering [Select fastest ... Ping] buttons");
|
ui.vertical(|ui| {
|
||||||
ui.horizontal(|ui| {
|
let height = height / 2.0;
|
||||||
let width = (width/5.0)-6.0;
|
let pinging = lock!(ping).pinging;
|
||||||
// [Select random node]
|
ui.set_enabled(pinging);
|
||||||
if ui.add_sized([width, height], Button::new("Select random node")).on_hover_text(P2POOL_SELECT_RANDOM).clicked() {
|
let prog = lock!(ping).prog.round();
|
||||||
self.node = RemoteNode::get_random(&self.node);
|
let msg = RichText::new(format!("{} ... {}%", lock!(ping).msg, prog));
|
||||||
}
|
let height = height / 1.25;
|
||||||
// [Select fastest node]
|
ui.add_space(5.0);
|
||||||
if ui.add_sized([width, height], Button::new("Select fastest node")).on_hover_text(P2POOL_SELECT_FASTEST).clicked() && lock!(ping).pinged {
|
ui.add_sized([width, height], Label::new(msg));
|
||||||
self.node = lock!(ping).fastest.to_string();
|
ui.add_space(5.0);
|
||||||
}
|
if pinging {
|
||||||
// [Ping Button]
|
ui.add_sized([width, height], Spinner::new().size(height));
|
||||||
ui.add_enabled_ui(!lock!(ping).pinging, |ui| {
|
} else {
|
||||||
if ui.add_sized([width, height], Button::new("Ping remote nodes")).on_hover_text(P2POOL_PING).clicked() {
|
ui.add_sized([width, height], Label::new("..."));
|
||||||
Ping::spawn_thread(ping);
|
}
|
||||||
}
|
ui.add_sized([width, height], ProgressBar::new(prog.round() / 100.0));
|
||||||
});
|
ui.add_space(5.0);
|
||||||
// [Last <-]
|
});
|
||||||
if ui.add_sized([width, height], Button::new("⬅ Last")).on_hover_text(P2POOL_SELECT_LAST).clicked() {
|
});
|
||||||
let ping = lock!(ping);
|
|
||||||
match ping.pinged {
|
|
||||||
true => self.node = RemoteNode::get_last_from_ping(&self.node, &ping.nodes),
|
|
||||||
false => self.node = RemoteNode::get_last(&self.node),
|
|
||||||
}
|
|
||||||
drop(ping);
|
|
||||||
}
|
|
||||||
// [Next ->]
|
|
||||||
if ui.add_sized([width, height], Button::new("Next ➡")).on_hover_text(P2POOL_SELECT_NEXT).clicked() {
|
|
||||||
let ping = lock!(ping);
|
|
||||||
match ping.pinged {
|
|
||||||
true => self.node = RemoteNode::get_next_from_ping(&self.node, &ping.nodes),
|
|
||||||
false => self.node = RemoteNode::get_next(&self.node),
|
|
||||||
}
|
|
||||||
drop(ping);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
debug!("P2Pool Tab | Rendering [Auto-*] buttons");
|
||||||
let height = height / 2.0;
|
ui.group(|ui| {
|
||||||
let pinging = lock!(ping).pinging;
|
ui.horizontal(|ui| {
|
||||||
ui.set_enabled(pinging);
|
let width = (width / 3.0) - (SPACE * 1.75);
|
||||||
let prog = lock!(ping).prog.round();
|
// [Auto-node]
|
||||||
let msg = RichText::new(format!("{} ... {}%", lock!(ping).msg, prog));
|
ui.add_sized(
|
||||||
let height = height / 1.25;
|
[width, height],
|
||||||
ui.add_space(5.0);
|
Checkbox::new(&mut self.auto_select, "Auto-select"),
|
||||||
ui.add_sized([width, height], Label::new(msg));
|
)
|
||||||
ui.add_space(5.0);
|
.on_hover_text(P2POOL_AUTO_SELECT);
|
||||||
if pinging {
|
ui.separator();
|
||||||
ui.add_sized([width, height], Spinner::new().size(height));
|
// [Auto-node]
|
||||||
} else {
|
ui.add_sized(
|
||||||
ui.add_sized([width, height], Label::new("..."));
|
[width, height],
|
||||||
}
|
Checkbox::new(&mut self.auto_ping, "Auto-ping"),
|
||||||
ui.add_sized([width, height], ProgressBar::new(prog.round()/100.0));
|
)
|
||||||
ui.add_space(5.0);
|
.on_hover_text(P2POOL_AUTO_NODE);
|
||||||
});
|
ui.separator();
|
||||||
});
|
// [Backup host]
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Checkbox::new(&mut self.backup_host, "Backup host"),
|
||||||
|
)
|
||||||
|
.on_hover_text(P2POOL_BACKUP_HOST_SIMPLE);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
debug!("P2Pool Tab | Rendering [Auto-*] buttons");
|
debug!("P2Pool Tab | Rendering warning text");
|
||||||
ui.group(|ui| {
|
ui.add_sized([width, height/2.0], Hyperlink::from_label_and_url("WARNING: It is recommended to run/use your own Monero Node (hover for details)", "https://github.com/hinto-janai/gupax#running-a-local-monero-node")).on_hover_text(P2POOL_COMMUNITY_NODE_WARNING);
|
||||||
ui.horizontal(|ui| {
|
|
||||||
let width = (width/3.0)-(SPACE*1.75);
|
|
||||||
// [Auto-node]
|
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_select, "Auto-select")).on_hover_text(P2POOL_AUTO_SELECT);
|
|
||||||
ui.separator();
|
|
||||||
// [Auto-node]
|
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_ping, "Auto-ping")).on_hover_text(P2POOL_AUTO_NODE);
|
|
||||||
ui.separator();
|
|
||||||
// [Backup host]
|
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.backup_host, "Backup host")).on_hover_text(P2POOL_BACKUP_HOST_SIMPLE);
|
|
||||||
})});
|
|
||||||
|
|
||||||
debug!("P2Pool Tab | Rendering warning text");
|
//---------------------------------------------------------------------------------------------------- Advanced
|
||||||
ui.add_sized([width, height/2.0], Hyperlink::from_label_and_url("WARNING: It is recommended to run/use your own Monero Node (hover for details)", "https://github.com/hinto-janai/gupax#running-a-local-monero-node")).on_hover_text(P2POOL_COMMUNITY_NODE_WARNING);
|
} else {
|
||||||
|
debug!("P2Pool Tab | Rendering [Node List] elements");
|
||||||
//---------------------------------------------------------------------------------------------------- Advanced
|
let mut incorrect_input = false; // This will disable [Add/Delete] on bad input
|
||||||
} else {
|
// [Monero node IP/RPC/ZMQ]
|
||||||
debug!("P2Pool Tab | Rendering [Node List] elements");
|
ui.horizontal(|ui| {
|
||||||
let mut incorrect_input = false; // This will disable [Add/Delete] on bad input
|
|
||||||
// [Monero node IP/RPC/ZMQ]
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = width/10.0;
|
let width = width/10.0;
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
|
@ -466,49 +538,84 @@ pub fn show(
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ui.add_space(5.0);
|
ui.add_space(5.0);
|
||||||
|
|
||||||
debug!("P2Pool Tab | Rendering [Main/Mini/Peers/Log] elements");
|
debug!("P2Pool Tab | Rendering [Main/Mini/Peers/Log] elements");
|
||||||
// [Main/Mini]
|
// [Main/Mini]
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let height = height/4.0;
|
let height = height / 4.0;
|
||||||
ui.group(|ui| { ui.horizontal(|ui| {
|
ui.group(|ui| {
|
||||||
let width = (width/4.0)-SPACE;
|
ui.horizontal(|ui| {
|
||||||
let height = height + 6.0;
|
let width = (width / 4.0) - SPACE;
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(!self.mini, "P2Pool Main")).on_hover_text(P2POOL_MAIN).clicked() { self.mini = false; }
|
let height = height + 6.0;
|
||||||
if ui.add_sized([width, height], SelectableLabel::new(self.mini, "P2Pool Mini")).on_hover_text(P2POOL_MINI).clicked() { self.mini = true; }
|
if ui
|
||||||
})});
|
.add_sized(
|
||||||
// [Out/In Peers] + [Log Level]
|
[width, height],
|
||||||
ui.group(|ui| { ui.vertical(|ui| {
|
SelectableLabel::new(!self.mini, "P2Pool Main"),
|
||||||
let text = (ui.available_width()/10.0)-SPACE;
|
)
|
||||||
let width = (text*8.0)-SPACE;
|
.on_hover_text(P2POOL_MAIN)
|
||||||
let height = height/3.0;
|
.clicked()
|
||||||
ui.style_mut().spacing.slider_width = width/1.1;
|
{
|
||||||
ui.style_mut().spacing.interact_size.y = height;
|
self.mini = false;
|
||||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
}
|
||||||
ui.horizontal(|ui| {
|
if ui
|
||||||
ui.add_sized([text, height], Label::new("Out peers [10-450]:"));
|
.add_sized(
|
||||||
ui.add_sized([width, height], Slider::new(&mut self.out_peers, 10..=450)).on_hover_text(P2POOL_OUT);
|
[width, height],
|
||||||
ui.add_space(ui.available_width()-4.0);
|
SelectableLabel::new(self.mini, "P2Pool Mini"),
|
||||||
});
|
)
|
||||||
ui.horizontal(|ui| {
|
.on_hover_text(P2POOL_MINI)
|
||||||
ui.add_sized([text, height], Label::new(" In peers [10-450]:"));
|
.clicked()
|
||||||
ui.add_sized([width, height], Slider::new(&mut self.in_peers, 10..=450)).on_hover_text(P2POOL_IN);
|
{
|
||||||
});
|
self.mini = true;
|
||||||
ui.horizontal(|ui| {
|
}
|
||||||
ui.add_sized([text, height], Label::new(" Log level [0-6]:"));
|
})
|
||||||
ui.add_sized([width, height], Slider::new(&mut self.log_level, 0..=6)).on_hover_text(P2POOL_LOG);
|
});
|
||||||
});
|
// [Out/In Peers] + [Log Level]
|
||||||
})});
|
ui.group(|ui| {
|
||||||
});
|
ui.vertical(|ui| {
|
||||||
|
let text = (ui.available_width() / 10.0) - SPACE;
|
||||||
|
let width = (text * 8.0) - SPACE;
|
||||||
|
let height = height / 3.0;
|
||||||
|
ui.style_mut().spacing.slider_width = width / 1.1;
|
||||||
|
ui.style_mut().spacing.interact_size.y = height;
|
||||||
|
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.add_sized([text, height], Label::new("Out peers [10-450]:"));
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Slider::new(&mut self.out_peers, 10..=450),
|
||||||
|
)
|
||||||
|
.on_hover_text(P2POOL_OUT);
|
||||||
|
ui.add_space(ui.available_width() - 4.0);
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.add_sized([text, height], Label::new(" In peers [10-450]:"));
|
||||||
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
Slider::new(&mut self.in_peers, 10..=450),
|
||||||
|
)
|
||||||
|
.on_hover_text(P2POOL_IN);
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.add_sized([text, height], Label::new(" Log level [0-6]:"));
|
||||||
|
ui.add_sized([width, height], Slider::new(&mut self.log_level, 0..=6))
|
||||||
|
.on_hover_text(P2POOL_LOG);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
debug!("P2Pool Tab | Rendering Backup host button");
|
debug!("P2Pool Tab | Rendering Backup host button");
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = width - SPACE;
|
let width = width - SPACE;
|
||||||
let height = ui.available_height() / 3.0;
|
let height = ui.available_height() / 3.0;
|
||||||
// [Backup host]
|
// [Backup host]
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.backup_host, "Backup host")).on_hover_text(P2POOL_BACKUP_HOST_ADVANCED);
|
ui.add_sized(
|
||||||
});
|
[width, height],
|
||||||
}
|
Checkbox::new(&mut self.backup_host, "Backup host"),
|
||||||
}
|
)
|
||||||
|
.on_hover_text(P2POOL_BACKUP_HOST_ADVANCED);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
56
src/panic.rs
56
src/panic.rs
|
@ -1,26 +1,20 @@
|
||||||
//---------------------------------------------------------------------------------------------------- Use
|
//---------------------------------------------------------------------------------------------------- Use
|
||||||
use crate::constants::{
|
use crate::constants::{COMMIT, GUPAX_VERSION, OS_NAME, P2POOL_VERSION, XMRIG_VERSION};
|
||||||
GUPAX_VERSION,
|
|
||||||
P2POOL_VERSION,
|
|
||||||
XMRIG_VERSION,
|
|
||||||
OS_NAME,
|
|
||||||
COMMIT,
|
|
||||||
};
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
/// Set custom panic hook.
|
/// Set custom panic hook.
|
||||||
pub(crate) fn set_panic_hook(now: std::time::Instant) {
|
pub(crate) fn set_panic_hook(now: std::time::Instant) {
|
||||||
std::panic::set_hook(Box::new(move |panic_info| {
|
std::panic::set_hook(Box::new(move |panic_info| {
|
||||||
// Set stack-trace.
|
// Set stack-trace.
|
||||||
let stack_trace = std::backtrace::Backtrace::force_capture();
|
let stack_trace = std::backtrace::Backtrace::force_capture();
|
||||||
let args = std::env::args_os();
|
let args = std::env::args_os();
|
||||||
let uptime = now.elapsed().as_secs_f32();
|
let uptime = now.elapsed().as_secs_f32();
|
||||||
|
|
||||||
// Re-format panic info.
|
// Re-format panic info.
|
||||||
let panic_info = format!(
|
let panic_info = format!(
|
||||||
"{panic_info:#?}
|
"{panic_info:#?}
|
||||||
|
|
||||||
info:
|
info:
|
||||||
OS | {OS_NAME}
|
OS | {OS_NAME}
|
||||||
|
@ -32,21 +26,23 @@ info:
|
||||||
uptime | {uptime} seconds
|
uptime | {uptime} seconds
|
||||||
|
|
||||||
stack backtrace:\n{stack_trace}",
|
stack backtrace:\n{stack_trace}",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attempt to write panic info to disk.
|
// Attempt to write panic info to disk.
|
||||||
match crate::disk::get_gupax_data_path() {
|
match crate::disk::get_gupax_data_path() {
|
||||||
Ok(mut path) => {
|
Ok(mut path) => {
|
||||||
path.push("crash.txt");
|
path.push("crash.txt");
|
||||||
match std::fs::write(&path, &panic_info) {
|
match std::fs::write(&path, &panic_info) {
|
||||||
Ok(_) => eprintln!("\nmass_panic!() - Saved panic log to: {}\n", path.display()),
|
Ok(_) => {
|
||||||
Err(e) => eprintln!("\nmass_panic!() - Could not save panic log: {e}\n"),
|
eprintln!("\nmass_panic!() - Saved panic log to: {}\n", path.display())
|
||||||
}
|
}
|
||||||
},
|
Err(e) => eprintln!("\nmass_panic!() - Could not save panic log: {e}\n"),
|
||||||
Err(e) => eprintln!("panic_hook PATH error: {e}"),
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => eprintln!("panic_hook PATH error: {e}"),
|
||||||
|
}
|
||||||
|
|
||||||
// Exit all threads.
|
// Exit all threads.
|
||||||
benri::mass_panic!(panic_info);
|
benri::mass_panic!(panic_info);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
213
src/regex.rs
213
src/regex.rs
|
@ -17,48 +17,51 @@
|
||||||
|
|
||||||
// Some regexes used throughout Gupax.
|
// Some regexes used throughout Gupax.
|
||||||
|
|
||||||
use regex::Regex;
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Lazy
|
//---------------------------------------------------------------------------------------------------- Lazy
|
||||||
pub static REGEXES: Lazy<Regexes> = Lazy::new(|| Regexes::new());
|
pub static REGEXES: Lazy<Regexes> = Lazy::new(|| Regexes::new());
|
||||||
pub static P2POOL_REGEX: Lazy<P2poolRegex> = Lazy::new(|| P2poolRegex::new());
|
pub static P2POOL_REGEX: Lazy<P2poolRegex> = Lazy::new(|| P2poolRegex::new());
|
||||||
pub static XMRIG_REGEX: Lazy<XmrigRegex> = Lazy::new(|| XmrigRegex::new());
|
pub static XMRIG_REGEX: Lazy<XmrigRegex> = Lazy::new(|| XmrigRegex::new());
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- [Regexes] struct
|
//---------------------------------------------------------------------------------------------------- [Regexes] struct
|
||||||
// General purpose Regexes, mostly used in the GUI.
|
// General purpose Regexes, mostly used in the GUI.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Regexes {
|
pub struct Regexes {
|
||||||
pub name: Regex,
|
pub name: Regex,
|
||||||
pub address: Regex,
|
pub address: Regex,
|
||||||
pub ipv4: Regex,
|
pub ipv4: Regex,
|
||||||
pub domain: Regex,
|
pub domain: Regex,
|
||||||
pub port: Regex,
|
pub port: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Regexes {
|
impl Regexes {
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: Regex::new("^[A-Za-z0-9-_.]+( [A-Za-z0-9-_.]+)*$").unwrap(),
|
name: Regex::new("^[A-Za-z0-9-_.]+( [A-Za-z0-9-_.]+)*$").unwrap(),
|
||||||
address: Regex::new("^4[A-Za-z1-9]+$").unwrap(), // This still needs to check for (l, I, o, 0)
|
address: Regex::new("^4[A-Za-z1-9]+$").unwrap(), // This still needs to check for (l, I, o, 0)
|
||||||
ipv4: Regex::new(r#"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"#).unwrap(),
|
ipv4: Regex::new(r#"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"#).unwrap(),
|
||||||
domain: Regex::new(r#"^[A-Za-z0-9-.]+[A-Za-z0-9-]+$"#).unwrap(),
|
domain: Regex::new(r#"^[A-Za-z0-9-.]+[A-Za-z0-9-]+$"#).unwrap(),
|
||||||
port: Regex::new(r#"^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"#).unwrap(),
|
port: Regex::new(r#"^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"#).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
// Check if a Monero address is correct.
|
// Check if a Monero address is correct.
|
||||||
// This actually only checks for length & Base58, and doesn't do any checksum validation
|
// This actually only checks for length & Base58, and doesn't do any checksum validation
|
||||||
// (the last few bytes of a Monero address are a Keccak hash checksum) so some invalid addresses can trick this function.
|
// (the last few bytes of a Monero address are a Keccak hash checksum) so some invalid addresses can trick this function.
|
||||||
pub fn addr_ok(address: &str) -> bool {
|
pub fn addr_ok(address: &str) -> bool {
|
||||||
address.len() == 95 && REGEXES.address.is_match(address) && !address.contains('0') && !address.contains('O') && !address.contains('l')
|
address.len() == 95
|
||||||
}
|
&& REGEXES.address.is_match(address)
|
||||||
|
&& !address.contains('0')
|
||||||
|
&& !address.contains('O')
|
||||||
|
&& !address.contains('l')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- [P2poolRegex]
|
//---------------------------------------------------------------------------------------------------- [P2poolRegex]
|
||||||
// Meant for parsing the output of P2Pool and finding payouts and total XMR found.
|
// Meant for parsing the output of P2Pool and finding payouts and total XMR found.
|
||||||
// Why Regex instead of the standard library?
|
// Why Regex instead of the standard library?
|
||||||
|
@ -76,102 +79,114 @@ impl Regexes {
|
||||||
// let n = regex.find_iter(P2POOL_OUTPUT).count();
|
// let n = regex.find_iter(P2POOL_OUTPUT).count();
|
||||||
//
|
//
|
||||||
// Both are nominally fast enough where it doesn't matter too much but meh, why not use regex.
|
// Both are nominally fast enough where it doesn't matter too much but meh, why not use regex.
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct P2poolRegex {
|
pub struct P2poolRegex {
|
||||||
pub date: Regex,
|
pub date: Regex,
|
||||||
pub payout: Regex,
|
pub payout: Regex,
|
||||||
pub payout_float: Regex,
|
pub payout_float: Regex,
|
||||||
pub block: Regex,
|
pub block: Regex,
|
||||||
pub block_int: Regex,
|
pub block_int: Regex,
|
||||||
pub block_comma: Regex,
|
pub block_comma: Regex,
|
||||||
pub synchronized: Regex,
|
pub synchronized: Regex,
|
||||||
pub next_height_1: Regex,
|
pub next_height_1: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl P2poolRegex {
|
impl P2poolRegex {
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
date: Regex::new("[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+").unwrap(),
|
date: Regex::new("[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+").unwrap(),
|
||||||
payout: Regex::new("payout of [0-9].[0-9]+ XMR").unwrap(), // Assumes 12 digits after the dot.
|
payout: Regex::new("payout of [0-9].[0-9]+ XMR").unwrap(), // Assumes 12 digits after the dot.
|
||||||
payout_float: Regex::new("[0-9].[0-9]{12}").unwrap(), // Assumes 12 digits after the dot.
|
payout_float: Regex::new("[0-9].[0-9]{12}").unwrap(), // Assumes 12 digits after the dot.
|
||||||
block: Regex::new("block [0-9]{7}").unwrap(), // Monero blocks will be 7 digits for... the next 10,379 years
|
block: Regex::new("block [0-9]{7}").unwrap(), // Monero blocks will be 7 digits for... the next 10,379 years
|
||||||
block_int: Regex::new("[0-9]{7}").unwrap(),
|
block_int: Regex::new("[0-9]{7}").unwrap(),
|
||||||
block_comma: Regex::new("[0-9],[0-9]{3},[0-9]{3}").unwrap(),
|
block_comma: Regex::new("[0-9],[0-9]{3},[0-9]{3}").unwrap(),
|
||||||
synchronized: Regex::new("SYNCHRONIZED").unwrap(),
|
synchronized: Regex::new("SYNCHRONIZED").unwrap(),
|
||||||
next_height_1: Regex::new("next height = 1").unwrap(),
|
next_height_1: Regex::new("next height = 1").unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- XMRig regex.
|
//---------------------------------------------------------------------------------------------------- XMRig regex.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct XmrigRegex {
|
pub struct XmrigRegex {
|
||||||
pub not_mining: Regex,
|
pub not_mining: Regex,
|
||||||
pub new_job: Regex,
|
pub new_job: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XmrigRegex {
|
impl XmrigRegex {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
not_mining: Regex::new("no active pools, stop mining").unwrap(),
|
not_mining: Regex::new("no active pools, stop mining").unwrap(),
|
||||||
new_job: Regex::new("new job").unwrap(),
|
new_job: Regex::new("new job").unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TESTS
|
//---------------------------------------------------------------------------------------------------- TESTS
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use regex::Regex;
|
use super::*;
|
||||||
use super::*;
|
use regex::Regex;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_regexes() {
|
fn build_regexes() {
|
||||||
let r = Regexes::new();
|
let r = Regexes::new();
|
||||||
assert!(Regex::is_match(&r.name, "_this_ is... a n-a-m-e."));
|
assert!(Regex::is_match(&r.name, "_this_ is... a n-a-m-e."));
|
||||||
assert!(Regex::is_match(&r.address, "44hintoFpuo3ugKfcqJvh5BmrsTRpnTasJmetKC4VXCt6QDtbHVuixdTtsm6Ptp7Y8haXnJ6j8Gj2dra8CKy5ewz7Vi9CYW"));
|
assert!(Regex::is_match(&r.address, "44hintoFpuo3ugKfcqJvh5BmrsTRpnTasJmetKC4VXCt6QDtbHVuixdTtsm6Ptp7Y8haXnJ6j8Gj2dra8CKy5ewz7Vi9CYW"));
|
||||||
assert!(Regex::is_match(&r.ipv4, "192.168.1.2"));
|
assert!(Regex::is_match(&r.ipv4, "192.168.1.2"));
|
||||||
assert!(Regex::is_match(&r.ipv4, "127.0.0.1"));
|
assert!(Regex::is_match(&r.ipv4, "127.0.0.1"));
|
||||||
assert!(Regex::is_match(&r.domain, "sub.domain.com"));
|
assert!(Regex::is_match(&r.domain, "sub.domain.com"));
|
||||||
assert!(Regex::is_match(&r.domain, "sub.domain.longtld"));
|
assert!(Regex::is_match(&r.domain, "sub.domain.longtld"));
|
||||||
assert!(Regex::is_match(&r.domain, "sub.sub.domain.longtld"));
|
assert!(Regex::is_match(&r.domain, "sub.sub.domain.longtld"));
|
||||||
assert!(Regex::is_match(&r.domain, "my.node.com"));
|
assert!(Regex::is_match(&r.domain, "my.node.com"));
|
||||||
assert!(Regex::is_match(&r.domain, "my.node.longtld"));
|
assert!(Regex::is_match(&r.domain, "my.node.longtld"));
|
||||||
assert!(Regex::is_match(&r.domain, "my.monero-node123.net"));
|
assert!(Regex::is_match(&r.domain, "my.monero-node123.net"));
|
||||||
assert!(Regex::is_match(&r.domain, "www.my-node.org"));
|
assert!(Regex::is_match(&r.domain, "www.my-node.org"));
|
||||||
assert!(Regex::is_match(&r.domain, "www.my-monero-node123.io"));
|
assert!(Regex::is_match(&r.domain, "www.my-monero-node123.io"));
|
||||||
assert!(Regex::is_match(&r.domain, "www.my-monero-node123.longtld"));
|
assert!(Regex::is_match(&r.domain, "www.my-monero-node123.longtld"));
|
||||||
assert!(Regex::is_match(&r.domain, "www.my-monero-node123.org"));
|
assert!(Regex::is_match(&r.domain, "www.my-monero-node123.org"));
|
||||||
for i in 1..=65535 {
|
for i in 1..=65535 {
|
||||||
assert!(Regex::is_match(&r.port, &i.to_string()));
|
assert!(Regex::is_match(&r.port, &i.to_string()));
|
||||||
}
|
}
|
||||||
assert!(!Regex::is_match(&r.port, "0"));
|
assert!(!Regex::is_match(&r.port, "0"));
|
||||||
assert!(!Regex::is_match(&r.port, "65536"));
|
assert!(!Regex::is_match(&r.port, "65536"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_p2pool_regex() {
|
fn build_p2pool_regex() {
|
||||||
let r = P2poolRegex::new();
|
let r = P2poolRegex::new();
|
||||||
let text = "NOTICE 2022-11-11 11:11:11.1111 P2Pool You received a payout of 0.111111111111 XMR in block 1111111";
|
let text = "NOTICE 2022-11-11 11:11:11.1111 P2Pool You received a payout of 0.111111111111 XMR in block 1111111";
|
||||||
let text2 = "2022-11-11 11:11:11.1111 | 0.111111111111 XMR | Block 1,111,111";
|
let text2 = "2022-11-11 11:11:11.1111 | 0.111111111111 XMR | Block 1,111,111";
|
||||||
let text3 = "NOTICE 2020-12-11 12:35:41.3150 SideChain SYNCHRONIZED";
|
let text3 = "NOTICE 2020-12-11 12:35:41.3150 SideChain SYNCHRONIZED";
|
||||||
assert_eq!(r.payout.find(text).unwrap().as_str(), "payout of 0.111111111111 XMR");
|
assert_eq!(
|
||||||
assert_eq!(r.payout_float.find(text).unwrap().as_str(), "0.111111111111");
|
r.payout.find(text).unwrap().as_str(),
|
||||||
assert_eq!(r.date.find(text).unwrap().as_str(), "2022-11-11 11:11:11.1111");
|
"payout of 0.111111111111 XMR"
|
||||||
assert_eq!(r.block.find(text).unwrap().as_str(), "block 1111111");
|
);
|
||||||
assert_eq!(r.block_int.find(text).unwrap().as_str(), "1111111");
|
assert_eq!(
|
||||||
assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111");
|
r.payout_float.find(text).unwrap().as_str(),
|
||||||
assert_eq!(r.synchronized.find(text3).unwrap().as_str(), "SYNCHRONIZED");
|
"0.111111111111"
|
||||||
}
|
);
|
||||||
|
assert_eq!(
|
||||||
|
r.date.find(text).unwrap().as_str(),
|
||||||
|
"2022-11-11 11:11:11.1111"
|
||||||
|
);
|
||||||
|
assert_eq!(r.block.find(text).unwrap().as_str(), "block 1111111");
|
||||||
|
assert_eq!(r.block_int.find(text).unwrap().as_str(), "1111111");
|
||||||
|
assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111");
|
||||||
|
assert_eq!(r.synchronized.find(text3).unwrap().as_str(), "SYNCHRONIZED");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_xmrig_regex() {
|
fn build_xmrig_regex() {
|
||||||
let r = XmrigRegex::new();
|
let r = XmrigRegex::new();
|
||||||
let text = "[2022-02-12 12:49:30.311] net no active pools, stop mining";
|
let text = "[2022-02-12 12:49:30.311] net no active pools, stop mining";
|
||||||
let text2 = "[2022-02-12 12:49:30.311] net new job from 192.168.2.1:3333 diff 402K algo rx/0 height 2241142 (11 tx)";
|
let text2 = "[2022-02-12 12:49:30.311] net new job from 192.168.2.1:3333 diff 402K algo rx/0 height 2241142 (11 tx)";
|
||||||
assert_eq!(r.not_mining.find(text).unwrap().as_str(), "no active pools, stop mining");
|
assert_eq!(
|
||||||
assert_eq!(r.new_job.find(text2).unwrap().as_str(), "new job");
|
r.not_mining.find(text).unwrap().as_str(),
|
||||||
}
|
"no active pools, stop mining"
|
||||||
|
);
|
||||||
|
assert_eq!(r.new_job.find(text2).unwrap().as_str(), "new job");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1254
src/status.rs
1254
src/status.rs
File diff suppressed because it is too large
Load diff
325
src/sudo.rs
325
src/sudo.rs
|
@ -19,176 +19,189 @@
|
||||||
// [zeroize] is used to wipe the memory after use.
|
// [zeroize] is used to wipe the memory after use.
|
||||||
// Only gets imported in [main.rs] for Unix.
|
// Only gets imported in [main.rs] for Unix.
|
||||||
|
|
||||||
use zeroize::Zeroize;
|
use crate::{constants::*, disk::Xmrig, macros::*, Helper, ProcessSignal};
|
||||||
use std::{
|
|
||||||
thread,
|
|
||||||
sync::{Arc,Mutex},
|
|
||||||
process::*,
|
|
||||||
io::Write,
|
|
||||||
path::PathBuf,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
Helper,
|
|
||||||
disk::Xmrig,
|
|
||||||
ProcessSignal,
|
|
||||||
constants::*,
|
|
||||||
macros::*,
|
|
||||||
};
|
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
path::PathBuf,
|
||||||
|
process::*,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
use zeroize::Zeroize;
|
||||||
|
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SudoState {
|
pub struct SudoState {
|
||||||
pub windows: bool, // If this bool is set, this struct is just a dummy so I don't have to change my type signatures :)
|
pub windows: bool, // If this bool is set, this struct is just a dummy so I don't have to change my type signatures :)
|
||||||
pub testing: bool, // Are we attempting a sudo test right now?
|
pub testing: bool, // Are we attempting a sudo test right now?
|
||||||
pub success: bool, // Was the sudo test a success?
|
pub success: bool, // Was the sudo test a success?
|
||||||
pub hide: bool, // Are we hiding the password?
|
pub hide: bool, // Are we hiding the password?
|
||||||
pub msg: String, // The message shown to the user if unsuccessful
|
pub msg: String, // The message shown to the user if unsuccessful
|
||||||
pub pass: String, // The actual password wrapped in a [SecretVec]
|
pub pass: String, // The actual password wrapped in a [SecretVec]
|
||||||
pub signal: ProcessSignal, // Main GUI will set this depending on if we want [Start] or [Restart]
|
pub signal: ProcessSignal, // Main GUI will set this depending on if we want [Start] or [Restart]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SudoState {
|
impl Default for SudoState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SudoState {
|
impl SudoState {
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
windows: true,
|
windows: true,
|
||||||
testing: false,
|
testing: false,
|
||||||
success: false,
|
success: false,
|
||||||
hide: true,
|
hide: true,
|
||||||
msg: String::new(),
|
msg: String::new(),
|
||||||
pass: String::new(),
|
pass: String::new(),
|
||||||
signal: ProcessSignal::None,
|
signal: ProcessSignal::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
windows: false,
|
windows: false,
|
||||||
testing: false,
|
testing: false,
|
||||||
success: false,
|
success: false,
|
||||||
hide: true,
|
hide: true,
|
||||||
msg: "".to_string(),
|
msg: "".to_string(),
|
||||||
pass: String::with_capacity(256),
|
pass: String::with_capacity(256),
|
||||||
signal: ProcessSignal::None,
|
signal: ProcessSignal::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
// Resets the state.
|
// Resets the state.
|
||||||
pub fn reset(state: &Arc<Mutex<Self>>) {
|
pub fn reset(state: &Arc<Mutex<Self>>) {
|
||||||
Self::wipe(state);
|
Self::wipe(state);
|
||||||
let mut state = lock!(state);
|
let mut state = lock!(state);
|
||||||
state.testing = false;
|
state.testing = false;
|
||||||
state.success = false;
|
state.success = false;
|
||||||
// state.signal = ProcessSignal::None;
|
// state.signal = ProcessSignal::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
// Swaps the pass with another 256-capacity String,
|
// Swaps the pass with another 256-capacity String,
|
||||||
// zeroizes the old and drops it.
|
// zeroizes the old and drops it.
|
||||||
pub fn wipe(state: &Arc<Mutex<Self>>) {
|
pub fn wipe(state: &Arc<Mutex<Self>>) {
|
||||||
let mut new = String::with_capacity(256);
|
let mut new = String::with_capacity(256);
|
||||||
// new is now == old, and vice-versa.
|
// new is now == old, and vice-versa.
|
||||||
std::mem::swap(&mut new, &mut lock!(state).pass);
|
std::mem::swap(&mut new, &mut lock!(state).pass);
|
||||||
// we're wiping & dropping the old pass here.
|
// we're wiping & dropping the old pass here.
|
||||||
new.zeroize();
|
new.zeroize();
|
||||||
std::mem::drop(new);
|
std::mem::drop(new);
|
||||||
info!("Sudo | Password wipe with 0's ... OK");
|
info!("Sudo | Password wipe with 0's ... OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
// Spawns a thread and tests sudo with the provided password.
|
// Spawns a thread and tests sudo with the provided password.
|
||||||
// Sudo takes the password through STDIN via [--stdin].
|
// Sudo takes the password through STDIN via [--stdin].
|
||||||
// Sets the appropriate state fields on success/failure.
|
// Sets the appropriate state fields on success/failure.
|
||||||
pub fn test_sudo(state: Arc<Mutex<Self>>, helper: &Arc<Mutex<Helper>>, xmrig: &Xmrig, path: &PathBuf) {
|
pub fn test_sudo(
|
||||||
let helper = Arc::clone(helper);
|
state: Arc<Mutex<Self>>,
|
||||||
let xmrig = xmrig.clone();
|
helper: &Arc<Mutex<Helper>>,
|
||||||
let path = path.clone();
|
xmrig: &Xmrig,
|
||||||
thread::spawn(move || {
|
path: &PathBuf,
|
||||||
// Set to testing
|
) {
|
||||||
lock!(state).testing = true;
|
let helper = Arc::clone(helper);
|
||||||
|
let xmrig = xmrig.clone();
|
||||||
|
let path = path.clone();
|
||||||
|
thread::spawn(move || {
|
||||||
|
// Set to testing
|
||||||
|
lock!(state).testing = true;
|
||||||
|
|
||||||
// Make sure sudo timestamp is reset
|
// Make sure sudo timestamp is reset
|
||||||
let reset = Command::new("sudo")
|
let reset = Command::new("sudo")
|
||||||
.arg("--reset-timestamp")
|
.arg("--reset-timestamp")
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.status();
|
.status();
|
||||||
match reset {
|
match reset {
|
||||||
Ok(_) => info!("Sudo | Resetting timestamp ... OK"),
|
Ok(_) => info!("Sudo | Resetting timestamp ... OK"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Sudo | Couldn't reset timestamp: {}", e);
|
error!("Sudo | Couldn't reset timestamp: {}", e);
|
||||||
Self::wipe(&state);
|
Self::wipe(&state);
|
||||||
lock!(state).msg = format!("Sudo error: {}", e);
|
lock!(state).msg = format!("Sudo error: {}", e);
|
||||||
lock!(state).testing = false;
|
lock!(state).testing = false;
|
||||||
return
|
return;
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn testing sudo
|
// Spawn testing sudo
|
||||||
let mut sudo = Command::new("sudo")
|
let mut sudo = Command::new("sudo")
|
||||||
.args(["--stdin", "--validate"])
|
.args(["--stdin", "--validate"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Write pass to STDIN
|
// Write pass to STDIN
|
||||||
let mut stdin = sudo.stdin.take().unwrap();
|
let mut stdin = sudo.stdin.take().unwrap();
|
||||||
stdin.write_all(lock!(state).pass.as_bytes()).unwrap();
|
stdin.write_all(lock!(state).pass.as_bytes()).unwrap();
|
||||||
drop(stdin);
|
drop(stdin);
|
||||||
|
|
||||||
// Sudo re-prompts and will hang.
|
// Sudo re-prompts and will hang.
|
||||||
// To workaround this, try checking
|
// To workaround this, try checking
|
||||||
// results for 5 seconds in a loop.
|
// results for 5 seconds in a loop.
|
||||||
for i in 1..=5 {
|
for i in 1..=5 {
|
||||||
match sudo.try_wait() {
|
match sudo.try_wait() {
|
||||||
Ok(Some(code)) => if code.success() {
|
Ok(Some(code)) => {
|
||||||
info!("Sudo | Password ... OK!");
|
if code.success() {
|
||||||
lock!(state).success = true;
|
info!("Sudo | Password ... OK!");
|
||||||
break
|
lock!(state).success = true;
|
||||||
},
|
break;
|
||||||
Ok(None) => {
|
}
|
||||||
info!("Sudo | Waiting [{}/5]...", i);
|
}
|
||||||
std::thread::sleep(SECOND);
|
Ok(None) => {
|
||||||
},
|
info!("Sudo | Waiting [{}/5]...", i);
|
||||||
Err(e) => {
|
std::thread::sleep(SECOND);
|
||||||
error!("Sudo | Couldn't reset timestamp: {}", e);
|
}
|
||||||
Self::wipe(&state);
|
Err(e) => {
|
||||||
lock!(state).msg = format!("Sudo error: {}", e);
|
error!("Sudo | Couldn't reset timestamp: {}", e);
|
||||||
lock!(state).testing = false;
|
Self::wipe(&state);
|
||||||
return
|
lock!(state).msg = format!("Sudo error: {}", e);
|
||||||
},
|
lock!(state).testing = false;
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
if let Err(e) = sudo.kill() { warn!("Sudo | Kill error (it probably already exited): {}", e); }
|
}
|
||||||
if lock!(state).success {
|
}
|
||||||
match lock!(state).signal {
|
if let Err(e) = sudo.kill() {
|
||||||
ProcessSignal::Restart => crate::helper::Helper::restart_xmrig(&helper, &xmrig, &path, Arc::clone(&state)),
|
warn!("Sudo | Kill error (it probably already exited): {}", e);
|
||||||
ProcessSignal::Stop => crate::helper::Helper::stop_xmrig(&helper),
|
}
|
||||||
_ => crate::helper::Helper::start_xmrig(&helper, &xmrig, &path, Arc::clone(&state)),
|
if lock!(state).success {
|
||||||
}
|
match lock!(state).signal {
|
||||||
} else {
|
ProcessSignal::Restart => crate::helper::Helper::restart_xmrig(
|
||||||
lock!(state).msg = "Incorrect password! (or sudo timeout)".to_string();
|
&helper,
|
||||||
Self::wipe(&state);
|
&xmrig,
|
||||||
}
|
&path,
|
||||||
lock!(state).signal = ProcessSignal::None;
|
Arc::clone(&state),
|
||||||
lock!(state).testing = false;
|
),
|
||||||
});
|
ProcessSignal::Stop => crate::helper::Helper::stop_xmrig(&helper),
|
||||||
}
|
_ => crate::helper::Helper::start_xmrig(
|
||||||
|
&helper,
|
||||||
|
&xmrig,
|
||||||
|
&path,
|
||||||
|
Arc::clone(&state),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lock!(state).msg = "Incorrect password! (or sudo timeout)".to_string();
|
||||||
|
Self::wipe(&state);
|
||||||
|
}
|
||||||
|
lock!(state).signal = ProcessSignal::None;
|
||||||
|
lock!(state).testing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1598
src/update.rs
1598
src/update.rs
File diff suppressed because it is too large
Load diff
694
src/xmr.rs
694
src/xmr.rs
|
@ -22,12 +22,8 @@
|
||||||
// These represent:
|
// These represent:
|
||||||
// "(DATE, ATOMIC_UNIT, MONERO_BLOCK)"
|
// "(DATE, ATOMIC_UNIT, MONERO_BLOCK)"
|
||||||
|
|
||||||
use crate::{
|
use crate::human::*;
|
||||||
human::*,
|
use crate::regex::P2POOL_REGEX;
|
||||||
};
|
|
||||||
use crate::regex::{
|
|
||||||
P2POOL_REGEX,
|
|
||||||
};
|
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
||||||
|
@ -41,70 +37,70 @@ use log::*;
|
||||||
// [u64] can hold max: 18_446_744_073_709_551_615 which equals to 18,446,744,073 XMR (18 billion).
|
// [u64] can hold max: 18_446_744_073_709_551_615 which equals to 18,446,744,073 XMR (18 billion).
|
||||||
// Given the constant XMR tail emission of (0.3 per minute|18 per hour|432 per day|157,680 per year)
|
// Given the constant XMR tail emission of (0.3 per minute|18 per hour|432 per day|157,680 per year)
|
||||||
// this would take: 116,976~ years to overflow.
|
// this would take: 116,976~ years to overflow.
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct AtomicUnit(u64);
|
pub struct AtomicUnit(u64);
|
||||||
|
|
||||||
impl AtomicUnit {
|
impl AtomicUnit {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self(0)
|
Self(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn from_u64(u: u64) -> Self {
|
pub const fn from_u64(u: u64) -> Self {
|
||||||
Self(u)
|
Self(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn add_u64(self, u: u64) -> Self {
|
pub const fn add_u64(self, u: u64) -> Self {
|
||||||
Self(self.0 + u)
|
Self(self.0 + u)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn add_self(self, atomic_unit: Self) -> Self {
|
pub const fn add_self(self, atomic_unit: Self) -> Self {
|
||||||
Self(self.0 + atomic_unit.0)
|
Self(self.0 + atomic_unit.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn to_u64(self) -> u64 {
|
pub const fn to_u64(self) -> u64 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::inherent_to_string_shadow_display)]
|
#[allow(clippy::inherent_to_string_shadow_display)]
|
||||||
// This is terrible but it formats it in a different way
|
// This is terrible but it formats it in a different way
|
||||||
// than `Display`, but for backwards compat, changing it
|
// than `Display`, but for backwards compat, changing it
|
||||||
// requires touching other code, so...
|
// requires touching other code, so...
|
||||||
pub fn to_string(self) -> String {
|
pub fn to_string(self) -> String {
|
||||||
self.0.to_string()
|
self.0.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sum_vec(vec: &Vec<Self>) -> Self {
|
pub fn sum_vec(vec: &Vec<Self>) -> Self {
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
for int in vec {
|
for int in vec {
|
||||||
sum += int.0;
|
sum += int.0;
|
||||||
}
|
}
|
||||||
Self(sum)
|
Self(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_f64(f: f64) -> Self {
|
pub fn from_f64(f: f64) -> Self {
|
||||||
Self((f * 1_000_000_000_000.0) as u64)
|
Self((f * 1_000_000_000_000.0) as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_f64(&self) -> f64 {
|
pub fn to_f64(&self) -> f64 {
|
||||||
self.0 as f64 / 1_000_000_000_000.0
|
self.0 as f64 / 1_000_000_000_000.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_human_number_12_point(&self) -> HumanNumber {
|
pub fn to_human_number_12_point(&self) -> HumanNumber {
|
||||||
let f = self.0 as f64 / 1_000_000_000_000.0;
|
let f = self.0 as f64 / 1_000_000_000_000.0;
|
||||||
HumanNumber::from_f64_12_point(f)
|
HumanNumber::from_f64_12_point(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_human_number_no_fmt(&self) -> HumanNumber {
|
pub fn to_human_number_no_fmt(&self) -> HumanNumber {
|
||||||
let f = self.0 as f64 / 1_000_000_000_000.0;
|
let f = self.0 as f64 / 1_000_000_000_000.0;
|
||||||
HumanNumber::from_f64_no_fmt(f)
|
HumanNumber::from_f64_no_fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Displays AtomicUnit as a real XMR floating point.
|
// Displays AtomicUnit as a real XMR floating point.
|
||||||
impl std::fmt::Display for AtomicUnit {
|
impl std::fmt::Display for AtomicUnit {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(f, "{}", Self::to_human_number_12_point(self))
|
write!(f, "{}", Self::to_human_number_12_point(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- [PayoutOrd]
|
//---------------------------------------------------------------------------------------------------- [PayoutOrd]
|
||||||
|
@ -117,301 +113,385 @@ impl std::fmt::Display for AtomicUnit {
|
||||||
// [0] = DATE
|
// [0] = DATE
|
||||||
// [1] = XMR IN ATOMIC-UNITS
|
// [1] = XMR IN ATOMIC-UNITS
|
||||||
// [2] = MONERO BLOCK
|
// [2] = MONERO BLOCK
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PayoutOrd(Vec<(String, AtomicUnit, HumanNumber)>);
|
pub struct PayoutOrd(Vec<(String, AtomicUnit, HumanNumber)>);
|
||||||
|
|
||||||
impl PayoutOrd {
|
impl PayoutOrd {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(vec![(String::from("????-??-?? ??:??:??.????"), AtomicUnit::new(), HumanNumber::unknown())])
|
Self(vec![(
|
||||||
}
|
String::from("????-??-?? ??:??:??.????"),
|
||||||
|
AtomicUnit::new(),
|
||||||
|
HumanNumber::unknown(),
|
||||||
|
)])
|
||||||
|
}
|
||||||
|
|
||||||
pub const fn from_vec(vec: Vec<(String, AtomicUnit, HumanNumber)>) -> Self {
|
pub const fn from_vec(vec: Vec<(String, AtomicUnit, HumanNumber)>) -> Self {
|
||||||
Self(vec)
|
Self(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_same(a: &Self, b: &Self) -> bool {
|
pub fn is_same(a: &Self, b: &Self) -> bool {
|
||||||
if a.0.is_empty() && b.0.is_empty() { return true }
|
if a.0.is_empty() && b.0.is_empty() {
|
||||||
if a.0.len() != b.0.len() { return false }
|
return true;
|
||||||
let mut n = 0;
|
}
|
||||||
for (date, atomic_unit, block) in &a.0 {
|
if a.0.len() != b.0.len() {
|
||||||
if *date != b.0[n].0 { return false }
|
return false;
|
||||||
if *atomic_unit != b.0[n].1 { return false }
|
}
|
||||||
if *block != b.0[n].2 { return false }
|
let mut n = 0;
|
||||||
n += 1;
|
for (date, atomic_unit, block) in &a.0 {
|
||||||
}
|
if *date != b.0[n].0 {
|
||||||
true
|
return false;
|
||||||
}
|
}
|
||||||
|
if *atomic_unit != b.0[n].1 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if *block != b.0[n].2 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
n += 1;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.0.is_empty()
|
self.0.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expected input: "NOTICE 2022-01-27 01:30:23.1377 P2Pool You received a payout of 0.000000000001 XMR in block 2642816"
|
// Expected input: "NOTICE 2022-01-27 01:30:23.1377 P2Pool You received a payout of 0.000000000001 XMR in block 2642816"
|
||||||
pub fn parse_raw_payout_line(line: &str) -> (String, AtomicUnit, HumanNumber) {
|
pub fn parse_raw_payout_line(line: &str) -> (String, AtomicUnit, HumanNumber) {
|
||||||
// Date
|
// Date
|
||||||
let date = match P2POOL_REGEX.date.find(line) {
|
let date = match P2POOL_REGEX.date.find(line) {
|
||||||
Some(date) => date.as_str().to_string(),
|
Some(date) => date.as_str().to_string(),
|
||||||
None => { error!("P2Pool | Date parse error: [{}]", line); "????-??-?? ??:??:??.????".to_string() },
|
None => {
|
||||||
};
|
error!("P2Pool | Date parse error: [{}]", line);
|
||||||
// AtomicUnit
|
"????-??-?? ??:??:??.????".to_string()
|
||||||
let atomic_unit = if let Some(word) = P2POOL_REGEX.payout.find(line) {
|
}
|
||||||
if let Some(word) = P2POOL_REGEX.payout_float.find(word.as_str()) {
|
};
|
||||||
match word.as_str().parse::<f64>() {
|
// AtomicUnit
|
||||||
Ok(au) => AtomicUnit::from_f64(au),
|
let atomic_unit = if let Some(word) = P2POOL_REGEX.payout.find(line) {
|
||||||
Err(e) => { error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line); AtomicUnit::new() },
|
if let Some(word) = P2POOL_REGEX.payout_float.find(word.as_str()) {
|
||||||
}
|
match word.as_str().parse::<f64>() {
|
||||||
} else {
|
Ok(au) => AtomicUnit::from_f64(au),
|
||||||
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
Err(e) => {
|
||||||
AtomicUnit::new()
|
error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line);
|
||||||
}
|
AtomicUnit::new()
|
||||||
} else {
|
}
|
||||||
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
}
|
||||||
AtomicUnit::new()
|
} else {
|
||||||
};
|
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
||||||
// Block
|
AtomicUnit::new()
|
||||||
let block = if let Some(word) = P2POOL_REGEX.block.find(line) {
|
}
|
||||||
if let Some(word) = P2POOL_REGEX.block_int.find(word.as_str()) {
|
} else {
|
||||||
match word.as_str().parse::<u64>() {
|
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
||||||
Ok(b) => HumanNumber::from_u64(b),
|
AtomicUnit::new()
|
||||||
Err(e) => { error!("P2Pool | Block parse error: [{}] on [{}]", e, line); HumanNumber::unknown() },
|
};
|
||||||
}
|
// Block
|
||||||
} else {
|
let block = if let Some(word) = P2POOL_REGEX.block.find(line) {
|
||||||
error!("P2Pool | Block parse error: [{}]", line);
|
if let Some(word) = P2POOL_REGEX.block_int.find(word.as_str()) {
|
||||||
HumanNumber::unknown()
|
match word.as_str().parse::<u64>() {
|
||||||
}
|
Ok(b) => HumanNumber::from_u64(b),
|
||||||
} else {
|
Err(e) => {
|
||||||
error!("P2Pool | Block parse error: [{}]", line);
|
error!("P2Pool | Block parse error: [{}] on [{}]", e, line);
|
||||||
HumanNumber::unknown()
|
HumanNumber::unknown()
|
||||||
};
|
}
|
||||||
(date, atomic_unit, block)
|
}
|
||||||
}
|
} else {
|
||||||
|
error!("P2Pool | Block parse error: [{}]", line);
|
||||||
|
HumanNumber::unknown()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error!("P2Pool | Block parse error: [{}]", line);
|
||||||
|
HumanNumber::unknown()
|
||||||
|
};
|
||||||
|
(date, atomic_unit, block)
|
||||||
|
}
|
||||||
|
|
||||||
// Expected input: "2022-01-27 01:30:23.1377 | 0.000000000001 XMR | Block 2,642,816"
|
// Expected input: "2022-01-27 01:30:23.1377 | 0.000000000001 XMR | Block 2,642,816"
|
||||||
pub fn parse_formatted_payout_line(line: &str) -> (String, AtomicUnit, HumanNumber) {
|
pub fn parse_formatted_payout_line(line: &str) -> (String, AtomicUnit, HumanNumber) {
|
||||||
// Date
|
// Date
|
||||||
let date = match P2POOL_REGEX.date.find(line) {
|
let date = match P2POOL_REGEX.date.find(line) {
|
||||||
Some(date) => date.as_str().to_string(),
|
Some(date) => date.as_str().to_string(),
|
||||||
None => { error!("P2Pool | Date parse error: [{}]", line); "????-??-?? ??:??:??.????".to_string() },
|
None => {
|
||||||
};
|
error!("P2Pool | Date parse error: [{}]", line);
|
||||||
// AtomicUnit
|
"????-??-?? ??:??:??.????".to_string()
|
||||||
let atomic_unit = if let Some(word) = P2POOL_REGEX.payout_float.find(line) {
|
}
|
||||||
match word.as_str().parse::<f64>() {
|
};
|
||||||
Ok(au) => AtomicUnit::from_f64(au),
|
// AtomicUnit
|
||||||
Err(e) => { error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line); AtomicUnit::new() },
|
let atomic_unit = if let Some(word) = P2POOL_REGEX.payout_float.find(line) {
|
||||||
}
|
match word.as_str().parse::<f64>() {
|
||||||
} else {
|
Ok(au) => AtomicUnit::from_f64(au),
|
||||||
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
Err(e) => {
|
||||||
AtomicUnit::new()
|
error!("P2Pool | AtomicUnit parse error: [{}] on [{}]", e, line);
|
||||||
};
|
AtomicUnit::new()
|
||||||
// Block
|
}
|
||||||
let block = match P2POOL_REGEX.block_comma.find(line) {
|
}
|
||||||
Some(b) => HumanNumber::from_str(b.as_str()),
|
} else {
|
||||||
None => { error!("P2Pool | Block parse error: [{}]", line); HumanNumber::unknown() },
|
error!("P2Pool | AtomicUnit parse error: [{}]", line);
|
||||||
};
|
AtomicUnit::new()
|
||||||
(date, atomic_unit, block)
|
};
|
||||||
}
|
// Block
|
||||||
|
let block = match P2POOL_REGEX.block_comma.find(line) {
|
||||||
|
Some(b) => HumanNumber::from_str(b.as_str()),
|
||||||
|
None => {
|
||||||
|
error!("P2Pool | Block parse error: [{}]", line);
|
||||||
|
HumanNumber::unknown()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
(date, atomic_unit, block)
|
||||||
|
}
|
||||||
|
|
||||||
// Takes in input of ONLY P2Pool payout logs and converts it into a usable [PayoutOrd]
|
// Takes in input of ONLY P2Pool payout logs and converts it into a usable [PayoutOrd]
|
||||||
// It expects formatted log lines like this: "2022-04-11 00:20:17.2571 | 0.001371623621 XMR | Block 2,562,511"
|
// It expects formatted log lines like this: "2022-04-11 00:20:17.2571 | 0.001371623621 XMR | Block 2,562,511"
|
||||||
// For efficiency reasons, I'd like to know the byte size
|
// For efficiency reasons, I'd like to know the byte size
|
||||||
// we should allocate for the vector so we aren't adding every loop.
|
// we should allocate for the vector so we aren't adding every loop.
|
||||||
// Given a log [str], the equation for how many bytes the final vec will be is:
|
// Given a log [str], the equation for how many bytes the final vec will be is:
|
||||||
// (BYTES_OF_DATE + BYTES OF XMR + BYTES OF BLOCK) + (SPACES, PIPES, MISC WORDS) * amount_of_lines
|
// (BYTES_OF_DATE + BYTES OF XMR + BYTES OF BLOCK) + (SPACES, PIPES, MISC WORDS) * amount_of_lines
|
||||||
// The first three are more or less constants (monero block 10m is in 10,379 years...): [23, 14, 7] (sum: 44)
|
// The first three are more or less constants (monero block 10m is in 10,379 years...): [23, 14, 7] (sum: 44)
|
||||||
// Spaces, pipes, commas and words (XMR, Block): [19]
|
// Spaces, pipes, commas and words (XMR, Block): [19]
|
||||||
// Add 7 more bytes for wrapper type overhead and it's an even [70] bytes per line.
|
// Add 7 more bytes for wrapper type overhead and it's an even [70] bytes per line.
|
||||||
pub fn update_from_payout_log(&mut self, log: &str) {
|
pub fn update_from_payout_log(&mut self, log: &str) {
|
||||||
let amount_of_lines = log.lines().count();
|
let amount_of_lines = log.lines().count();
|
||||||
let mut vec: Vec<(String, AtomicUnit, HumanNumber)> = Vec::with_capacity(70 * amount_of_lines);
|
let mut vec: Vec<(String, AtomicUnit, HumanNumber)> =
|
||||||
for line in log.lines() {
|
Vec::with_capacity(70 * amount_of_lines);
|
||||||
debug!("PayoutOrd | Parsing line: [{}]", line);
|
for line in log.lines() {
|
||||||
vec.push(Self::parse_formatted_payout_line(line));
|
debug!("PayoutOrd | Parsing line: [{}]", line);
|
||||||
}
|
vec.push(Self::parse_formatted_payout_line(line));
|
||||||
*self = Self(vec);
|
}
|
||||||
}
|
*self = Self(vec);
|
||||||
|
}
|
||||||
|
|
||||||
// Takes the wrapper types, and pushes to existing [Self]
|
// Takes the wrapper types, and pushes to existing [Self]
|
||||||
pub fn push(&mut self, date: String, atomic_unit: AtomicUnit, block: HumanNumber) {
|
pub fn push(&mut self, date: String, atomic_unit: AtomicUnit, block: HumanNumber) {
|
||||||
self.0.push((date, atomic_unit, block));
|
self.0.push((date, atomic_unit, block));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes the raw components (no wrapper types), convert them and pushes to existing [Self]
|
// Takes the raw components (no wrapper types), convert them and pushes to existing [Self]
|
||||||
pub fn push_raw(&mut self, date: &str, atomic_unit: u64, block: u64) {
|
pub fn push_raw(&mut self, date: &str, atomic_unit: u64, block: u64) {
|
||||||
let atomic_unit = AtomicUnit(atomic_unit);
|
let atomic_unit = AtomicUnit(atomic_unit);
|
||||||
let block = HumanNumber::from_u64(block);
|
let block = HumanNumber::from_u64(block);
|
||||||
self.0.push((date.to_string(), atomic_unit, block));
|
self.0.push((date.to_string(), atomic_unit, block));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn atomic_unit_sum(&self) -> AtomicUnit {
|
pub fn atomic_unit_sum(&self) -> AtomicUnit {
|
||||||
let mut sum: u64 = 0;
|
let mut sum: u64 = 0;
|
||||||
for (_, atomic_unit, _) in &self.0 {
|
for (_, atomic_unit, _) in &self.0 {
|
||||||
sum += atomic_unit.to_u64();
|
sum += atomic_unit.to_u64();
|
||||||
}
|
}
|
||||||
AtomicUnit::from_u64(sum)
|
AtomicUnit::from_u64(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort [Self] from highest payout to lowest
|
// Sort [Self] from highest payout to lowest
|
||||||
pub fn sort_payout_high_to_low(&mut self) {
|
pub fn sort_payout_high_to_low(&mut self) {
|
||||||
// This is a little confusing because wrapper types are basically 1 element tuples so:
|
// This is a little confusing because wrapper types are basically 1 element tuples so:
|
||||||
// self.0 = The [Vec] within [PayoutOrd]
|
// self.0 = The [Vec] within [PayoutOrd]
|
||||||
// b.1.0 = [b] is [(String, AtomicUnit, HumanNumber)], [.1] is the [AtomicUnit] inside it, [.0] is the [u64] inside that
|
// b.1.0 = [b] is [(String, AtomicUnit, HumanNumber)], [.1] is the [AtomicUnit] inside it, [.0] is the [u64] inside that
|
||||||
// a.1.0 = Same deal, but we compare it with the previous value (b)
|
// a.1.0 = Same deal, but we compare it with the previous value (b)
|
||||||
self.0.sort_by(|a, b| b.1.0.cmp(&a.1.0));
|
self.0.sort_by(|a, b| b.1 .0.cmp(&a.1 .0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// These sorting functions take around [0.0035~] seconds on a Ryzen 5950x
|
// These sorting functions take around [0.0035~] seconds on a Ryzen 5950x
|
||||||
// given a Vec filled with 1_000_000 elements, not bad.
|
// given a Vec filled with 1_000_000 elements, not bad.
|
||||||
pub fn sort_payout_low_to_high(&mut self) {
|
pub fn sort_payout_low_to_high(&mut self) {
|
||||||
self.0.sort_by(|a, b| a.1.0.cmp(&b.1.0));
|
self.0.sort_by(|a, b| a.1 .0.cmp(&b.1 .0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a reversed [Iter] of the [PayoutOrd]
|
// Returns a reversed [Iter] of the [PayoutOrd]
|
||||||
// This is obviously faster than actually reordering the Vec.
|
// This is obviously faster than actually reordering the Vec.
|
||||||
pub fn rev_iter(&self) -> std::iter::Rev<std::slice::Iter<'_, (String, AtomicUnit, HumanNumber)>> {
|
pub fn rev_iter(
|
||||||
self.0.iter().rev()
|
&self,
|
||||||
}
|
) -> std::iter::Rev<std::slice::Iter<'_, (String, AtomicUnit, HumanNumber)>> {
|
||||||
|
self.0.iter().rev()
|
||||||
|
}
|
||||||
|
|
||||||
// Recent <-> Oldest relies on the line order.
|
// Recent <-> Oldest relies on the line order.
|
||||||
// The raw log lines will be shown instead of this struct.
|
// The raw log lines will be shown instead of this struct.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PayoutOrd { fn default() -> Self { Self::new() } }
|
impl Default for PayoutOrd {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for PayoutOrd {
|
impl std::fmt::Display for PayoutOrd {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
for i in &self.0 {
|
for i in &self.0 {
|
||||||
writeln!(f, "{} | {} XMR | Block {}", i.0, i.1, i.2)?;
|
writeln!(f, "{} | {} XMR | Block {}", i.0, i.1, i.2)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TESTS
|
//---------------------------------------------------------------------------------------------------- TESTS
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn update_p2pool_payout_log() {
|
fn update_p2pool_payout_log() {
|
||||||
use crate::xmr::PayoutOrd;
|
use crate::xmr::PayoutOrd;
|
||||||
let log =
|
let log = r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
||||||
r#"2021-12-21 01:01:01.1111 | 0.001000000000 XMR | Block 1,234,567
|
|
||||||
2021-12-21 02:01:01.1111 | 0.002000000000 XMR | Block 2,345,678
|
2021-12-21 02:01:01.1111 | 0.002000000000 XMR | Block 2,345,678
|
||||||
2021-12-21 03:01:01.1111 | 0.003000000000 XMR | Block 3,456,789
|
2021-12-21 03:01:01.1111 | 0.003000000000 XMR | Block 3,456,789
|
||||||
"#;
|
"#;
|
||||||
let mut payout_ord = PayoutOrd::new();
|
let mut payout_ord = PayoutOrd::new();
|
||||||
println!("BEFORE: {}", payout_ord);
|
println!("BEFORE: {}", payout_ord);
|
||||||
PayoutOrd::update_from_payout_log(&mut payout_ord, log);
|
PayoutOrd::update_from_payout_log(&mut payout_ord, log);
|
||||||
println!("AFTER: {}", payout_ord);
|
println!("AFTER: {}", payout_ord);
|
||||||
assert_eq!(payout_ord.to_string(), log);
|
assert_eq!(payout_ord.to_string(), log);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push_to_payout_ord() {
|
fn push_to_payout_ord() {
|
||||||
use crate::xmr::PayoutOrd;
|
use crate::human::HumanNumber;
|
||||||
use crate::xmr::AtomicUnit;
|
use crate::xmr::AtomicUnit;
|
||||||
use crate::human::HumanNumber;
|
use crate::xmr::PayoutOrd;
|
||||||
let mut payout_ord = PayoutOrd::from_vec(vec![]);
|
let mut payout_ord = PayoutOrd::from_vec(vec![]);
|
||||||
let should_be = "2022-09-08 18:42:55.4636 | 0.000000000001 XMR | Block 2,654,321\n";
|
let should_be = "2022-09-08 18:42:55.4636 | 0.000000000001 XMR | Block 2,654,321\n";
|
||||||
println!("BEFORE: {:#?}", payout_ord);
|
println!("BEFORE: {:#?}", payout_ord);
|
||||||
payout_ord.push_raw("2022-09-08 18:42:55.4636", 1, 2654321);
|
payout_ord.push_raw("2022-09-08 18:42:55.4636", 1, 2654321);
|
||||||
println!("AFTER: {}", payout_ord);
|
println!("AFTER: {}", payout_ord);
|
||||||
println!("SHOULD_BE: {}", should_be);
|
println!("SHOULD_BE: {}", should_be);
|
||||||
assert_eq!(payout_ord.to_string(), should_be);
|
assert_eq!(payout_ord.to_string(), should_be);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sum_payout_ord_atomic_unit() {
|
fn sum_payout_ord_atomic_unit() {
|
||||||
use crate::xmr::PayoutOrd;
|
use crate::human::HumanNumber;
|
||||||
use crate::xmr::AtomicUnit;
|
use crate::xmr::AtomicUnit;
|
||||||
use crate::human::HumanNumber;
|
use crate::xmr::PayoutOrd;
|
||||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1), HumanNumber::from_u64(2654321)),
|
(
|
||||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(1), HumanNumber::from_u64(2654322)),
|
"2022-09-08 18:42:55.4636".to_string(),
|
||||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(1), HumanNumber::from_u64(2654323)),
|
AtomicUnit::from_u64(1),
|
||||||
]);
|
HumanNumber::from_u64(2654321),
|
||||||
println!("OG: {:#?}", payout_ord);
|
),
|
||||||
let sum = PayoutOrd::atomic_unit_sum(&payout_ord);
|
(
|
||||||
println!("SUM: {}", sum.to_u64());
|
"2022-09-09 16:18:26.7582".to_string(),
|
||||||
assert_eq!(sum.to_u64(), 3);
|
AtomicUnit::from_u64(1),
|
||||||
}
|
HumanNumber::from_u64(2654322),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"2022-09-10 11:15:21.1272".to_string(),
|
||||||
|
AtomicUnit::from_u64(1),
|
||||||
|
HumanNumber::from_u64(2654323),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
println!("OG: {:#?}", payout_ord);
|
||||||
|
let sum = PayoutOrd::atomic_unit_sum(&payout_ord);
|
||||||
|
println!("SUM: {}", sum.to_u64());
|
||||||
|
assert_eq!(sum.to_u64(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sort_p2pool_payout_ord() {
|
fn sort_p2pool_payout_ord() {
|
||||||
use crate::xmr::PayoutOrd;
|
use crate::human::HumanNumber;
|
||||||
use crate::xmr::AtomicUnit;
|
use crate::xmr::AtomicUnit;
|
||||||
use crate::human::HumanNumber;
|
use crate::xmr::PayoutOrd;
|
||||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1000000000), HumanNumber::from_u64(2654321)),
|
(
|
||||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(2000000000), HumanNumber::from_u64(2654322)),
|
"2022-09-08 18:42:55.4636".to_string(),
|
||||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(3000000000), HumanNumber::from_u64(2654323)),
|
AtomicUnit::from_u64(1000000000),
|
||||||
]);
|
HumanNumber::from_u64(2654321),
|
||||||
println!("OG: {:#?}", payout_ord);
|
),
|
||||||
|
(
|
||||||
|
"2022-09-09 16:18:26.7582".to_string(),
|
||||||
|
AtomicUnit::from_u64(2000000000),
|
||||||
|
HumanNumber::from_u64(2654322),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"2022-09-10 11:15:21.1272".to_string(),
|
||||||
|
AtomicUnit::from_u64(3000000000),
|
||||||
|
HumanNumber::from_u64(2654323),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
println!("OG: {:#?}", payout_ord);
|
||||||
|
|
||||||
// High to Low
|
// High to Low
|
||||||
PayoutOrd::sort_payout_high_to_low(&mut payout_ord);
|
PayoutOrd::sort_payout_high_to_low(&mut payout_ord);
|
||||||
println!("AFTER PAYOUT HIGH TO LOW: {:#?}", payout_ord);
|
println!("AFTER PAYOUT HIGH TO LOW: {:#?}", payout_ord);
|
||||||
let should_be =
|
let should_be = r#"2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
||||||
r#"2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
|
||||||
2022-09-09 16:18:26.7582 | 0.002000000000 XMR | Block 2,654,322
|
2022-09-09 16:18:26.7582 | 0.002000000000 XMR | Block 2,654,322
|
||||||
2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
||||||
"#;
|
"#;
|
||||||
println!("SHOULD_BE:\n{}", should_be);
|
println!("SHOULD_BE:\n{}", should_be);
|
||||||
println!("IS:\n{}", payout_ord);
|
println!("IS:\n{}", payout_ord);
|
||||||
assert_eq!(payout_ord.to_string(), should_be);
|
assert_eq!(payout_ord.to_string(), should_be);
|
||||||
|
|
||||||
// Low to High
|
// Low to High
|
||||||
PayoutOrd::sort_payout_low_to_high(&mut payout_ord);
|
PayoutOrd::sort_payout_low_to_high(&mut payout_ord);
|
||||||
println!("AFTER PAYOUT LOW TO HIGH: {:#?}", payout_ord);
|
println!("AFTER PAYOUT LOW TO HIGH: {:#?}", payout_ord);
|
||||||
let should_be =
|
let should_be = r#"2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
||||||
r#"2022-09-08 18:42:55.4636 | 0.001000000000 XMR | Block 2,654,321
|
|
||||||
2022-09-09 16:18:26.7582 | 0.002000000000 XMR | Block 2,654,322
|
2022-09-09 16:18:26.7582 | 0.002000000000 XMR | Block 2,654,322
|
||||||
2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
2022-09-10 11:15:21.1272 | 0.003000000000 XMR | Block 2,654,323
|
||||||
"#;
|
"#;
|
||||||
println!("SHOULD_BE:\n{}", should_be);
|
println!("SHOULD_BE:\n{}", should_be);
|
||||||
println!("IS:\n{}", payout_ord);
|
println!("IS:\n{}", payout_ord);
|
||||||
assert_eq!(payout_ord.to_string(), should_be);
|
assert_eq!(payout_ord.to_string(), should_be);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn payout_ord_is_same() {
|
fn payout_ord_is_same() {
|
||||||
use crate::xmr::PayoutOrd;
|
use crate::human::HumanNumber;
|
||||||
use crate::xmr::AtomicUnit;
|
use crate::xmr::AtomicUnit;
|
||||||
use crate::human::HumanNumber;
|
use crate::xmr::PayoutOrd;
|
||||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1000000000), HumanNumber::from_u64(2654321)),
|
(
|
||||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(2000000000), HumanNumber::from_u64(2654322)),
|
"2022-09-08 18:42:55.4636".to_string(),
|
||||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(3000000000), HumanNumber::from_u64(2654323)),
|
AtomicUnit::from_u64(1000000000),
|
||||||
]);
|
HumanNumber::from_u64(2654321),
|
||||||
let payout_ord_2 = payout_ord.clone();
|
),
|
||||||
println!("1: {:#?}", payout_ord);
|
(
|
||||||
println!("2: {:#?}", payout_ord);
|
"2022-09-09 16:18:26.7582".to_string(),
|
||||||
|
AtomicUnit::from_u64(2000000000),
|
||||||
|
HumanNumber::from_u64(2654322),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"2022-09-10 11:15:21.1272".to_string(),
|
||||||
|
AtomicUnit::from_u64(3000000000),
|
||||||
|
HumanNumber::from_u64(2654323),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
let payout_ord_2 = payout_ord.clone();
|
||||||
|
println!("1: {:#?}", payout_ord);
|
||||||
|
println!("2: {:#?}", payout_ord);
|
||||||
|
|
||||||
assert!(PayoutOrd::is_same(&payout_ord, &payout_ord_2) == true);
|
assert!(PayoutOrd::is_same(&payout_ord, &payout_ord_2) == true);
|
||||||
payout_ord.push_raw("2022-09-08 18:42:55.4636", 1000000000, 2654321);
|
payout_ord.push_raw("2022-09-08 18:42:55.4636", 1000000000, 2654321);
|
||||||
println!("1: {:#?}", payout_ord);
|
println!("1: {:#?}", payout_ord);
|
||||||
println!("2: {:#?}", payout_ord);
|
println!("2: {:#?}", payout_ord);
|
||||||
assert!(PayoutOrd::is_same(&payout_ord, &payout_ord_2) == false);
|
assert!(PayoutOrd::is_same(&payout_ord, &payout_ord_2) == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn view_reverse_payout_ord() {
|
fn view_reverse_payout_ord() {
|
||||||
use crate::xmr::PayoutOrd;
|
use crate::human::HumanNumber;
|
||||||
use crate::xmr::AtomicUnit;
|
use crate::xmr::AtomicUnit;
|
||||||
use crate::human::HumanNumber;
|
use crate::xmr::PayoutOrd;
|
||||||
let mut payout_ord = PayoutOrd::from_vec(vec![
|
let mut payout_ord = PayoutOrd::from_vec(vec![
|
||||||
("2022-09-08 18:42:55.4636".to_string(), AtomicUnit::from_u64(1000000000), HumanNumber::from_u64(2654321)),
|
(
|
||||||
("2022-09-09 16:18:26.7582".to_string(), AtomicUnit::from_u64(2000000000), HumanNumber::from_u64(2654322)),
|
"2022-09-08 18:42:55.4636".to_string(),
|
||||||
("2022-09-10 11:15:21.1272".to_string(), AtomicUnit::from_u64(3000000000), HumanNumber::from_u64(2654323)),
|
AtomicUnit::from_u64(1000000000),
|
||||||
]);
|
HumanNumber::from_u64(2654321),
|
||||||
println!("OG: {:#?}", payout_ord);
|
),
|
||||||
|
(
|
||||||
|
"2022-09-09 16:18:26.7582".to_string(),
|
||||||
|
AtomicUnit::from_u64(2000000000),
|
||||||
|
HumanNumber::from_u64(2654322),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"2022-09-10 11:15:21.1272".to_string(),
|
||||||
|
AtomicUnit::from_u64(3000000000),
|
||||||
|
HumanNumber::from_u64(2654323),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
println!("OG: {:#?}", payout_ord);
|
||||||
|
|
||||||
#[allow(clippy::never_loop)]
|
#[allow(clippy::never_loop)]
|
||||||
for (_, atomic_unit, _) in payout_ord.rev_iter() {
|
for (_, atomic_unit, _) in payout_ord.rev_iter() {
|
||||||
if atomic_unit.to_u64() == 3000000000 {
|
if atomic_unit.to_u64() == 3000000000 {
|
||||||
break
|
break;
|
||||||
} else {
|
} else {
|
||||||
println!("expected: 3000000000, found: {}", atomic_unit);
|
println!("expected: 3000000000, found: {}", atomic_unit);
|
||||||
panic!("not reversed");
|
panic!("not reversed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
445
src/xmrig.rs
445
src/xmrig.rs
|
@ -15,135 +15,178 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::regex::REGEXES;
|
||||||
Regexes,
|
use crate::{constants::*, disk::*, macros::*, Process, PubXmrigApi, Regexes};
|
||||||
constants::*,
|
|
||||||
disk::*,
|
|
||||||
Process,
|
|
||||||
PubXmrigApi,
|
|
||||||
macros::*,
|
|
||||||
};
|
|
||||||
use egui::{
|
use egui::{
|
||||||
TextEdit,SelectableLabel,ComboBox,Label,Button,RichText,Slider,Checkbox,
|
Button, Checkbox, ComboBox, Label, RichText, SelectableLabel, Slider, TextEdit, TextStyle::*,
|
||||||
TextStyle::*,
|
|
||||||
};
|
};
|
||||||
use std::{
|
|
||||||
sync::{Arc,Mutex},
|
|
||||||
};
|
|
||||||
use regex::Regex;
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use crate::regex::{
|
use regex::Regex;
|
||||||
REGEXES,
|
use std::sync::{Arc, Mutex};
|
||||||
};
|
|
||||||
|
|
||||||
impl crate::disk::Xmrig {
|
impl crate::disk::Xmrig {
|
||||||
#[inline(always)] // called once
|
#[inline(always)] // called once
|
||||||
pub fn show(
|
pub fn show(
|
||||||
&mut self,
|
&mut self,
|
||||||
pool_vec: &mut Vec<(String, Pool)>,
|
pool_vec: &mut Vec<(String, Pool)>,
|
||||||
process: &Arc<Mutex<Process>>,
|
process: &Arc<Mutex<Process>>,
|
||||||
api: &Arc<Mutex<PubXmrigApi>>,
|
api: &Arc<Mutex<PubXmrigApi>>,
|
||||||
buffer: &mut String,
|
buffer: &mut String,
|
||||||
width: f32,
|
width: f32,
|
||||||
height: f32,
|
height: f32,
|
||||||
_ctx: &egui::Context,
|
_ctx: &egui::Context,
|
||||||
ui: &mut egui::Ui
|
ui: &mut egui::Ui,
|
||||||
) {
|
) {
|
||||||
let text_edit = height / 25.0;
|
let text_edit = height / 25.0;
|
||||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||||
debug!("XMRig Tab | Rendering [Console]");
|
debug!("XMRig Tab | Rendering [Console]");
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
if self.simple {
|
if self.simple {
|
||||||
let height = height / 1.5;
|
let height = height / 1.5;
|
||||||
let width = width - SPACE;
|
let width = width - SPACE;
|
||||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
egui::ScrollArea::vertical()
|
||||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
.stick_to_bottom(true)
|
||||||
});
|
.max_width(width)
|
||||||
});
|
.max_height(height)
|
||||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
.auto_shrink([false; 2])
|
||||||
} else {
|
.show_viewport(ui, |ui, _| {
|
||||||
let height = height / 2.8;
|
ui.add_sized(
|
||||||
let width = width - SPACE;
|
[width, height],
|
||||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
);
|
||||||
egui::ScrollArea::vertical().stick_to_bottom(true).max_width(width).max_height(height).auto_shrink([false; 2]).show_viewport(ui, |ui, _| {
|
});
|
||||||
ui.add_sized([width, height], TextEdit::multiline(&mut lock!(api).output.as_str()));
|
});
|
||||||
});
|
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||||
});
|
} else {
|
||||||
ui.separator();
|
let height = height / 2.8;
|
||||||
let response = ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(buffer), r#"Commands: [h]ashrate, [p]ause, [r]esume, re[s]ults, [c]onnection"#)).on_hover_text(XMRIG_INPUT);
|
let width = width - SPACE;
|
||||||
// If the user pressed enter, dump buffer contents into the process STDIN
|
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||||
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||||
response.request_focus(); // Get focus back
|
egui::ScrollArea::vertical()
|
||||||
let buffer = std::mem::take(buffer); // Take buffer
|
.stick_to_bottom(true)
|
||||||
let mut process = lock!(process); // Lock
|
.max_width(width)
|
||||||
if process.is_alive() { process.input.push(buffer); } // Push only if alive
|
.max_height(height)
|
||||||
}
|
.auto_shrink([false; 2])
|
||||||
}
|
.show_viewport(ui, |ui, _| {
|
||||||
});
|
ui.add_sized(
|
||||||
|
[width, height],
|
||||||
|
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.separator();
|
||||||
|
let response = ui
|
||||||
|
.add_sized(
|
||||||
|
[width, text_edit],
|
||||||
|
TextEdit::hint_text(
|
||||||
|
TextEdit::singleline(buffer),
|
||||||
|
r#"Commands: [h]ashrate, [p]ause, [r]esume, re[s]ults, [c]onnection"#,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_INPUT);
|
||||||
|
// If the user pressed enter, dump buffer contents into the process STDIN
|
||||||
|
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
|
||||||
|
response.request_focus(); // Get focus back
|
||||||
|
let buffer = std::mem::take(buffer); // Take buffer
|
||||||
|
let mut process = lock!(process); // Lock
|
||||||
|
if process.is_alive() {
|
||||||
|
process.input.push(buffer);
|
||||||
|
} // Push only if alive
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Arguments
|
//---------------------------------------------------------------------------------------------------- Arguments
|
||||||
if !self.simple {
|
if !self.simple {
|
||||||
debug!("XMRig Tab | Rendering [Arguments]");
|
debug!("XMRig Tab | Rendering [Arguments]");
|
||||||
ui.group(|ui| { ui.horizontal(|ui| {
|
ui.group(|ui| {
|
||||||
let width = (width/10.0) - SPACE;
|
ui.horizontal(|ui| {
|
||||||
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
|
let width = (width / 10.0) - SPACE;
|
||||||
ui.add_sized([ui.available_width(), text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.arguments), r#"--url <...> --user <...> --config <...>"#)).on_hover_text(XMRIG_ARGUMENTS);
|
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
|
||||||
self.arguments.truncate(1024);
|
ui.add_sized(
|
||||||
})});
|
[ui.available_width(), text_edit],
|
||||||
ui.set_enabled(self.arguments.is_empty());
|
TextEdit::hint_text(
|
||||||
//---------------------------------------------------------------------------------------------------- Address
|
TextEdit::singleline(&mut self.arguments),
|
||||||
debug!("XMRig Tab | Rendering [Address]");
|
r#"--url <...> --user <...> --config <...>"#,
|
||||||
ui.group(|ui| {
|
),
|
||||||
let width = width - SPACE;
|
)
|
||||||
ui.spacing_mut().text_edit_width = (width)-(SPACE*3.0);
|
.on_hover_text(XMRIG_ARGUMENTS);
|
||||||
let text;
|
self.arguments.truncate(1024);
|
||||||
let color;
|
})
|
||||||
let len = format!("{:02}", self.address.len());
|
});
|
||||||
if self.address.is_empty() {
|
ui.set_enabled(self.arguments.is_empty());
|
||||||
text = format!("Monero Address [{}/95] ➖", len);
|
//---------------------------------------------------------------------------------------------------- Address
|
||||||
color = LIGHT_GRAY;
|
debug!("XMRig Tab | Rendering [Address]");
|
||||||
} else if Regexes::addr_ok(&self.address) {
|
ui.group(|ui| {
|
||||||
text = format!("Monero Address [{}/95] ✔", len);
|
let width = width - SPACE;
|
||||||
color = GREEN;
|
ui.spacing_mut().text_edit_width = (width) - (SPACE * 3.0);
|
||||||
} else {
|
let text;
|
||||||
text = format!("Monero Address [{}/95] ❌", len);
|
let color;
|
||||||
color = RED;
|
let len = format!("{:02}", self.address.len());
|
||||||
}
|
if self.address.is_empty() {
|
||||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
text = format!("Monero Address [{}/95] ➖", len);
|
||||||
ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4...")).on_hover_text(XMRIG_ADDRESS);
|
color = LIGHT_GRAY;
|
||||||
self.address.truncate(95);
|
} else if Regexes::addr_ok(&self.address) {
|
||||||
});
|
text = format!("Monero Address [{}/95] ✔", len);
|
||||||
}
|
color = GREEN;
|
||||||
|
} else {
|
||||||
|
text = format!("Monero Address [{}/95] ❌", len);
|
||||||
|
color = RED;
|
||||||
|
}
|
||||||
|
ui.add_sized(
|
||||||
|
[width, text_edit],
|
||||||
|
Label::new(RichText::new(text).color(color)),
|
||||||
|
);
|
||||||
|
ui.add_sized(
|
||||||
|
[width, text_edit],
|
||||||
|
TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4..."),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_ADDRESS);
|
||||||
|
self.address.truncate(95);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Threads
|
//---------------------------------------------------------------------------------------------------- Threads
|
||||||
if self.simple { ui.add_space(SPACE); }
|
if self.simple {
|
||||||
debug!("XMRig Tab | Rendering [Threads]");
|
ui.add_space(SPACE);
|
||||||
ui.vertical(|ui| {
|
}
|
||||||
let width = width / 10.0;
|
debug!("XMRig Tab | Rendering [Threads]");
|
||||||
let text_width = width * 2.4;
|
ui.vertical(|ui| {
|
||||||
ui.spacing_mut().slider_width = width * 6.5;
|
let width = width / 10.0;
|
||||||
ui.spacing_mut().icon_width = width / 25.0;
|
let text_width = width * 2.4;
|
||||||
ui.horizontal(|ui| {
|
ui.spacing_mut().slider_width = width * 6.5;
|
||||||
ui.add_sized([text_width, text_edit], Label::new(format!("Threads [1-{}]:", self.max_threads)));
|
ui.spacing_mut().icon_width = width / 25.0;
|
||||||
ui.add_sized([width, text_edit], Slider::new(&mut self.current_threads, 1..=self.max_threads)).on_hover_text(XMRIG_THREADS);
|
ui.horizontal(|ui| {
|
||||||
});
|
ui.add_sized(
|
||||||
#[cfg(not(target_os = "linux"))] // Pause on active isn't supported on Linux
|
[text_width, text_edit],
|
||||||
ui.horizontal(|ui| {
|
Label::new(format!("Threads [1-{}]:", self.max_threads)),
|
||||||
ui.add_sized([text_width, text_edit], Label::new(format!("Pause on active [0-255]:")));
|
);
|
||||||
ui.add_sized([width, text_edit], Slider::new(&mut self.pause, 0..=255)).on_hover_text(format!("{} [{}] seconds.", XMRIG_PAUSE, self.pause));
|
ui.add_sized(
|
||||||
});
|
[width, text_edit],
|
||||||
});
|
Slider::new(&mut self.current_threads, 1..=self.max_threads),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_THREADS);
|
||||||
|
});
|
||||||
|
#[cfg(not(target_os = "linux"))] // Pause on active isn't supported on Linux
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.add_sized(
|
||||||
|
[text_width, text_edit],
|
||||||
|
Label::new(format!("Pause on active [0-255]:")),
|
||||||
|
);
|
||||||
|
ui.add_sized([width, text_edit], Slider::new(&mut self.pause, 0..=255))
|
||||||
|
.on_hover_text(format!("{} [{}] seconds.", XMRIG_PAUSE, self.pause));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Simple
|
//---------------------------------------------------------------------------------------------------- Simple
|
||||||
if !self.simple {
|
if !self.simple {
|
||||||
debug!("XMRig Tab | Rendering [Pool List] elements");
|
debug!("XMRig Tab | Rendering [Pool List] elements");
|
||||||
let width = ui.available_width() - 10.0;
|
let width = ui.available_width() - 10.0;
|
||||||
let mut incorrect_input = false; // This will disable [Add/Delete] on bad input
|
let mut incorrect_input = false; // This will disable [Add/Delete] on bad input
|
||||||
// [Pool IP/Port]
|
// [Pool IP/Port]
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
let width = width/10.0;
|
let width = width/10.0;
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
|
@ -353,77 +396,97 @@ pub fn show(
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ui.add_space(5.0);
|
ui.add_space(5.0);
|
||||||
|
|
||||||
debug!("XMRig Tab | Rendering [API] TextEdits");
|
debug!("XMRig Tab | Rendering [API] TextEdits");
|
||||||
// [HTTP API IP/Port]
|
// [HTTP API IP/Port]
|
||||||
ui.group(|ui| { ui.horizontal(|ui| {
|
ui.group(|ui| {
|
||||||
ui.vertical(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let width = width/10.0;
|
ui.vertical(|ui| {
|
||||||
ui.spacing_mut().text_edit_width = width*2.39;
|
let width = width / 10.0;
|
||||||
// HTTP API
|
ui.spacing_mut().text_edit_width = width * 2.39;
|
||||||
ui.horizontal(|ui| {
|
// HTTP API
|
||||||
let text;
|
ui.horizontal(|ui| {
|
||||||
let color;
|
let text;
|
||||||
let len = format!("{:03}", self.api_ip.len());
|
let color;
|
||||||
if self.api_ip.is_empty() {
|
let len = format!("{:03}", self.api_ip.len());
|
||||||
text = format!("HTTP API IP [{}/255]➖", len);
|
if self.api_ip.is_empty() {
|
||||||
color = LIGHT_GRAY;
|
text = format!("HTTP API IP [{}/255]➖", len);
|
||||||
incorrect_input = true;
|
color = LIGHT_GRAY;
|
||||||
} else if self.api_ip == "localhost" || REGEXES.ipv4.is_match(&self.api_ip) || REGEXES.domain.is_match(&self.api_ip) {
|
incorrect_input = true;
|
||||||
text = format!("HTTP API IP [{}/255]✔", len);
|
} else if self.api_ip == "localhost"
|
||||||
color = GREEN;
|
|| REGEXES.ipv4.is_match(&self.api_ip)
|
||||||
} else {
|
|| REGEXES.domain.is_match(&self.api_ip)
|
||||||
text = format!("HTTP API IP [{}/255]❌", len);
|
{
|
||||||
color = RED;
|
text = format!("HTTP API IP [{}/255]✔", len);
|
||||||
incorrect_input = true;
|
color = GREEN;
|
||||||
}
|
} else {
|
||||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
text = format!("HTTP API IP [{}/255]❌", len);
|
||||||
ui.text_edit_singleline(&mut self.api_ip).on_hover_text(XMRIG_API_IP);
|
color = RED;
|
||||||
self.api_ip.truncate(255);
|
incorrect_input = true;
|
||||||
});
|
}
|
||||||
ui.horizontal(|ui| {
|
ui.add_sized(
|
||||||
let text;
|
[width, text_edit],
|
||||||
let color;
|
Label::new(RichText::new(text).color(color)),
|
||||||
let len = self.api_port.len();
|
);
|
||||||
if self.api_port.is_empty() {
|
ui.text_edit_singleline(&mut self.api_ip)
|
||||||
text = format!("HTTP API Port [ {}/5 ]➖", len);
|
.on_hover_text(XMRIG_API_IP);
|
||||||
color = LIGHT_GRAY;
|
self.api_ip.truncate(255);
|
||||||
incorrect_input = true;
|
});
|
||||||
} else if REGEXES.port.is_match(&self.api_port) {
|
ui.horizontal(|ui| {
|
||||||
text = format!("HTTP API Port [ {}/5 ]✔", len);
|
let text;
|
||||||
color = GREEN;
|
let color;
|
||||||
} else {
|
let len = self.api_port.len();
|
||||||
text = format!("HTTP API Port [ {}/5 ]❌", len);
|
if self.api_port.is_empty() {
|
||||||
color = RED;
|
text = format!("HTTP API Port [ {}/5 ]➖", len);
|
||||||
incorrect_input = true;
|
color = LIGHT_GRAY;
|
||||||
}
|
incorrect_input = true;
|
||||||
ui.add_sized([width, text_edit], Label::new(RichText::new(text).color(color)));
|
} else if REGEXES.port.is_match(&self.api_port) {
|
||||||
ui.text_edit_singleline(&mut self.api_port).on_hover_text(XMRIG_API_PORT);
|
text = format!("HTTP API Port [ {}/5 ]✔", len);
|
||||||
self.api_port.truncate(5);
|
color = GREEN;
|
||||||
});
|
} else {
|
||||||
});
|
text = format!("HTTP API Port [ {}/5 ]❌", len);
|
||||||
|
color = RED;
|
||||||
|
incorrect_input = true;
|
||||||
|
}
|
||||||
|
ui.add_sized(
|
||||||
|
[width, text_edit],
|
||||||
|
Label::new(RichText::new(text).color(color)),
|
||||||
|
);
|
||||||
|
ui.text_edit_singleline(&mut self.api_port)
|
||||||
|
.on_hover_text(XMRIG_API_PORT);
|
||||||
|
self.api_port.truncate(5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
debug!("XMRig Tab | Rendering [TLS/Keepalive] buttons");
|
debug!("XMRig Tab | Rendering [TLS/Keepalive] buttons");
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
// TLS/Keepalive
|
// TLS/Keepalive
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let width = (ui.available_width()/2.0)-11.0;
|
let width = (ui.available_width() / 2.0) - 11.0;
|
||||||
let height = text_edit*2.0;
|
let height = text_edit * 2.0;
|
||||||
// let mut style = (*ctx.style()).clone();
|
// let mut style = (*ctx.style()).clone();
|
||||||
// style.spacing.icon_width_inner = width / 8.0;
|
// style.spacing.icon_width_inner = width / 8.0;
|
||||||
// style.spacing.icon_width = width / 6.0;
|
// style.spacing.icon_width = width / 6.0;
|
||||||
// style.spacing.icon_spacing = 20.0;
|
// style.spacing.icon_spacing = 20.0;
|
||||||
// ctx.set_style(style);
|
// ctx.set_style(style);
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.tls, "TLS Connection")).on_hover_text(XMRIG_TLS);
|
ui.add_sized(
|
||||||
ui.separator();
|
[width, height],
|
||||||
ui.add_sized([width, height], Checkbox::new(&mut self.keepalive, "Keepalive")).on_hover_text(XMRIG_KEEPALIVE);
|
Checkbox::new(&mut self.tls, "TLS Connection"),
|
||||||
});
|
)
|
||||||
});
|
.on_hover_text(XMRIG_TLS);
|
||||||
});
|
ui.separator();
|
||||||
});
|
ui.add_sized(
|
||||||
}
|
[width, height],
|
||||||
}
|
Checkbox::new(&mut self.keepalive, "Keepalive"),
|
||||||
|
)
|
||||||
|
.on_hover_text(XMRIG_KEEPALIVE);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue