From 02d6fb7270304740e25a800765f3cafa69410bb3 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:18:23 +0300 Subject: [PATCH] fix chain dir detection --- src/data.rs | 2 ++ src/requests.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/data.rs b/src/data.rs index 0188bbe..2ea4e0a 100644 --- a/src/data.rs +++ b/src/data.rs @@ -17,6 +17,7 @@ pub const OUTPUT_SIZE: u64 = 674 + 33 + 1; #[derive(Debug)] pub struct Dashboard { // status + pub chain: String, pub height: String, pub sync: String, pub node_ver: String, @@ -56,6 +57,7 @@ pub struct Dashboard { impl Dashboard { pub fn new() -> Dashboard { Dashboard { + chain: String::new(), height: String::new(), sync: String::new(), node_ver: String::new(), diff --git a/src/requests.rs b/src/requests.rs index 34e3e9d..b26f2d7 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -162,6 +162,7 @@ pub async fn get_status(dashboard: Arc>) -> Result<(), anyhow:: data.kernel_mmr_size = resp2["result"]["Ok"]["header"]["kernel_mmr_size"].to_string(); } + data.chain = resp1["result"]["Ok"]["chain"].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(); @@ -305,10 +306,14 @@ pub fn get_disk_usage(dashboard: Arc>) -> Result<(), Error> { let mut data = dashboard.lock().unwrap(); let chain_dir; - if CONFIG.coingecko_api == "enabled" { + if data.chain == "main" { chain_dir = format!("{}/main/chain_data", CONFIG.grin_dir); - } else { + } else if data.chain == "test" { chain_dir = format!("{}/test/chain_data", CONFIG.grin_dir); + } else { + // Chain parameter in get_status() rpc is added in 5.3.3 node. + // Default to main chain in case of node version less than 5.3.3. + chain_dir = format!("{}/main/chain_data", CONFIG.grin_dir); } match get_size(chain_dir.clone()) {