mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-06-01 13:04:51 -04:00
feat: check swap cli wallet rpc version and remove if not fluorine fermi
- swap cli will check its wallet rpc version and delete the binary if its version does not match on "Fluorine Fermi". it will then download the newer version. - adds download progress for wallet rpc
This commit is contained in:
parent
0a7a27327e
commit
249e97826f
2 changed files with 32 additions and 2 deletions
|
@ -39,6 +39,8 @@ const PACKED_FILE: &str = "monero-wallet-rpc";
|
|||
#[cfg(target_os = "windows")]
|
||||
const PACKED_FILE: &str = "monero-wallet-rpc.exe";
|
||||
|
||||
const CODENAME: &str = "Fluorine Fermi";
|
||||
|
||||
#[derive(Debug, Clone, Copy, thiserror::Error)]
|
||||
#[error("monero wallet rpc executable not found in downloaded archive")]
|
||||
pub struct ExecutableNotFoundInArchive;
|
||||
|
@ -75,6 +77,22 @@ impl WalletRpc {
|
|||
remove_file(monero_wallet_rpc.archive_path()).await?;
|
||||
}
|
||||
|
||||
// check the monero-wallet-rpc version
|
||||
let exec_path = monero_wallet_rpc.exec_path();
|
||||
tracing::debug!("exec path: {}", exec_path.display());
|
||||
|
||||
if exec_path.exists() {
|
||||
let output = Command::new(&exec_path).arg("--version").output().await?;
|
||||
let version = String::from_utf8_lossy(&output.stdout);
|
||||
tracing::debug!("RPC version output: {}", version);
|
||||
|
||||
if !version.contains(CODENAME) {
|
||||
tracing::info!("Removing old version of monero-wallet-rpc");
|
||||
tokio::fs::remove_file(exec_path).await?;
|
||||
}
|
||||
}
|
||||
|
||||
// if monero-wallet-rpc doesn't exist then download it
|
||||
if !monero_wallet_rpc.exec_path().exists() {
|
||||
let mut options = OpenOptions::new();
|
||||
let mut file = options
|
||||
|
@ -112,12 +130,24 @@ impl WalletRpc {
|
|||
let mut stream = FramedRead::new(StreamReader::new(byte_stream), BytesCodec::new())
|
||||
.map_ok(|bytes| bytes.freeze());
|
||||
|
||||
let (mut received, mut notified) = (0, 0);
|
||||
while let Some(chunk) = stream.next().await {
|
||||
file.write(&chunk?).await?;
|
||||
let bytes = chunk?;
|
||||
received += bytes.len();
|
||||
// the stream is decompressed as it is downloaded
|
||||
// file is compressed approx 3:1 in bz format
|
||||
let total = 3 * content_length;
|
||||
let percent = 100 * received as u64 / total;
|
||||
if percent != notified && percent % 10 == 0 {
|
||||
tracing::debug!("{}%", percent);
|
||||
notified = percent;
|
||||
}
|
||||
file.write(&bytes).await?;
|
||||
}
|
||||
|
||||
file.flush().await?;
|
||||
|
||||
tracing::debug!("Extracting archive");
|
||||
Self::extract_archive(&monero_wallet_rpc).await?;
|
||||
}
|
||||
Ok(monero_wallet_rpc)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue