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:
Byron Hambly 2022-08-10 21:19:08 +02:00
parent 0a7a27327e
commit 249e97826f
No known key found for this signature in database
GPG Key ID: DE8F6EA20A661697
2 changed files with 32 additions and 2 deletions

View File

@ -21,9 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adjust quote based on Bitcoin balance.
If the max_buy_btc in the ASB config is higher than the available balance to trade, it will return the max available balance discounting the Monero locking fees. In the case the balance is lower than the min_buy_btc config it will return 0 to the CLI. If the ASB returns a quote of 0 the CLI will not allow you continue with a trade.
- Reduce required confirmations for Bitcoin transactions from 2 to 1
- Update from monero v17.2.0 to monero v17.3.0
- Both the ASB and CLI now support the [Identify](https://github.com/libp2p/specs/blob/master/identify/README.md) protocol. This makes its version and network (testnet/mainnet) avaliable to others
- Display minimum BTC deposit required to cover the minimum quantity plus fee in the Swap CLI
- Swap CLI will check its monero-wallet-rpc version and remove it if it's older than Fluorine Fermi (0.18)
## [0.10.2] - 2021-12-25

View File

@ -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)