Added node_info stuff
This commit is contained in:
16
src/main.rs
16
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::<NodeInfo>()
|
||||
}).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)
|
||||
}
|
||||
|
||||
55
src/monero_rpc.rs
Normal file
55
src/monero_rpc.rs
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user