mirror of
https://github.com/transatoshi-mw/grin-explorer.git
synced 2025-10-21 13:33:41 +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?;
|
||||
|
||||
if resp1 != Value::Null {
|
||||
let params = &format!("[{}, null, null]", resp1["result"]["Ok"]["tip"]["height"])[..];
|
||||
let resp2 = call("get_block", params, "1", "foreign").await?;
|
||||
|
||||
let mut data = dashboard.lock().unwrap();
|
||||
|
||||
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();
|
||||
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(())
|
||||
|
@@ -66,7 +66,6 @@
|
||||
</div>
|
||||
|
||||
<div class="card-group">
|
||||
<div class="card card-background border-0">
|
||||
<div class="card border-bottom-0 border-start-0 rounded-0 mx-0 mt-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-grid"></i> BLOCKCHAIN</div>
|
||||
@@ -82,23 +81,16 @@
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Time Since Last Block </div><div class="value-text text-end" hx-get="/rpc/block/time_since_last" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card border-bottom-0 border-start-0 rounded-0 mx-0 my-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-speedometer2"></i> TRANSACTIONS & FEES</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">1H Period </div><div class="value-text text-end" hx-get="/rpc/txns/count_1h" hx-trigger="load, every 10s"></div>
|
||||
<div class="value-text">Unspent Outputs </div><div class="value-text text-end" hx-get="/rpc/blockchain/unspent_outputs" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">24H Period </div><div class="value-text text-end" hx-get="/rpc/txns/count_24h" hx-trigger="load, every 10s"></div>
|
||||
<div class="value-text">Kernels </div><div class="value-text text-end" hx-get="/rpc/blockchain/kernels" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-bottom-0 border-end-0 rounded-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-hammer"></i> MINING</div>
|
||||
@@ -146,7 +138,20 @@
|
||||
</div>
|
||||
|
||||
<div class="card-group">
|
||||
<div class="card rounded-0 border-start-0">
|
||||
<div class="card border-bottom-0 border-start-0 rounded-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-speedometer2"></i> TRANSACTIONS & FEES</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">1H Period </div><div class="value-text text-end" hx-get="/rpc/txns/count_1h" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">24H Period </div><div class="value-text text-end" hx-get="/rpc/txns/count_24h" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card rounded-0 border-bottom-0 border-start-0 border-end-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-receipt"></i> MEMPOOL</div>
|
||||
<br>
|
||||
@@ -159,7 +164,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card rounded-0">
|
||||
</div>
|
||||
<div class="card-group">
|
||||
<div class="card rounded-0 border-start-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-diagram-3"></i> CONNECTIONS</div>
|
||||
<br>
|
||||
@@ -172,7 +179,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card rounded-0 border-end-0">
|
||||
<div class="card rounded-0 border-start-0 border-end-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="darkorange-text"><i class="bi bi-pc-display-horizontal"></i> NODE</div>
|
||||
<br>
|
||||
@@ -264,6 +271,14 @@
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Time Since Last Block </div><div class="value-text text-end" hx-get="/rpc/block/time_since_last" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Unspent Outputs </div><div class="value-text text-end" hx-get="/rpc/blockchain/unspent_outputs" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Kernels </div><div class="value-text text-end" hx-get="/rpc/blockchain/kernels" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||
@@ -519,6 +534,14 @@
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Time Since Last Block </div><div class="value-text text-end" hx-get="/rpc/block/time_since_last" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Unspent Outputs </div><div class="value-text text-end" hx-get="/rpc/blockchain/unspent_outputs" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Kernels </div><div class="value-text text-end" hx-get="/rpc/blockchain/kernels" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card border-bottom-0 border-end-0 rounded-0">
|
||||
@@ -626,6 +649,14 @@
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Time Since Last Block </div><div class="value-text text-end" hx-get="/rpc/block/time_since_last" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Unspent Outputs </div><div class="value-text text-end" hx-get="/rpc/blockchain/unspent_outputs" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">Kernels </div><div class="value-text text-end" hx-get="/rpc/blockchain/kernels" hx-trigger="load, every 10s"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||
|
Reference in New Issue
Block a user