diff --git a/Cargo.toml b/Cargo.toml index 3bd2a3b..8196f02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] rocket = "0.5.0" -serde = "1.0.200" +serde = { version = "1.0", features = ["derive"] } sysinfo = "0.30.12" readable = "0.16.0" reqwest = { version = "0.12", features = ["json", "blocking"] } diff --git a/src/main.rs b/src/main.rs index 7b5b4eb..e9b2901 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,9 @@ use std::collections::HashMap; use sysinfo::{Components, Disks, Networks, System}; use tokio::task; +mod monero_rpc; +use monero_rpc::{NodeInfo, NodeInfoInner}; + #[derive(Serialize, Debug)] struct ComponentInfo { name: String, @@ -89,32 +92,31 @@ fn get_system_info() -> SysInfo { } -fn get_node_info() { +fn get_node_info() -> NodeInfoInner { 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 node_info = 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() + resp.json::() }).unwrap(); - - println!("{:?}", text); + node_info.result } #[get("/")] fn index() -> Template { - get_node_info(); + let node_info = get_node_info(); let system_context = get_system_info(); let context = context! { system: system_context, + node_info: node_info, }; Template::render("index", &context) } diff --git a/src/monero_rpc.rs b/src/monero_rpc.rs new file mode 100644 index 0000000..92f357e --- /dev/null +++ b/src/monero_rpc.rs @@ -0,0 +1,55 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct NodeInfo { + pub id: String, + pub jsonrpc: String, + pub result: NodeInfoInner +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct NodeInfoInner { + adjusted_time: u64, + alt_blocks_count: u64, + block_size_limit: u64, + block_size_median: u64, + block_weight_limit: u64, + block_weight_median: u64, + bootstrap_daemon_address: String, + busy_syncing: bool, + credits: u64, + cumulative_difficulty: u64, + cumulative_difficulty_top64: u64, + database_size: u64, + difficulty: u64, + difficulty_top64: u64, + free_space: u64, + grey_peerlist_size: u64, + height: u64, + height_without_bootstrap: u64, + incoming_connections_count: u64, + mainnet: bool, + nettype: String, + offline: bool, + outgoing_connections_count: u64, + restricted: bool, + rpc_connections_count: u64, + stagenet: bool, + start_time: u64, + status: String, + synchronized: bool, + target: u64, + target_height: u64, + testnet: bool, + top_block_hash: String, + top_hash: String, + tx_count: u64, + tx_pool_size: u64, + untrusted: bool, + update_available: bool, + version: String, + was_bootstrap_ever_used: bool, + white_peerlist_size: u64, + wide_cumulative_difficulty: String, + wide_difficulty: String +}