From 3afcd831da5f369e8bbdbe11c8fa6f5da1585f9f Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Tue, 7 May 2024 21:51:42 +0300 Subject: [PATCH 01/10] adding breakeven cost --- src/data.rs | 2 + src/main.rs | 12 +++++- src/requests.rs | 5 ++- static/styles/style.css | 64 +++---------------------------- templates/index.html.tera | 81 ++++++++++++++++++++++++++++----------- 5 files changed, 80 insertions(+), 84 deletions(-) diff --git a/src/data.rs b/src/data.rs index b6164c5..ed358d7 100644 --- a/src/data.rs +++ b/src/data.rs @@ -31,6 +31,7 @@ pub struct Dashboard { // mining pub production_cost: String, pub reward_ratio: String, + pub break_even_cost: String, // mempool pub txns: String, pub stem: String, @@ -60,6 +61,7 @@ impl Dashboard { difficulty: String::new(), production_cost: String::new(), reward_ratio: String::new(), + break_even_cost: String::new(), txns: String::new(), stem: String::new(), } diff --git a/src/main.rs b/src/main.rs index 3785383..ca71a77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -340,6 +340,14 @@ fn reward_ratio(dashboard: &State>>) -> String { } +#[get("/rpc/mining/breakeven_cost")] +fn breakeven_cost(dashboard: &State>>) -> String { + let data = dashboard.lock().unwrap(); + + format!("$ {}", data.break_even_cost) +} + + #[get("/rpc/network/difficulty")] fn network_difficulty(dashboard: &State>>) -> String { let data = dashboard.lock().unwrap(); @@ -543,8 +551,8 @@ async fn main() { txns_count_24h, block_list, block_link, block_link_color, block_time, block_txns, block_inputs, block_outputs, block_fees, block_weight, block_details_by_height, block_header_by_hash, - soft_supply, production_cost, reward_ratio, last_block_age, - block_list_by_height, block_list_index, search, kernel]) + soft_supply, production_cost, reward_ratio, breakeven_cost, + last_block_age, block_list_by_height, block_list_index, search, kernel]) .mount("/static", FileServer::from("static")) .attach(Template::fairing()) .launch() diff --git a/src/requests.rs b/src/requests.rs index 4a43a41..483640c 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -227,10 +227,13 @@ pub async fn get_mining_stats(dashboard: Arc>) -> Result<(), Er let coins_per_hour = 1.2 / hashrate * 60.0 * 60.0; // Calculating production cost of 1 grin - // Assuming $0,07 per kW/h + // Assuming $0.07 per kW/h data.production_cost = format!("{:.3}", 120.0 / 1000.0 * 0.07 * (1.0 / coins_per_hour)); + data.reward_ratio = format!("{:.2}", data.price_usd.parse::().unwrap() / data.production_cost.parse::().unwrap()); + data.break_even_cost = format!("{:.2}", data.price_usd.parse::().unwrap() + / (120.0 / 1000.0 * (1.0 / coins_per_hour))); } } diff --git a/static/styles/style.css b/static/styles/style.css index c370b84..e4c0286 100644 --- a/static/styles/style.css +++ b/static/styles/style.css @@ -6,8 +6,8 @@ color: #FF7518 !important; } -.grey_background { - background-color: red !important; +.card-background { + background-color: #FBFBFB !important; } a, a:link, a:visited { @@ -52,23 +52,6 @@ div.card { color: black; } -div.rp, -span.rp { - color: red; -} - -div.bluechblk, -span.bluechblk { - color: blue; -} - -div.toast-header, -div.toast-body { - background-color: #f2a900; - color: #14151a; - border-color: #14151a; -} - .nav-item, .nav-link { color: #71797E !important; @@ -154,27 +137,14 @@ footer { border-color: #1f2029; } -.dark-mode div.toast-header, -.dark-mode div.toast-body { - background-color: black; - color: silver; - border-color: #14151a; -} - -.dark-mode div.bluechblk, -.dark-mode span.bluechblk { - color: royalblue; -} - -.dark-mode div.rp, -.dark-mode span.rp { - color: lightcoral; -} - .dark-mode .bg-style { background-color: #14151a !important; } +.dark-mode .card-background { + background-color: #1f2029 !important; +} + .dark-mode a, .dark-mode a:link, .dark-mode a:visited, @@ -222,28 +192,6 @@ footer { border-style: none; } -.dark-mode .pagination .page-item .page-link { - background-color: #14151a; - border-color: silver; -} - -.dark-mode .navbar-nav > li > .dropdown-menu, -.dark-mode .navbar-nav > li > .dropdown-menu a, -.dark-mode .navbar-nav > li > .dropdown-menu a:link, -.dark-mode .navbar-nav > li > .dropdown-menu a:hover { - color: silver; - background-color: #1f2029; -} - -.dark-mode .dropdown-menu { - background-color: #1f2029; -} - -.dark-mode .dropdown-menu .dropdown-item { - color: silver; - background-color: #343a40; -} - .dark-mode .close { color: silver; } diff --git a/templates/index.html.tera b/templates/index.html.tera index e38e85f..a9badb1 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -46,7 +46,7 @@ -  
+

@@ -62,11 +62,10 @@
-
-
-
-
BLOCKCHAIN
-
+
+
+
+
BLOCKCHAIN

Size 
@@ -79,9 +78,24 @@
Time Since Last Block 
+
+
+
+
+
TRANSACTIONS & FEES
+
+
+
1H Period (60 Blocks) 
+
+
+
+
24H Period (1440 Blocks) 
+
+
-
+ +
MINING

@@ -103,7 +117,7 @@ -  
+

@@ -112,27 +126,22 @@ -  
-
-
-
-
-
-
TRANSACTIONS & FEES
-
-
-
1H Period (60 Blocks) 
+

-
24H Period (1440 Blocks) 
+
Breakeven Electricity Cost + + +
-
@@ -222,7 +231,7 @@ -  
+

@@ -277,7 +286,7 @@ -  
+

@@ -286,7 +295,16 @@ -  
+
+ +
+
+
Breakeven Electricity Cost + + +
@@ -419,6 +437,23 @@ + + From ae53bd9e309b62e6f40f78c4824d5c34691d92ba Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Tue, 7 May 2024 21:57:33 +0300 Subject: [PATCH 02/10] update value name --- src/data.rs | 4 ++-- src/main.rs | 2 +- src/requests.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/data.rs b/src/data.rs index ed358d7..da4d1b8 100644 --- a/src/data.rs +++ b/src/data.rs @@ -31,7 +31,7 @@ pub struct Dashboard { // mining pub production_cost: String, pub reward_ratio: String, - pub break_even_cost: String, + pub breakeven_cost: String, // mempool pub txns: String, pub stem: String, @@ -61,7 +61,7 @@ impl Dashboard { difficulty: String::new(), production_cost: String::new(), reward_ratio: String::new(), - break_even_cost: String::new(), + breakeven_cost: String::new(), txns: String::new(), stem: String::new(), } diff --git a/src/main.rs b/src/main.rs index ca71a77..ce0cf74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,7 +344,7 @@ fn reward_ratio(dashboard: &State>>) -> String { fn breakeven_cost(dashboard: &State>>) -> String { let data = dashboard.lock().unwrap(); - format!("$ {}", data.break_even_cost) + format!("$ {}", data.breakeven_cost) } diff --git a/src/requests.rs b/src/requests.rs index 483640c..27e677c 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -232,7 +232,7 @@ pub async fn get_mining_stats(dashboard: Arc>) -> Result<(), Er data.reward_ratio = format!("{:.2}", data.price_usd.parse::().unwrap() / data.production_cost.parse::().unwrap()); - data.break_even_cost = format!("{:.2}", data.price_usd.parse::().unwrap() + data.breakeven_cost = format!("{:.2}", data.price_usd.parse::().unwrap() / (120.0 / 1000.0 * (1.0 / coins_per_hour))); } } From 522c2e412ee14bc4e22f02381e07932d27857fac Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Wed, 8 May 2024 14:06:07 +0300 Subject: [PATCH 03/10] shorten wording --- templates/index.html.tera | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/index.html.tera b/templates/index.html.tera index a9badb1..44dae51 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -85,11 +85,11 @@
TRANSACTIONS & FEES

-
1H Period (60 Blocks) 
+
1H Period 

-
24H Period (1440 Blocks) 
+
24H Period 
@@ -100,7 +100,7 @@
MINING

-
Hashrate (1440 Blocks) 
KG/s
+
Hashrate 
KG/s

@@ -269,7 +269,7 @@
MINING

-
Hashrate (1440 Blocks) 
KG/s
+
Hashrate 
KG/s

@@ -299,7 +299,7 @@

-
Breakeven Electricity Cost +
Breakeven Elec. Cost
From ce04d8c77e49c922e6f255002c837b139fe01c30 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Wed, 8 May 2024 14:13:02 +0300 Subject: [PATCH 04/10] correct diff window --- src/requests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/requests.rs b/src/requests.rs index 27e677c..3ffbb07 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -197,7 +197,7 @@ pub fn get_disk_usage(dashboard: Arc>) -> Result<(), Error> { // Collecting: hashrate, difficulty, production cost. pub async fn get_mining_stats(dashboard: Arc>) -> Result<(), Error> { - let difficulty_window = 60; + let difficulty_window = 1440; let height = get_current_height(dashboard.clone()); if height.is_empty() == false { From 2abae0fc0c28c65f268b4797a1bdab23ca005115 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Wed, 8 May 2024 14:16:49 +0300 Subject: [PATCH 05/10] more wording corrections --- templates/block_details.html.tera | 4 ++-- templates/error.html.tera | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/block_details.html.tera b/templates/block_details.html.tera index aa65dda..01371bf 100644 --- a/templates/block_details.html.tera +++ b/templates/block_details.html.tera @@ -45,7 +45,7 @@ {% for i in range(end=block.ker_len) %}
- {% if block.kernels[i][1] == "Coinbase" %} @@ -92,7 +92,7 @@ {% for i in range(end=block.out_len) %}
- {% if block.outputs[i][1] == "Coinbase" %}
diff --git a/templates/error.html.tera b/templates/error.html.tera index 0b85371..15c7ec0 100644 --- a/templates/error.html.tera +++ b/templates/error.html.tera @@ -7,11 +7,11 @@

No results found.


- Explorer supports requests by block number, block hash or kernel hash.

+ Explorer supports requests by block number, block hash or kernel.

Examples:
Block number - 2765726
Block hash - 0000fc4d93e5717579b955ab840165d96603f009804a228be22da76f6f906a3c
- Kernel hash - 084caeb931b7e8cb73d6419ea74ea157a3cef19f6e9307108a8a808df58437a4ef + Kernel - 084caeb931b7e8cb73d6419ea74ea157a3cef19f6e9307108a8a808df58437a4ef
From bc365a3d17011f8491a0cac0c707e92e46071015 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Wed, 8 May 2024 14:22:33 +0300 Subject: [PATCH 06/10] minor comment update --- src/requests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/requests.rs b/src/requests.rs index 3ffbb07..9960c14 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -195,7 +195,7 @@ pub fn get_disk_usage(dashboard: Arc>) -> Result<(), Error> { } -// Collecting: hashrate, difficulty, production cost. +// Collecting: hashrate, difficulty, production cost, breakeven cost. pub async fn get_mining_stats(dashboard: Arc>) -> Result<(), Error> { let difficulty_window = 1440; let height = get_current_height(dashboard.clone()); From 1fe6179d99fa3425d60739a8121f40b13d31759c Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Wed, 8 May 2024 14:44:14 +0300 Subject: [PATCH 07/10] bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- templates/base.html.tera | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39490aa..b3c3156 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -730,7 +730,7 @@ dependencies = [ [[package]] name = "grin-explorer" -version = "0.1.1" +version = "0.1.2" dependencies = [ "chrono", "colored", diff --git a/Cargo.toml b/Cargo.toml index a243ad9..3a21405 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grin-explorer" -version = "0.1.1" +version = "0.1.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/templates/base.html.tera b/templates/base.html.tera index 69ebb71..8c1c0f0 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -212,7 +212,7 @@ From 91d4a780d75c9e41de89de310d962590df9a189e Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Wed, 8 May 2024 15:13:53 +0300 Subject: [PATCH 08/10] adding (kW/h) --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ce0cf74..feb0e9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,7 +344,7 @@ fn reward_ratio(dashboard: &State>>) -> String { fn breakeven_cost(dashboard: &State>>) -> String { let data = dashboard.lock().unwrap(); - format!("$ {}", data.breakeven_cost) + format!("$ {} (kW/h)", data.breakeven_cost) } From e720f32c2f3e345728ffe129e6eeffbae7a27506 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Fri, 10 May 2024 14:00:39 +0300 Subject: [PATCH 09/10] move hardcoded dir path into config file --- Explorer.toml | 3 +++ src/data.rs | 2 ++ src/requests.rs | 10 +++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Explorer.toml b/Explorer.toml index 6e9e95e..95a7c76 100644 --- a/Explorer.toml +++ b/Explorer.toml @@ -16,3 +16,6 @@ api_secret_path = "~/.grin/main/.api_secret" # Foreign API secret path. foreign_api_secret_path = "~/.grin/main/.foreign_api_secret" +# Path to Grin directory +grin_dir = "~/.grin" + diff --git a/src/data.rs b/src/data.rs index da4d1b8..a8a462c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -138,6 +138,7 @@ pub struct ExplorerConfig { pub user: String, pub api_secret_path: String, pub foreign_api_secret_path: String, + pub grin_dir: String, pub api_secret: String, pub foreign_api_secret: String, } @@ -151,6 +152,7 @@ impl ExplorerConfig { user: String::new(), api_secret_path: String::new(), foreign_api_secret_path: String::new(), + grin_dir: String::new(), api_secret: String::new(), foreign_api_secret: String::new(), } diff --git a/src/requests.rs b/src/requests.rs index 9960c14..b758888 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -35,6 +35,7 @@ lazy_static! { "user" => cfg.user = value, "api_secret_path" => cfg.api_secret_path = value, "foreign_api_secret_path" => cfg.foreign_api_secret_path = value, + "grin_dir" => cfg.grin_dir = value, _ => println!("{} Unknown config setting '{}'.", "[ ERROR ]".red(), name), } } @@ -43,7 +44,8 @@ lazy_static! { shellexpand::tilde(&cfg.api_secret_path))).unwrap(); cfg.foreign_api_secret = fs::read_to_string(format!("{}", shellexpand::tilde(&cfg.foreign_api_secret_path))).unwrap(); - + cfg.grin_dir = format!("{}", shellexpand::tilde(&cfg.grin_dir)); + cfg }; } @@ -187,9 +189,11 @@ pub async fn get_market(dashboard: Arc>) -> Result<(), Error> { // Collecting: disk_usage. pub fn get_disk_usage(dashboard: Arc>) -> Result<(), Error> { let mut data = dashboard.lock().unwrap(); - let grin_dir = format!("{}/.grin", std::env::var("HOME").unwrap()); - data.disk_usage = format!("{:.2}", (get_size(grin_dir).unwrap() as f64) / 1000.0 / 1000.0 / 1000.0); + let chain_data = format!("{}/main/chain_data", CONFIG.grin_dir); + + data.disk_usage = format!("{:.2}", (get_size(chain_data).unwrap() as f64) + / 1000.0 / 1000.0 / 1000.0); Ok(()) } From 0538d73f209e3293d93778b665aceca98d7ab446 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Fri, 10 May 2024 14:18:17 +0300 Subject: [PATCH 10/10] correct borders roundness --- templates/index.html.tera | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/index.html.tera b/templates/index.html.tera index 44dae51..db5e950 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -63,7 +63,7 @@
-
+
BLOCKCHAIN

@@ -80,7 +80,7 @@
-
+
TRANSACTIONS & FEES