diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9650ca..8745f522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,4 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A changelog file. +### Fixed + +- Make monero_wallet_rpc readiness check language agnostic. The readiness check was + failing on non-english language systems preventing users from starting the swap-cli + and asb. + [Unreleased]: https://github.com/comit-network/xmr-btc-swap/compare/v0.3...HEAD diff --git a/monero-rpc/src/rpc/wallet.rs b/monero-rpc/src/rpc/wallet.rs index 7481ee27..71607299 100644 --- a/monero-rpc/src/rpc/wallet.rs +++ b/monero-rpc/src/rpc/wallet.rs @@ -357,6 +357,24 @@ impl Client { let r = serde_json::from_str::>(&response)?; Ok(r.result) } + + pub async fn get_version(&self) -> Result { + let request = Request::new("get_version", ""); + + let response = self + .inner + .post(self.url.clone()) + .json(&request) + .send() + .await? + .text() + .await?; + + debug!("get_version RPC response: {}", response); + + let r = serde_json::from_str::>(&response)?; + Ok(r.result) + } } #[derive(Serialize, Debug, Clone)] @@ -512,6 +530,11 @@ pub struct SweepAll { weight_list: Vec, } +#[derive(Debug, Copy, Clone, Deserialize)] +pub struct Version { + version: u32, +} + #[cfg(test)] mod tests { use super::*; diff --git a/swap/src/monero/wallet_rpc.rs b/swap/src/monero/wallet_rpc.rs index 5abb8f90..fdb367cd 100644 --- a/swap/src/monero/wallet_rpc.rs +++ b/swap/src/monero/wallet_rpc.rs @@ -2,11 +2,13 @@ use ::monero::Network; use anyhow::{Context, Result}; use big_bytes::BigByte; use futures::{StreamExt, TryStreamExt}; +use monero_rpc::wallet::Client; use reqwest::header::CONTENT_LENGTH; use reqwest::Url; use std::io::ErrorKind; use std::path::{Path, PathBuf}; use std::process::Stdio; +use std::time::Duration; use tokio::fs::{remove_file, OpenOptions}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::process::{Child, Command}; @@ -146,12 +148,16 @@ impl WalletRpc { let mut reader = BufReader::new(stdout).lines(); - while let Some(line) = reader.next_line().await? { - if line.contains("Starting wallet RPC server") { - break; - } + // If we do not hear from the monero_wallet_rpc process for 3 seconds we assume + // it is is ready + while let Ok(line) = tokio::time::timeout(Duration::from_secs(3), reader.next_line()).await + { + line?; } + // Send a json rpc request to make sure monero_wallet_rpc is ready + Client::localhost(port).get_version().await?; + Ok(WalletRpcProcess { _child: child, port,