Skip to content

Commit

Permalink
feat: airdrop referrals (#587)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Pepper <pepdog@gmail.com>
Co-authored-by: Misieq01 <38589417+Misieq01@users.noreply.github.com>
Co-authored-by: Keith Simon <41575888+Krakaw@users.noreply.github.com>
Co-authored-by: stringhandler <stringhandler@protonmail.com>
  • Loading branch information
5 people authored Sep 24, 2024
1 parent fbfacb3 commit 8a5d7c5
Show file tree
Hide file tree
Showing 89 changed files with 2,744 additions and 1,849 deletions.
100 changes: 51 additions & 49 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
{
"settings": "Settings",
"seed-words": "Seed words",
"send-logs": "Send logs",
"change-language": "Language",
"logs": "Logs",
"open-logs-directory": "Open logs directory",
"debug-info": "Debug",
"hardware-status": "Hardware status",
"update-versions": "Update versions",
"refresh-versions": "Refresh versions",
"idle-timeout": {
"title": "Time after which machine is considered idle",
"placeholder": "Enter idle timeout in seconds",
"max": "Maximum is 21600 seconds",
"min": "Minimum is 1 second"
},
"tabs": {
"general": "General",
"mining": "Mining",
"experimental": "Experimental"
},
"monero-address": {
"title": "Monero address",
"placeholder": "Enter Monero address"
},
"last-block-added-time": "Last block added to chain time",
"visual-mode": "Visual mode",
"pool-mining": "Pool Mining",
"pool-mining-description": "When enabled, you will mine in a pool and join a group of miners.",
"cpu-mining-enabled": "CPU Mining",
"gpu-mining-enabled": "GPU Mining",
"gpu-unavailable": "⚠️ GPU disabled because your hardware does not support it",
"p2pool-stats": "Squad Stats",
"tribe": "Squad",
"miners": "Miners",
"mining-toggle-warning": "Mining will be paused while the changes take effect.",
"tribe-earnings": "Squad earnings",
"tribe-pool-height": "Squad height",
"p2pool-hash-rate": "Squad hash rates",
"p2pool-total-earnings": "Squad total earnings",
"p2pool-chain-tip": "Tip of chains",
"p2pool-user-total-earnings": "Total earnings",
"yes": "Yes",
"cancel": "Cancel",
"reset-settings": "Reset Settings",
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet",
"experimental-title": "Experimental Features",
"experimental-warning": "⚠️ Warning: These features are under active development and could behave unpredictably. Please proceed carefully.",
"settings": "Settings",
"seed-words": "Seed words",
"send-logs": "Send logs",
"your-feedback": "Please describe your issue",
"feedback-required": "Feedback is required",
"change-language": "Language",
"logs": "Logs",
"open-logs-directory": "Open logs directory",
"debug-info": "Debug",
"hardware-status": "Hardware status",
"update-versions": "Update versions",
"refresh-versions": "Refresh versions",
"idle-timeout": {
"title": "Time after which machine is considered idle",
"placeholder": "Enter idle timeout in seconds",
"max": "Maximum is 21600 seconds",
"min": "Minimum is 1 second"
},
"tabs": {
"general": "General",
"mining": "Mining",
"experimental": "Experimental"
},
"monero-address": {
"title": "Monero address",
"placeholder": "Enter Monero address"
},
"last-block-added-time": "Last block added to chain time",
"visual-mode": "Visual mode",
"pool-mining": "Pool Mining",
"pool-mining-description": "When enabled, you will mine in a pool and join a group of miners.",
"cpu-mining-enabled": "CPU Mining",
"gpu-mining-enabled": "GPU Mining",
"gpu-unavailable": "⚠️ GPU disabled because your hardware does not support it",
"p2pool-stats": "Squad Stats",
"tribe": "Squad",
"miners": "Miners",
"mining-toggle-warning": "Mining will be paused while the changes take effect.",
"tribe-earnings": "Squad earnings",
"tribe-pool-height": "Squad height",
"p2pool-hash-rate": "Squad hash rates",
"p2pool-total-earnings": "Squad total earnings",
"p2pool-chain-tip": "Tip of chains",
"p2pool-user-total-earnings": "Total earnings",
"yes": "Yes",
"cancel": "Cancel",
"reset-settings": "Reset Settings",
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet",
"experimental-title": "Experimental Features",
"experimental-warning": "⚠️ Warning: These features are under active development and could behave unpredictably. Please proceed carefully.",
"connected-to-tari": "Connected to the Tari Network",
"not-connected-to-tari": "Not connected to the Tari Network",
"connected-peers": "Connected Peers",
Expand Down
10 changes: 0 additions & 10 deletions src-tauri/Cargo.lock

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

1 change: 0 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ nix = { version = "0.29.0", features = ["signal"] }
sha2 = "0.10.8"
regex = "1.10.5"
zip = "2.2.0"
zip-extensions = "0.8.1"
# static bind lzma
xz2 = { version = "0.1.7", features = ["static"] }
# humantime = "2.1.0"
Expand Down
11 changes: 11 additions & 0 deletions src-tauri/binaries_versions_esmeralda.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"binaries": {
"xmrig": "6.22.0",
"mmproxy": "1.5.1-pre.0",
"minotari_node": "1.5.1-pre.0",
"wallet": "1.5.1-pre.0",
"sha-p2pool": "0.1.8",
"xtrgpuminer": "0.1.8-pre.4"
}

}
11 changes: 11 additions & 0 deletions src-tauri/binaries_versions_nextnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"binaries": {
"xmrig": "6.22.0",
"mmproxy": "1.5.1-rc.2",
"minotari_node": "1.5.1-rc.2",
"wallet": "1.5.1-rc.2",
"sha-p2pool": "0.1.8",
"xtrgpuminer": "0.1.8-pre.4"
}

}
113 changes: 113 additions & 0 deletions src-tauri/src/binaries/adapter_github.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use std::path::PathBuf;

use anyhow::Error;
use async_trait::async_trait;
use log::{error, info};
use regex::Regex;
use tari_common::configuration::Network;
use tauri::api::path::cache_dir;

use crate::{
download_utils::download_file_with_retries, github, progress_tracker::ProgressTracker,
};

use super::binaries_resolver::{LatestVersionApiAdapter, VersionAsset, VersionDownloadInfo};

pub const LOG_TARGET: &str = "tari::universe::adapter_github";

pub struct GithubReleasesAdapter {
pub repo: String,
pub owner: String,
pub specific_name: Option<Regex>,
}

#[async_trait]
impl LatestVersionApiAdapter for GithubReleasesAdapter {
async fn fetch_releases_list(&self) -> Result<Vec<VersionDownloadInfo>, Error> {
let releases = github::list_releases(&self.owner, &self.repo).await?;
Ok(releases.clone())
}

async fn download_and_get_checksum_path(
&self,
directory: PathBuf,
download_info: VersionDownloadInfo,
progress_tracker: ProgressTracker,
) -> Result<PathBuf, Error> {
let asset = self.find_version_for_platform(&download_info)?;
let checksum_path = directory
.join("in_progress")
.join(format!("{}.sha256", asset.name));
let checksum_url = format!("{}.sha256", asset.url);

match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker).await {
Ok(_) => Ok(checksum_path),
Err(e) => {
error!(target: LOG_TARGET, "Failed to download checksum file: {}", e);
Err(e)
}
}
}

fn get_binary_folder(&self) -> PathBuf {
let binary_folder_path = cache_dir()
.unwrap()
.join("com.tari.universe")
.join("binaries")
.join(&self.repo)
.join(
Network::get_current_or_user_setting_or_default()
.to_string()
.to_lowercase(),
);

if !binary_folder_path.exists() {
drop(std::fs::create_dir_all(&binary_folder_path));
}

binary_folder_path
}

fn find_version_for_platform(
&self,
version: &VersionDownloadInfo,
) -> Result<VersionAsset, Error> {
let mut name_suffix = "";
// TODO: add platform specific logic
if cfg!(target_os = "windows") {
name_suffix = r"windows-x64.*\.zip";
}

if cfg!(target_os = "macos") && cfg!(target_arch = "x86_64") {
name_suffix = r"macos-x86_64.*\.zip";
}

if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") {
name_suffix = r"macos-arm64.*\.zip";
}
if cfg!(target_os = "linux") {
name_suffix = r"linux-x86_64.*\.zip";
}
if name_suffix.is_empty() {
panic!("Unsupported OS");
}

info!(target: LOG_TARGET, "Looking for platform with suffix: {}", name_suffix);

let reg = Regex::new(name_suffix).unwrap();

let platform = version
.assets
.iter()
.find(|a| {
if let Some(ref specific) = self.specific_name {
specific.is_match(&a.name) && reg.is_match(&a.name)
} else {
reg.is_match(&a.name)
}
})
.ok_or(anyhow::anyhow!("Failed to get platform asset"))?;
info!(target: LOG_TARGET, "Found platform: {:?}", platform);
Ok(platform.clone())
}
}
92 changes: 92 additions & 0 deletions src-tauri/src/binaries/adapter_xmrig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::path::PathBuf;

use anyhow::Error;
use async_trait::async_trait;
use regex::Regex;
use tari_common::configuration::Network;
use tauri::api::path::cache_dir;

use crate::{github, progress_tracker::ProgressTracker};

use super::binaries_resolver::{LatestVersionApiAdapter, VersionAsset, VersionDownloadInfo};

pub struct XmrigVersionApiAdapter {}

#[async_trait]
impl LatestVersionApiAdapter for XmrigVersionApiAdapter {
async fn fetch_releases_list(&self) -> Result<Vec<VersionDownloadInfo>, Error> {
let releases = github::list_releases("xmrig", "xmrig").await?;
Ok(releases.clone())
}

async fn download_and_get_checksum_path(
&self,
directory: PathBuf,
download_info: VersionDownloadInfo,
_: ProgressTracker,
) -> Result<PathBuf, Error> {
// When xmrig is downloaded checksum will be already in its folder so there is no need to download it
// directory parameter should point to folder where xmrig is extracted
// file with checksum should be in the same folder as xmrig
// file name is SHA256SUMS
// let platform = self.find_version_for_platform(version)?;
let checksum_path = directory
.join(format!("xmrig-{}", download_info.version))
.join("SHA256SUMS");

Ok(checksum_path)
}

fn get_binary_folder(&self) -> PathBuf {
let binary_folder_path = cache_dir()
.unwrap()
.join("com.tari.universe")
.join("binaries")
.join("xmrig")
.join(
Network::get_current_or_user_setting_or_default()
.to_string()
.to_lowercase(),
);

if !binary_folder_path.exists() {
drop(std::fs::create_dir_all(&binary_folder_path));
}

binary_folder_path
}

fn find_version_for_platform(
&self,
_version: &VersionDownloadInfo,
) -> Result<VersionAsset, anyhow::Error> {
let mut name_suffix = "";
if cfg!(target_os = "windows") {
name_suffix = r".*msvc-win64\.zip";
}
if cfg!(target_os = "macos") && cfg!(target_arch = "x86_64") {
name_suffix = r".*macos-x64\.tar.gz";
}
if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") {
// the x64 seems to work better on the M1
name_suffix = r".*macos-arm64\.tar.gz";
}
if cfg!(target_os = "linux") {
name_suffix = r".*linux-static-x64\.tar.gz";
}
if cfg!(target_os = "freebsd") {
name_suffix = r".*freebsd-static-x64\.tar.gz";
}
if name_suffix.is_empty() {
panic!("Unsupported OS");
}

let reg = Regex::new(name_suffix).unwrap();
let platform = _version
.assets
.iter()
.find(|a| reg.is_match(&a.name))
.ok_or(anyhow::anyhow!("Failed to get platform asset"))?;
Ok(platform.clone())
}
}
Loading

0 comments on commit 8a5d7c5

Please sign in to comment.