Skip to content

Commit

Permalink
chore(release): version 0.8.49 (#1435)
Browse files Browse the repository at this point in the history
Description
---
Onwards and upwards
  • Loading branch information
brianp authored Jan 24, 2025
2 parents 8c99ccd + ec7cd62 commit df2c2fe
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 161 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tari-universe",
"private": true,
"version": "0.8.48",
"version": "0.8.49",
"type": "module",
"scripts": {
"dev": "vite dev --mode development",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Tari Universe"
edition = "2021"
name = "tari-universe"
repository = "https://github.com/tari-project/universe"
version = "0.8.48"
version = "0.8.49"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
118 changes: 118 additions & 0 deletions src-tauri/src/airdrop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2024. The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
use log::{info, warn};
use serde::{Deserialize, Serialize};

use crate::{mm_proxy_adapter::MergeMiningProxyConfig, UniverseAppState};

const LOG_TARGET: &str = "tari::universe::airdrop";

#[derive(Debug, Deserialize, Serialize)]
pub struct AirdropAccessToken {
pub exp: u64,
pub iat: i32,
pub id: String,
pub provider: String,
pub role: String,
pub scope: String,
}

pub fn decode_jwt_claims(t: &str) -> Option<AirdropAccessToken> {
let key = DecodingKey::from_secret(&[]);
let mut validation = Validation::new(Algorithm::HS256);
validation.insecure_disable_signature_validation();

match decode::<AirdropAccessToken>(t, &key, &validation) {
Ok(data) => Some(data.claims),
Err(e) => {
warn!(target: LOG_TARGET,"Error decoding access token: {:?}", e);
None
}
}
}

pub fn decode_jwt_claims_without_exp(t: &str) -> Option<AirdropAccessToken> {
let key = DecodingKey::from_secret(&[]);
let mut validation = Validation::new(Algorithm::HS256);
validation.insecure_disable_signature_validation();
validation.validate_exp = false;

match decode::<AirdropAccessToken>(t, &key, &validation) {
Ok(data) => Some(data.claims),
Err(e) => {
warn!(target: LOG_TARGET,"Error decoding access token without exp: {:?}", e);
None
}
}
}

pub async fn validate_jwt(airdrop_access_token: Option<String>) -> Option<String> {
airdrop_access_token.and_then(|t| {
let claims = decode_jwt_claims(&t);

let now = std::time::SystemTime::now();
let now_unix = now
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs();

if let Some(claims) = claims {
if claims.exp < now_unix {
warn!(target: LOG_TARGET,"Access token has expired");
None
} else {
Some(t)
}
} else {
None
}
})
}

pub async fn restart_mm_proxy_with_new_telemetry_id(
state: tauri::State<'_, UniverseAppState>,
) -> Result<(), String> {
info!(target: LOG_TARGET, "Restarting mm_proxy");
let telemetry_id = state
.telemetry_manager
.read()
.await
.get_unique_string()
.await;
let mm_proxy_manager_config = state
.mm_proxy_manager
.config()
.await
.ok_or("mm proxy config could not be found")?;
let _unused = state
.mm_proxy_manager
.change_config(MergeMiningProxyConfig {
coinbase_extra: telemetry_id.clone(),
..mm_proxy_manager_config
})
.await
.map_err(|e| e.to_string());
info!(target: LOG_TARGET, "mm_proxy restarted");
Ok(())
}
26 changes: 26 additions & 0 deletions src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub struct AppConfigFromFile {
p2pool_stats_server_port: Option<u16>,
#[serde(default = "default_false")]
pre_release: bool,
#[serde(default)]
airdrop_tokens: Option<AirdropTokens>,
}

impl Default for AppConfigFromFile {
Expand Down Expand Up @@ -154,6 +156,7 @@ impl Default for AppConfigFromFile {
show_experimental_settings: false,
p2pool_stats_server_port: default_p2pool_stats_server_port(),
pre_release: false,
airdrop_tokens: None,
}
}
}
Expand All @@ -165,6 +168,12 @@ pub enum DisplayMode {
Light,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AirdropTokens {
pub token: String,
pub refresh_token: String,
}

impl DisplayMode {
pub fn from_str(s: &str) -> Option<DisplayMode> {
match s {
Expand Down Expand Up @@ -266,6 +275,7 @@ pub(crate) struct AppConfig {
show_experimental_settings: bool,
p2pool_stats_server_port: Option<u16>,
pre_release: bool,
airdrop_tokens: Option<AirdropTokens>,
}

impl AppConfig {
Expand Down Expand Up @@ -310,6 +320,7 @@ impl AppConfig {
keyring_accessed: false,
p2pool_stats_server_port: default_p2pool_stats_server_port(),
pre_release: false,
airdrop_tokens: None,
}
}

Expand Down Expand Up @@ -387,6 +398,7 @@ impl AppConfig {
self.show_experimental_settings = config.show_experimental_settings;
self.p2pool_stats_server_port = config.p2pool_stats_server_port;
self.pre_release = config.pre_release;
self.airdrop_tokens = config.airdrop_tokens;

KEYRING_ACCESSED.store(
config.keyring_accessed,
Expand Down Expand Up @@ -506,6 +518,19 @@ impl AppConfig {
self.custom_max_gpu_usage.clone()
}

pub fn airdrop_tokens(&self) -> Option<AirdropTokens> {
self.airdrop_tokens.clone()
}

pub async fn set_airdrop_tokens(
&mut self,
airdrop_tokens: Option<AirdropTokens>,
) -> Result<(), anyhow::Error> {
self.airdrop_tokens = airdrop_tokens;
self.update_config_file().await?;
Ok(())
}

pub async fn set_max_gpu_usage(
&mut self,
custom_max_gpu_usage: Vec<GpuThreads>,
Expand Down Expand Up @@ -786,6 +811,7 @@ impl AppConfig {
show_experimental_settings: self.show_experimental_settings,
p2pool_stats_server_port: self.p2pool_stats_server_port,
pre_release: self.pre_release,
airdrop_tokens: self.airdrop_tokens.clone(),
};
let config = serde_json::to_string(config)?;
debug!(target: LOG_TARGET, "Updating config file: {:?} {:?}", file, self.clone());
Expand Down
4 changes: 0 additions & 4 deletions src-tauri/src/app_in_memory_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const TELEMETRY_API_URL: &str =
pub struct AppInMemoryConfig {
pub airdrop_url: String,
pub airdrop_api_url: String,
pub airdrop_access_token: Option<String>,
pub telemetry_api_url: String,
}

Expand All @@ -67,7 +66,6 @@ impl Default for AppInMemoryConfig {
AppInMemoryConfig {
airdrop_url: "https://airdrop.tari.com".into(),
airdrop_api_url: "https://ut.tari.com".into(),
airdrop_access_token: None,
telemetry_api_url: "https://ut.tari.com/push".into(),
}
}
Expand Down Expand Up @@ -112,15 +110,13 @@ impl AppInMemoryConfig {
return AppInMemoryConfig {
airdrop_url: AIRDROP_BASE_URL.into(),
airdrop_api_url: AIRDROP_API_BASE_URL.into(),
airdrop_access_token: None,
telemetry_api_url: TELEMETRY_API_URL.into(),
};

#[cfg(feature = "airdrop-local")]
return AppInMemoryConfig {
airdrop_url: "http://localhost:4000".into(),
airdrop_api_url: "http://localhost:3004".into(),
airdrop_access_token: None,
telemetry_api_url: "http://localhost:3004".into(),
};

Expand Down
Loading

0 comments on commit df2c2fe

Please sign in to comment.