use crate::Log;
use anyhow::{Result, anyhow};
use std::{net::SocketAddrV4, process::Child};
pub struct NodeInstance {
pub address: SocketAddrV4,
pub(crate) log: Log,
pub(crate) process: Child,
}
impl NodeInstance {
pub fn ws(&self) -> String {
format!("ws://{}", self.address)
}
pub fn logs(&self) -> Result<Vec<String>> {
let Ok(logs) = self.log.logs.read() else {
return Err(anyhow!("Failed to read logs from the node process."));
};
Ok(logs.clone().into_vec())
}
}
impl Drop for NodeInstance {
fn drop(&mut self) {
self.process.kill().expect("Unable to kill node process.")
}
}