From ee769d87e6695ebe9726ab08547f22e94ee82119 Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:05:54 +0100 Subject: [PATCH] fix(gui): Do not release .deb binaries --- src-tauri/tauri.conf.json | 5 ++-- swap/src/bin/asb.rs | 22 +++++++------- swap/src/bin/swap.rs | 5 ---- swap/src/cli/api.rs | 3 +- swap/src/common/mod.rs | 62 ++++++++++----------------------------- 5 files changed, 28 insertions(+), 69 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c3b5924fd..7f6cabe3a 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -29,8 +29,7 @@ "appimage", "dmg", "nsis", - "app", - "deb" + "app" ], "icon": [ "icons/32x32.png", @@ -58,4 +57,4 @@ ] } } -} \ No newline at end of file +} diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 2ef273fbf..9ca4da0b4 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -29,7 +29,7 @@ use swap::asb::config::{ }; use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate}; use swap::common::tracing_util::Format; -use swap::common::{self, check_latest_version, get_logs}; +use swap::common::{self, get_logs, warn_if_outdated}; use swap::database::{open_db, AccessMode}; use swap::network::rendezvous::XmrBtcNamespace; use swap::network::swarm; @@ -63,12 +63,10 @@ pub async fn main() -> Result<()> { } }; - // warn if we're not on the latest version - if let Err(e) = check_latest_version(env!("CARGO_PKG_VERSION")).await { - eprintln!("{}", e); - } + // Check in the background if there's a new version available + tokio::spawn(async move { warn_if_outdated(env!("CARGO_PKG_VERSION")).await }); - // read config from the specified path + // Read config from the specified path let config = match read_config(config_path.clone())? { Ok(config) => config, Err(ConfigNotInitialized {}) => { @@ -77,13 +75,13 @@ pub async fn main() -> Result<()> { } }; - // initialize tracing + // Initialize tracing let format = if json { Format::Json } else { Format::Raw }; let log_dir = config.data.dir.join("logs"); common::tracing_util::init(LevelFilter::DEBUG, format, log_dir, None) .expect("initialize tracing"); - // check for conflicting env / config values + // Check for conflicting env / config values if config.monero.network != env_config.monero_network { bail!(format!( "Expected monero network in config file to be {:?} but was {:?}", @@ -118,12 +116,12 @@ pub async fn main() -> Result<()> { ); } - // initialize monero wallet + // Initialize Monero wallet let monero_wallet = init_monero_wallet(&config, env_config).await?; let monero_address = monero_wallet.get_main_address(); tracing::info!(%monero_address, "Monero wallet address"); - // check monero balance + // Check Monero balance let monero = monero_wallet.get_balance().await?; match (monero.balance, monero.unlocked_balance) { (0, _) => { @@ -146,14 +144,14 @@ pub async fn main() -> Result<()> { } } - // init bitcoin wallet + // Initialize Bitcoin wallet let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; let bitcoin_balance = bitcoin_wallet.balance().await?; tracing::info!(%bitcoin_balance, "Bitcoin wallet balance"); let kraken_price_updates = kraken::connect(config.maker.price_ticker_ws_url.clone())?; - // setup Tor hidden services + // Setup Tor hidden services let tor_client = tor::Client::new(config.tor.socks5_port).with_control_port(config.tor.control_port); let _ac = match tor_client.assert_tor_running().await { diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 941bf18dc..9d79c9dc0 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -14,14 +14,9 @@ use anyhow::Result; use std::env; use swap::cli::command::{parse_args_and_apply_defaults, ParseResult}; -use swap::common::check_latest_version; #[tokio::main] pub async fn main() -> Result<()> { - if let Err(e) = check_latest_version(env!("CARGO_PKG_VERSION")).await { - eprintln!("{}", e); - } - match parse_args_and_apply_defaults(env::args_os()).await? { ParseResult::Success(context) => { context.tasks.wait_for_tasks().await?; diff --git a/swap/src/cli/api.rs b/swap/src/cli/api.rs index 1e6392a9e..b6476f749 100644 --- a/swap/src/cli/api.rs +++ b/swap/src/cli/api.rs @@ -642,10 +642,9 @@ pub mod api_test { json: bool, ) -> Self { let data_dir = data::data_dir_from(data_dir, is_testnet).unwrap(); - let seed = Seed::from_file_or_generate(data_dir.as_path()).unwrap(); - let env_config = env_config_from(is_testnet); + Self { namespace: XmrBtcNamespace::from_is_testnet(is_testnet), env_config, diff --git a/swap/src/common/mod.rs b/swap/src/common/mod.rs index 48d05aab9..a78588690 100644 --- a/swap/src/common/mod.rs +++ b/swap/src/common/mod.rs @@ -1,45 +1,35 @@ pub mod tracing_util; -use std::{collections::HashMap, path::PathBuf}; - use anyhow::anyhow; +use std::{collections::HashMap, path::PathBuf}; use tokio::{ fs::{read_dir, File}, io::{AsyncBufReadExt, BufReader}, }; use uuid::Uuid; -const LATEST_RELEASE_URL: &str = "https://github.com/comit-network/xmr-btc-swap/releases/latest"; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub enum Version { - Current, - Available, -} +const LATEST_RELEASE_URL: &str = "https://github.com/UnstoppableSwap/core/releases/latest"; -/// Check the latest release from GitHub API. -pub async fn check_latest_version(current_version: &str) -> anyhow::Result { +/// Check the latest release from GitHub and warn if we are not on the latest version. +pub async fn warn_if_outdated(current_version: &str) -> anyhow::Result<()> { + // Visit the Github releases page and check which url we are redirected to let response = reqwest::get(LATEST_RELEASE_URL).await?; - let e = "Failed to get latest release."; let download_url = response.url(); - let segments = download_url.path_segments().ok_or_else(|| anyhow!(e))?; - let latest_version = segments.last().ok_or_else(|| anyhow!(e))?; - let result = if is_latest_version(current_version, latest_version) { - Version::Current - } else { + let segments = download_url + .path_segments() + .ok_or_else(|| anyhow!("Cannot split Github release URL into segments"))?; + let latest_version = segments + .last() + .ok_or_else(|| anyhow!("Cannot extract latest version from Github release URL"))?; + + if current_version != latest_version { tracing::warn!(%current_version, %latest_version, %download_url, "You are not on the latest version", ); - Version::Available - }; - - Ok(result) -} + } -// todo: naive implementation can be improved using semver -fn is_latest_version(current: &str, latest: &str) -> bool { - current == latest + Ok(()) } /// helper macro for [`redact`]... eldrich sorcery @@ -196,25 +186,3 @@ pub fn redact_with(input: &str, replacements: &mut HashMap) -> S redacted } - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn it_compares_versions() { - assert!(is_latest_version("0.10.2", "0.10.2")); - assert!(!is_latest_version("0.10.2", "0.10.3")); - assert!(!is_latest_version("0.10.2", "0.11.0")); - } - - #[tokio::test] - #[ignore = "For local testing, makes http requests to github."] - async fn it_compares_with_github() { - let result = check_latest_version("0.11.0").await.unwrap(); - assert_eq!(result, Version::Available); - - let result = check_latest_version("0.11.1").await.unwrap(); - assert_eq!(result, Version::Current); - } -}