mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-25 07:29:32 -05:00
Check if binary is latest version
This commit is contained in:
parent
ec8500551f
commit
9fb0d7b733
@ -67,6 +67,12 @@ async fn main() -> Result<()> {
|
||||
let swap_id = Uuid::new_v4();
|
||||
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let db = open_db(data_dir.join("sqlite")).await?;
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
@ -149,6 +155,11 @@ async fn main() -> Result<()> {
|
||||
Command::History => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let db = open_db(data_dir.join("sqlite")).await?;
|
||||
let swaps = db.all().await?;
|
||||
|
||||
@ -173,6 +184,11 @@ async fn main() -> Result<()> {
|
||||
Command::Config => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
tracing::info!(path=%data_dir.display(), "Data directory");
|
||||
tracing::info!(path=%format!("{}/logs", data_dir.display()), "Log files directory");
|
||||
tracing::info!(path=%format!("{}/sqlite", data_dir.display()), "Sqlite file location");
|
||||
@ -187,6 +203,12 @@ async fn main() -> Result<()> {
|
||||
address,
|
||||
} => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
let bitcoin_wallet = init_bitcoin_wallet(
|
||||
@ -220,6 +242,12 @@ async fn main() -> Result<()> {
|
||||
bitcoin_target_block,
|
||||
} => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
let bitcoin_wallet = init_bitcoin_wallet(
|
||||
@ -245,6 +273,12 @@ async fn main() -> Result<()> {
|
||||
tor_socks5_port,
|
||||
} => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let db = open_db(data_dir.join("sqlite")).await?;
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
@ -306,6 +340,12 @@ async fn main() -> Result<()> {
|
||||
bitcoin_target_block,
|
||||
} => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let db = open_db(data_dir.join("sqlite")).await?;
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
@ -328,6 +368,12 @@ async fn main() -> Result<()> {
|
||||
bitcoin_target_block,
|
||||
} => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let db = open_db(data_dir.join("sqlite")).await?;
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
@ -353,6 +399,11 @@ async fn main() -> Result<()> {
|
||||
.context("Rendezvous node address must contain peer ID")?;
|
||||
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
let identity = seed.derive_libp2p_identity();
|
||||
@ -433,6 +484,11 @@ async fn main() -> Result<()> {
|
||||
} => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||
.context("Failed to read in seed file")?;
|
||||
let bitcoin_wallet = init_bitcoin_wallet(
|
||||
@ -447,6 +503,13 @@ async fn main() -> Result<()> {
|
||||
tracing::info!(descriptor=%wallet_export.to_string(), "Exported bitcoin wallet");
|
||||
}
|
||||
Command::MoneroRecovery { swap_id } => {
|
||||
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
|
||||
|
||||
match check_latest_version().await {
|
||||
Ok(()) => (),
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
};
|
||||
|
||||
let db = open_db(data_dir.join("sqlite")).await?;
|
||||
|
||||
let swap_state: BobState = db.get_state(swap_id).await?.try_into()?;
|
||||
@ -629,10 +692,43 @@ where
|
||||
Ok((btc_swap_amount, fees))
|
||||
}
|
||||
|
||||
pub async fn check_latest_version() -> Result<()> {
|
||||
const GITHUB_LATEST_VERSION_URL: &str =
|
||||
"https://github.com/comit-network/xmr-btc-swap/releases/latest";
|
||||
|
||||
let response = match reqwest::get(GITHUB_LATEST_VERSION_URL).await {
|
||||
Ok(res) => res,
|
||||
Err(_) => bail!(
|
||||
"could not request the website {}",
|
||||
GITHUB_LATEST_VERSION_URL
|
||||
),
|
||||
};
|
||||
|
||||
let last_version_from_url: &str = match response.url().path_segments() {
|
||||
Some(split_segments) => match split_segments.last() {
|
||||
Some(seg) => seg,
|
||||
None => bail!("could not check the latest version"),
|
||||
},
|
||||
None => bail!("could not check the latest version"),
|
||||
};
|
||||
|
||||
let version_from_binary: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
if last_version_from_url != version_from_binary {
|
||||
tracing::warn!(
|
||||
"You are not on the lastest version {}, it's available on Github: {}",
|
||||
last_version_from_url,
|
||||
GITHUB_LATEST_VERSION_URL
|
||||
);
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::determine_btc_to_swap;
|
||||
use crate::{check_latest_version, determine_btc_to_swap};
|
||||
use ::bitcoin::Amount;
|
||||
use std::sync::Mutex;
|
||||
use swap::tracing_ext::capture_logs;
|
||||
@ -995,4 +1091,13 @@ mod tests {
|
||||
async fn get_dummy_address() -> Result<bitcoin::Address> {
|
||||
Ok("1PdfytjS7C8wwd9Lq5o4x9aXA2YRqaCpH6".parse()?)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn check_correct_latest_version() {
|
||||
let writer = capture_logs(LevelFilter::INFO);
|
||||
|
||||
check_latest_version().await.unwrap();
|
||||
|
||||
assert_eq!(writer.captured(), r"");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user