mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-23 08:51:51 -04:00
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:
parent
2c3c4936c6
commit
bc902ea63a
3 changed files with 39 additions and 4 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue