Use language agnostic heuristic to check if monero_wallet_rpc is ready

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.
This commit is contained in:
rishflab 2021-03-25 14:03:00 +11:00
parent 2c3c4936c6
commit bc902ea63a
3 changed files with 39 additions and 4 deletions

View File

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

View File

@ -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::*;

View File

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