379: Use language agnostic heuristic to check if monero_wallet_rpc is ready r=rishflab a=rishflab

Our strategy of searching for a english string to determine if
monero_wallet_rpc is ready is not compatible with languages other than
english. Instead we assume the monero rpc is ready if it has stopped
writing to stdout. We make a json rpc request to confirm this. A better
solution would have been to configure the monero_wallet_rpc to always
output in english but there is not command line argument to configure
the language.

Closes #353.

NOTE: will squash after approved

Co-authored-by: rishflab <rishflab@hotmail.com>
pull/385/head
bors[bot] 3 years ago committed by GitHub
commit 1684f4b92e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -357,6 +357,24 @@ impl Client {
let r = serde_json::from_str::<Response<SweepAll>>(&response)?;
Ok(r.result)
}
pub async fn get_version(&self) -> Result<Version> {
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<Version>>(&response)?;
Ok(r.result)
}
}
#[derive(Serialize, Debug, Clone)]
@ -512,6 +530,11 @@ pub struct SweepAll {
weight_list: Vec<u32>,
}
#[derive(Debug, Copy, Clone, Deserialize)]
pub struct Version {
version: u32,
}
#[cfg(test)]
mod tests {
use super::*;

@ -2,6 +2,7 @@ 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;
@ -123,6 +124,7 @@ impl WalletRpc {
tracing::debug!("Starting monero-wallet-rpc on port {}", port);
let mut child = Command::new(self.exec_path())
.env("LANG", "en_AU.UTF-8")
.stdout(Stdio::piped())
.kill_on_drop(true)
.arg(match network {
@ -146,12 +148,25 @@ impl WalletRpc {
let mut reader = BufReader::new(stdout).lines();
#[cfg(not(target_os = "windows"))]
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
#[cfg(target_os = "windows")]
while let Ok(line) =
tokio::time::timeout(std::time::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,

Loading…
Cancel
Save