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/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 b6164c5..a8a462c 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 breakeven_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(), + breakeven_cost: String::new(), txns: String::new(), stem: String::new(), } @@ -136,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, } @@ -149,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/main.rs b/src/main.rs index 3785383..feb0e9a 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!("$ {} (kW/h)", data.breakeven_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..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,17 +189,19 @@ 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(()) } -// 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 = 60; + let difficulty_window = 1440; let height = get_current_height(dashboard.clone()); if height.is_empty() == false { @@ -227,10 +231,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.breakeven_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/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 @@ 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
diff --git a/templates/index.html.tera b/templates/index.html.tera index e38e85f..db5e950 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -46,7 +46,7 @@ -  
+

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

Size 
@@ -79,14 +78,29 @@
Time Since Last Block 
+
+
+
+
+
TRANSACTIONS & FEES
+
+
+
1H Period 
+
+
+
+
24H Period 
+
+
-
+ +
MINING

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

@@ -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 @@ -  
+

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

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

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

@@ -286,7 +295,16 @@ -  
+
+ +
+
+
Breakeven Elec. Cost + + +
@@ -295,11 +313,11 @@
TRANSACTIONS & FEES

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

-
24H Period (1440 Blocks) 
+
24H Period 
@@ -419,6 +437,23 @@ + +