Added first steps of getting monerod info

Although it is proving surprisingly difficult!
This commit is contained in:
2024-05-14 22:31:47 +01:00
parent 81f31aa442
commit cdd562aee5
4 changed files with 578 additions and 45 deletions

View File

@@ -5,8 +5,10 @@ use rocket_dyn_templates::{context, Template};
use readable::byte::Byte;
use readable::up::UptimeFull;
use std::path::Path;
use reqwest;
use std::collections::HashMap;
use sysinfo::{Components, Disks, Networks, System};
use tokio::task;
#[derive(Serialize, Debug)]
struct ComponentInfo {
@@ -86,8 +88,30 @@ fn get_system_info() -> SysInfo {
}
}
fn get_node_info() {
let mut map = HashMap::new();
map.insert("jsonrpc", "2.0");
map.insert("id", "0");
map.insert("method", "get_info");
let text = task::block_in_place(move || {
let client = reqwest::blocking::Client::new();
// TODO: Properly handle this unwrap - half the point of this is to capture
// when the node is down
let resp = client.post("http://127.0.0.1:18081/json_rpc").json(&map).send().unwrap();
// TODO: Make this resp.json - I need to build a deserializer I think
// TODO: Figure out _why_ this part needs to be inside this closure
resp.text()
}).unwrap();
println!("{:?}", text);
}
#[get("/")]
fn index() -> Template {
get_node_info();
let system_context = get_system_info();
let context = context! {
system: system_context,