mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-12 07:59:33 -05:00
Merge #379
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>
This commit is contained in:
commit
1684f4b92e
@ -11,4 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- A changelog file.
|
- 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
|
[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)?;
|
let r = serde_json::from_str::<Response<SweepAll>>(&response)?;
|
||||||
Ok(r.result)
|
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)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
@ -512,6 +530,11 @@ pub struct SweepAll {
|
|||||||
weight_list: Vec<u32>,
|
weight_list: Vec<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Deserialize)]
|
||||||
|
pub struct Version {
|
||||||
|
version: u32,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -2,6 +2,7 @@ use ::monero::Network;
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use big_bytes::BigByte;
|
use big_bytes::BigByte;
|
||||||
use futures::{StreamExt, TryStreamExt};
|
use futures::{StreamExt, TryStreamExt};
|
||||||
|
use monero_rpc::wallet::Client;
|
||||||
use reqwest::header::CONTENT_LENGTH;
|
use reqwest::header::CONTENT_LENGTH;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
@ -123,6 +124,7 @@ impl WalletRpc {
|
|||||||
tracing::debug!("Starting monero-wallet-rpc on port {}", port);
|
tracing::debug!("Starting monero-wallet-rpc on port {}", port);
|
||||||
|
|
||||||
let mut child = Command::new(self.exec_path())
|
let mut child = Command::new(self.exec_path())
|
||||||
|
.env("LANG", "en_AU.UTF-8")
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.kill_on_drop(true)
|
.kill_on_drop(true)
|
||||||
.arg(match network {
|
.arg(match network {
|
||||||
@ -146,12 +148,25 @@ impl WalletRpc {
|
|||||||
|
|
||||||
let mut reader = BufReader::new(stdout).lines();
|
let mut reader = BufReader::new(stdout).lines();
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
while let Some(line) = reader.next_line().await? {
|
while let Some(line) = reader.next_line().await? {
|
||||||
if line.contains("Starting wallet RPC server") {
|
if line.contains("Starting wallet RPC server") {
|
||||||
break;
|
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 {
|
Ok(WalletRpcProcess {
|
||||||
_child: child,
|
_child: child,
|
||||||
port,
|
port,
|
||||||
|
Loading…
Reference in New Issue
Block a user