mirror of
https://github.com/transatoshi-mw/grin-explorer.git
synced 2025-10-22 05:43:42 +00:00
adding outputs & kernels into the dashboard
This commit is contained in:
@@ -49,6 +49,8 @@ pub struct Dashboard {
|
||||
pub stem: String,
|
||||
// utxo
|
||||
pub utxo_count: String,
|
||||
// kernel
|
||||
pub kernel_mmr_size: String,
|
||||
}
|
||||
|
||||
impl Dashboard {
|
||||
@@ -79,6 +81,7 @@ impl Dashboard {
|
||||
txns: String::new(),
|
||||
stem: String::new(),
|
||||
utxo_count: String::new(),
|
||||
kernel_mmr_size: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
50
src/main.rs
50
src/main.rs
@@ -1,6 +1,7 @@
|
||||
#[macro_use] extern crate rocket;
|
||||
use chrono::Utc;
|
||||
use either::Either;
|
||||
use num_format::{Locale, ToFormattedString};
|
||||
use rocket_dyn_templates::{Template, context};
|
||||
use rocket::fs::FileServer;
|
||||
use rocket::{State, tokio};
|
||||
@@ -10,7 +11,7 @@ use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::data::{Block, Dashboard, Kernel, Output, Statistics, Transactions, OUTPUT_SIZE};
|
||||
use crate::data::{Block, Dashboard, Kernel, Output, Statistics, Transactions, OUTPUT_SIZE, KERNEL_SIZE};
|
||||
use crate::requests::CONFIG;
|
||||
|
||||
mod data;
|
||||
@@ -649,7 +650,50 @@ fn block_list_index(dashboard: &State<Arc<Mutex<Dashboard>>>) -> String {
|
||||
|
||||
"".to_string()
|
||||
}
|
||||
// End of HTMX backends.
|
||||
|
||||
|
||||
#[get("/rpc/blockchain/unspent_outputs")]
|
||||
fn unspent_outputs(dashboard: &State<Arc<Mutex<Dashboard>>>) -> String {
|
||||
let data = dashboard.lock().unwrap();
|
||||
|
||||
if data.utxo_count.is_empty() == false {
|
||||
let utxo_count = data.utxo_count.parse::<u64>().unwrap();
|
||||
let mut utxo_size = utxo_count as f64 * OUTPUT_SIZE as f64 / 1000.0 / 1000.0;
|
||||
let mut unit = "MB";
|
||||
|
||||
if utxo_size > 1000000000.0 {
|
||||
unit = "GB";
|
||||
utxo_size = utxo_size / 1000.0;
|
||||
}
|
||||
|
||||
return format!("{} ({:.2} {})", utxo_count.to_formatted_string(&Locale::en), utxo_size, unit);
|
||||
}
|
||||
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
|
||||
#[get("/rpc/blockchain/kernels")]
|
||||
fn kernels(dashboard: &State<Arc<Mutex<Dashboard>>>) -> String {
|
||||
let data = dashboard.lock().unwrap();
|
||||
|
||||
if data.utxo_count.is_empty() == false {
|
||||
let kernel_count = data.kernel_mmr_size.parse::<u64>().unwrap() / 2;
|
||||
let mut kernel_size = kernel_count as f64 * KERNEL_SIZE as f64 / 1000.0 / 1000.0;
|
||||
let mut unit = "MB";
|
||||
|
||||
if kernel_size > 1000000000.0 {
|
||||
unit = "GB";
|
||||
kernel_size = kernel_size / 1000.0;
|
||||
}
|
||||
|
||||
return format!("{} ({:.2} {})", kernel_count.to_formatted_string(&Locale::en), kernel_size, unit);
|
||||
}
|
||||
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
// End of HTMX routes.
|
||||
|
||||
|
||||
// Main
|
||||
@@ -731,7 +775,7 @@ async fn main() {
|
||||
block_size, block_weight, block_details_by_height, block_header_by_hash,
|
||||
soft_supply, production_cost, reward_ratio, breakeven_cost,
|
||||
last_block_age, block_list_by_height, block_list_index, search, kernel,
|
||||
output, api_owner, api_foreign, stats])
|
||||
output, api_owner, api_foreign, stats, unspent_outputs, kernels])
|
||||
.mount("/static", FileServer::from("static"))
|
||||
.attach(Template::fairing())
|
||||
.launch()
|
||||
|
@@ -148,17 +148,24 @@ pub async fn call_external(method: &str, params: &str, id: &str, rpc_type: &str,
|
||||
}
|
||||
|
||||
|
||||
// Collecting: height, sync, node_ver, proto_ver.
|
||||
// Collecting: height, sync, node_ver, proto_ver, kernel_mmr_size.
|
||||
pub async fn get_status(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), anyhow::Error> {
|
||||
let resp = call("get_status", "[]", "1", "owner").await?;
|
||||
let resp1 = call("get_status", "[]", "1", "owner").await?;
|
||||
|
||||
let mut data = dashboard.lock().unwrap();
|
||||
if resp1 != Value::Null {
|
||||
let params = &format!("[{}, null, null]", resp1["result"]["Ok"]["tip"]["height"])[..];
|
||||
let resp2 = call("get_block", params, "1", "foreign").await?;
|
||||
|
||||
if resp != Value::Null {
|
||||
data.height = resp["result"]["Ok"]["tip"]["height"].to_string();
|
||||
data.sync = resp["result"]["Ok"]["sync_status"].as_str().unwrap().to_string();
|
||||
data.node_ver = resp["result"]["Ok"]["user_agent"].as_str().unwrap().to_string();
|
||||
data.proto_ver = resp["result"]["Ok"]["protocol_version"].to_string();
|
||||
let mut data = dashboard.lock().unwrap();
|
||||
|
||||
if resp2 != Value::Null {
|
||||
data.kernel_mmr_size = resp2["result"]["Ok"]["header"]["kernel_mmr_size"].to_string();
|
||||
}
|
||||
|
||||
data.height = resp1["result"]["Ok"]["tip"]["height"].to_string();
|
||||
data.sync = resp1["result"]["Ok"]["sync_status"].as_str().unwrap().to_string();
|
||||
data.node_ver = resp1["result"]["Ok"]["user_agent"].as_str().unwrap().to_string();
|
||||
data.proto_ver = resp1["result"]["Ok"]["protocol_version"].to_string();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user