From 2c0e8d0df75c0b5e7ab4af4d2379480dfc9c33bb Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Tue, 7 May 2024 13:45:55 +0300 Subject: [PATCH] fix transactions stats --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/requests.rs | 21 ++++++++++++++------- templates/base.html.tera | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 927112a..39490aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -730,7 +730,7 @@ dependencies = [ [[package]] name = "grin-explorer" -version = "0.1.0" +version = "0.1.1" dependencies = [ "chrono", "colored", diff --git a/Cargo.toml b/Cargo.toml index 1f4fc95..a243ad9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin-explorer" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/requests.rs b/src/requests.rs index aa45ca7..4a43a41 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -387,18 +387,20 @@ pub async fn get_kernel(kernel: &str, height: &mut String) pub async fn get_block_kernels(height: &String, blocks: &mut Vec) -> Result<(), Error> { if height.is_empty() == false { - let params = &format!("[{}, {}, 1440, false]", height.parse::().unwrap() - 1440, - height)[..]; - let resp = call("get_blocks", params, "foreign").await.unwrap(); + let params = &format!("[{}, {}, 720, false]", height.parse::().unwrap() - 720, + height)[..]; + let resp = call("get_blocks", params, "foreign").await.unwrap(); for resp_block in resp["result"]["Ok"]["blocks"].as_array().unwrap() { + let mut block = Block::new(); + for kernel in resp_block["kernels"].as_array().unwrap() { - let mut block = Block::new(); block.kernels.push((kernel["excess"].to_string(), kernel["features"].as_str().unwrap().to_string(), kernel["fee"].to_string())); - blocks.push(block); } + + blocks.push(block); } } @@ -413,7 +415,11 @@ pub async fn get_txn_stats(dashboard: Arc>, let height = get_current_height(dashboard.clone()); if height.is_empty() == false { - // Collecting kernels for 1440 blocks + // get_blocks grin rpc has limit of maximum of 1000 blocks request + // https://github.com/mimblewimble/grin/blob/master/api/src/handlers/blocks_api.rs#L27 + // So, collecting kernels 2 times by 720 blocks to get a day of blocks + let _ = get_block_kernels(&((height.parse::().unwrap() - 720).to_string()), &mut blocks) + .await; let _ = get_block_kernels(&height, &mut blocks).await; if blocks.is_empty() == false { @@ -424,7 +430,8 @@ pub async fn get_txn_stats(dashboard: Arc>, let mut index = 0; for block in blocks { - if index < 60 { + // Latest 60 blocks + if index >= 1380 { for kernel in block.kernels.clone() { if kernel.1 != "Coinbase" { ker_count_1h = ker_count_1h + 1; diff --git a/templates/base.html.tera b/templates/base.html.tera index 5c1e2d5..69ebb71 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -212,7 +212,7 @@