use crate::rpc::control::ControlRpc;
use anyhow::Result;
use serde_json::{json, Value};
pub async fn get_uptime(control: &ControlRpc) -> Result<Value> {
let params = json!([]);
let uptime = control.uptime(¶ms).await?;
Ok(uptime)
}
pub async fn get_memory_info(control: &ControlRpc, mode: Option<&str>) -> Result<Value> {
let params = if let Some(m) = mode {
json!([m])
} else {
json!([])
};
let info = control.getmemoryinfo(¶ms).await?;
Ok(info)
}
pub async fn get_rpc_info(control: &ControlRpc) -> Result<Value> {
let params = json!([]);
let info = control.getrpcinfo(¶ms).await?;
Ok(info)
}
pub async fn get_help(control: &ControlRpc, command: Option<&str>) -> Result<Value> {
let params = if let Some(cmd) = command {
json!([cmd])
} else {
json!([])
};
let help = control.help(¶ms).await?;
Ok(help)
}
pub async fn get_logging(control: &ControlRpc) -> Result<Value> {
let params = json!([]);
let logging = control.logging(¶ms).await?;
Ok(logging)
}
pub async fn set_logging(
control: &ControlRpc,
include: Option<Vec<String>>,
exclude: Option<Vec<String>>,
) -> Result<Value> {
let mut params = json!([]);
if let Some(inc) = include {
params.as_array_mut().unwrap().push(json!(inc));
}
if let Some(exc) = exclude {
params.as_array_mut().unwrap().push(json!(exc));
}
let logging = control.logging(¶ms).await?;
Ok(logging)
}
pub async fn stop_node(control: &ControlRpc) -> Result<Value> {
let params = json!([]);
let result = control.stop(¶ms).await?;
Ok(result)
}