mirror of
https://github.com/transatoshi-mw/grin-explorer.git
synced 2025-10-22 05:43:42 +00:00
adding breakeven cost
This commit is contained in:
@@ -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(),
|
||||
}
|
||||
|
12
src/main.rs
12
src/main.rs
@@ -340,6 +340,14 @@ fn reward_ratio(dashboard: &State<Arc<Mutex<Dashboard>>>) -> String {
|
||||
}
|
||||
|
||||
|
||||
#[get("/rpc/mining/breakeven_cost")]
|
||||
fn breakeven_cost(dashboard: &State<Arc<Mutex<Dashboard>>>) -> String {
|
||||
let data = dashboard.lock().unwrap();
|
||||
|
||||
format!("$ {}", data.break_even_cost)
|
||||
}
|
||||
|
||||
|
||||
#[get("/rpc/network/difficulty")]
|
||||
fn network_difficulty(dashboard: &State<Arc<Mutex<Dashboard>>>) -> 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()
|
||||
|
@@ -227,10 +227,13 @@ pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>) -> 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::<f64>().unwrap()
|
||||
/ data.production_cost.parse::<f64>().unwrap());
|
||||
data.break_even_cost = format!("{:.2}", data.price_usd.parse::<f64>().unwrap()
|
||||
/ (120.0 / 1000.0 * (1.0 / coins_per_hour)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user