Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mmrrnn committed Jul 30, 2024
1 parent c1e27fb commit dde7742
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 40 deletions.
13 changes: 7 additions & 6 deletions src-tauri/src/binary_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ impl LatestVersionApiAdapter for GithubReleasesAdapter {
let version = releases
.iter()
.filter_map(|v| {

if v.version.pre.starts_with(network) {

Some(&v.version)
} else {
None
Expand Down Expand Up @@ -106,7 +104,7 @@ impl LatestVersionApiAdapter for GithubReleasesAdapter {
let name_suffix = "macos-arm64.zip";
#[cfg(target_os = "linux")]
let name_suffix = "linux-x86_64.zip";

let platform = version
.assets
.iter()
Expand Down Expand Up @@ -217,15 +215,18 @@ impl BinaryResolver {
let in_progress_file_zip = in_progress_dir.join(&asset.name);
download_file(&asset.url, &in_progress_file_zip).await?;

let in_progress_file_sha256 = in_progress_dir.clone().join(format!("{}.sha256", asset.name));
let in_progress_file_sha256 = in_progress_dir
.clone()
.join(format!("{}.sha256", asset.name));
let asset_sha256_url = format!("{}.sha256", asset.url.clone());
download_file(&asset_sha256_url, &in_progress_file_sha256).await?;

let is_sha_validated = validate_checksum(
in_progress_file_zip.clone(),
in_progress_file_sha256.clone(),
asset.name.clone()
).await?;
asset.name.clone(),
)
.await?;
if is_sha_validated {
println!("Renaming & Extracting file");
let bin_dir = adapter
Expand Down
11 changes: 5 additions & 6 deletions src-tauri/src/cpu_miner.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use sysinfo::{CpuRefreshKind, RefreshKind, System};
use crate::mm_proxy_manager::MmProxyManager;
use crate::xmrig::http_api::XmrigHttpApiClient;
use crate::xmrig_adapter::{XmrigAdapter, XmrigNodeConnection};
use crate::{CpuMinerConfig, CpuMinerConnection, CpuMinerConnectionStatus, CpuMinerStatus};
use sysinfo::{CpuRefreshKind, RefreshKind, System};
use tari_shutdown::{Shutdown, ShutdownSignal};
use tauri::async_runtime::JoinHandle;
use tokio::select;
Expand Down Expand Up @@ -126,13 +126,12 @@ impl CpuMiner {
}

pub async fn status(&self) -> Result<CpuMinerStatus, anyhow::Error> {
let mut s = System::new_with_specifics(
RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
let mut s =
System::new_with_specifics(RefreshKind::new().with_cpu(CpuRefreshKind::everything()));

// Wait a bit because CPU usage is based on diff.
// Wait a bit because CPU usage is based on diff.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
// Refresh CPUs again.
// Refresh CPUs again.
s.refresh_cpu();

let mut cpu_usage = s.global_cpu_info().cpu_usage();
Expand Down
14 changes: 9 additions & 5 deletions src-tauri/src/download_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ use anyhow::{anyhow, Error};
use async_zip::base::read::seek::ZipFileReader;
use flate2::read::GzDecoder;
use futures_util::StreamExt;
use regex::Regex;
use sha2::{Digest, Sha256};
use std::path::{Path, PathBuf};
use tar::Archive;
use tokio::fs;
use tokio::fs::{File, OpenOptions};
use tokio::io::AsyncReadExt;
use tokio::io::{AsyncWriteExt, BufReader};
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
use sha2::{Sha256, Digest};
use regex::Regex;
use tokio::io::AsyncReadExt;

// Taken from async_zip example

Expand Down Expand Up @@ -128,7 +128,11 @@ pub async fn set_permissions(file_path: &Path) -> Result<(), anyhow::Error> {
Ok(())
}

pub async fn validate_checksum(file_path: PathBuf, file_sha256_path: PathBuf, asset_name: String) -> Result<bool, Error> {
pub async fn validate_checksum(
file_path: PathBuf,
file_sha256_path: PathBuf,
asset_name: String,
) -> Result<bool, Error> {
let mut file_sha256 = File::open(file_sha256_path.clone()).await?;
let mut buffer_sha256 = Vec::new();
file_sha256.read_to_end(&mut buffer_sha256).await?;
Expand All @@ -151,6 +155,6 @@ pub async fn validate_checksum(file_path: PathBuf, file_sha256_path: PathBuf, as
hasher.update(&buffer);
let hash = hasher.finalize();
let hash_hex = format!("{:x}", hash);

Ok(hash_hex == expected_hash)
}
6 changes: 3 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ async fn start_mining<'r>(
.cpu_miner
.write()
.await
.start(state.shutdown.to_signal(), &config, &mm_proxy_manager).await
.start(state.shutdown.to_signal(), &config, &mm_proxy_manager)
.await
.map_err(|e| {
dbg!(e.to_string());
e.to_string()
Expand Down Expand Up @@ -83,7 +84,6 @@ async fn status(state: tauri::State<'_, UniverseAppState>) -> Result<AppStatus,
eprintln!("Error getting cpu miner status: {:?}", e);
return Err(e);
}

};
Ok(AppStatus { cpu })
}
Expand All @@ -98,7 +98,7 @@ pub struct AppStatus {
pub struct CpuMinerStatus {
pub is_mining: bool,
pub hash_rate: f64,
pub cpu_usage : u32,
pub cpu_usage: u32,
pub connection: CpuMinerConnectionStatus,
}

Expand Down
14 changes: 6 additions & 8 deletions src-tauri/src/merge_mining_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ impl ProcessAdapter for MergeMiningProxyAdapter {
let file_path = BinaryResolver::current()
.resolve_path(Binaries::MergeMiningProxy, &version)?;
crate::download_utils::set_permissions(&file_path).await?;
let mut child = tokio::process::Command::new(
file_path
)
.args(args)
// .stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::piped())
.kill_on_drop(true)
.spawn()?;
let mut child = tokio::process::Command::new(file_path)
.args(args)
// .stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::piped())
.kill_on_drop(true)
.spawn()?;

select! {
res = shutdown_signal =>{
Expand Down
20 changes: 9 additions & 11 deletions src-tauri/src/minotari_node_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ProcessAdapter for MinotariNodeAdapter {
"-b".to_string(),
working_dir.to_str().unwrap().to_string(),
"--non-interactive-mode".to_string(),
"--mining-enabled".to_string()
"--mining-enabled".to_string(),
];
dbg!(&args);
Ok((
Expand All @@ -46,17 +46,15 @@ impl ProcessAdapter for MinotariNodeAdapter {
.ensure_latest(Binaries::MinotariNode)
.await?;

let file_path = BinaryResolver::current()
.resolve_path(Binaries::MinotariNode, &version)?;
let file_path =
BinaryResolver::current().resolve_path(Binaries::MinotariNode, &version)?;
crate::download_utils::set_permissions(&file_path).await?;
let mut child = tokio::process::Command::new(
file_path
)
.args(args)
// .stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::piped())
.kill_on_drop(true)
.spawn()?;
let mut child = tokio::process::Command::new(file_path)
.args(args)
// .stdout(std::process::Stdio::piped())
// .stderr(std::process::Stdio::piped())
.kill_on_drop(true)
.spawn()?;

select! {
res = shutdown_signal =>{
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/xmrig_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ impl XmrigAdapter {
args.push(format!("--user={}", self.monero_address));
args.push("--threads=6".to_string());


let client = XmrigHttpApiClient::new(
format!("http://127.0.0.1:{}", self.http_api_port),
self.http_api_token.clone(),
Expand Down

0 comments on commit dde7742

Please sign in to comment.