Merge pull request #1 from aglkm/v012

V012
This commit is contained in:
aglkm
2024-05-10 14:35:20 +03:00
committed by GitHub
11 changed files with 105 additions and 100 deletions

2
Cargo.lock generated
View File

@@ -730,7 +730,7 @@ dependencies = [
[[package]]
name = "grin-explorer"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"chrono",
"colored",

View File

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

View File

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

View File

@@ -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(),
}

View File

@@ -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!("$ {} (kW/h)", data.breakeven_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()

View File

@@ -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<Mutex<Dashboard>>) -> Result<(), Error> {
// Collecting: disk_usage.
pub fn get_disk_usage(dashboard: Arc<Mutex<Dashboard>>) -> 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<Mutex<Dashboard>>) -> 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<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.breakeven_cost = format!("{:.2}", data.price_usd.parse::<f64>().unwrap()
/ (120.0 / 1000.0 * (1.0 / coins_per_hour)));
}
}

View File

@@ -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;
}

View File

@@ -212,7 +212,7 @@
<div class="row mb-2">
<div class="col d-flex justify-content-center">
<a class="text-decoration-none" href="https://github.com/aglkm/grin-explorer">
<span style="color:grey">v.0.1.1 <i class="bi bi-github"></i></span>
<span style="color:grey">v.0.1.2 <i class="bi bi-github"></i></span>
</a>
</div>
</div>

View File

@@ -45,7 +45,7 @@
{% for i in range(end=block.ker_len) %}
<br>
<div class="row">
<!-- kernels[i][0] - Hash
<!-- kernels[i][0] - Kernel
kernels[i][1] - Type
kernels[i][2] - Fee -->
{% if block.kernels[i][1] == "Coinbase" %}
@@ -92,7 +92,7 @@
{% for i in range(end=block.out_len) %}
<br>
<div class="row">
<!-- outputs[i][0] - Hash
<!-- outputs[i][0] - Output
outputs[i][1] - Type -->
{% if block.outputs[i][1] == "Coinbase" %}
<div class="col-sm value-text" align="left">

View File

@@ -7,11 +7,11 @@
<div class="card">
<div class="card-body">
<h4>No results found.</h4><br>
Explorer supports requests by block number, block hash or kernel hash.<br><br>
Explorer supports requests by block number, block hash or kernel.<br><br>
Examples:<br>
Block number - <a class="text-decoration-none" href="/block/2765726">2765726</a><br>
Block hash - <a class="text-decoration-none" href="/hash/0000fc4d93e5717579b955ab840165d96603f009804a228be22da76f6f906a3c">0000fc4d93e5717579b955ab840165d96603f009804a228be22da76f6f906a3c</a><br>
Kernel hash - <a class="text-decoration-none" href="/kernel/084caeb931b7e8cb73d6419ea74ea157a3cef19f6e9307108a8a808df58437a4ef">084caeb931b7e8cb73d6419ea74ea157a3cef19f6e9307108a8a808df58437a4ef</a>
Kernel - <a class="text-decoration-none" href="/kernel/084caeb931b7e8cb73d6419ea74ea157a3cef19f6e9307108a8a808df58437a4ef">084caeb931b7e8cb73d6419ea74ea157a3cef19f6e9307108a8a808df58437a4ef</a>
</div>
</div>

View File

@@ -46,7 +46,7 @@
<button class="btn-sm shadow-none" data-bs-toggle="modal" data-bs-target="#soft_sup">
<i class="bi bi-question-circle"></i>
</button>
&nbsp;</div><div class="value-text text-end" hx-get="/rpc/market/soft_supply" hx-trigger="load, every 10s"></div>
</div><div class="value-text text-end" hx-get="/rpc/market/soft_supply" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
@@ -62,11 +62,10 @@
<div class="card-group mb-2">
<div class="card me-2">
<div class="card-body" align="left">
<div class="d-flex justify-content-between">
<div class="darkorange-text"><i class="bi bi-grid"></i> BLOCKCHAIN</div>
</div>
<div class="card card-background me-2">
<div class="card rounded-end-0 mb-2">
<div class="card-body" align="left">
<div class="darkorange-text"><i class="bi bi-grid"></i> BLOCKCHAIN</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">Size&nbsp;</div><div class="value-text text-end" hx-get="/rpc/disk/usage" hx-trigger="load, every 10s"></div>
@@ -79,14 +78,29 @@
<div class="d-flex justify-content-between">
<div class="value-text">Time Since Last Block&nbsp;</div><div class="value-text text-end" hx-get="/rpc/block/time_since_last" hx-trigger="load, every 10s"></div>
</div>
</div>
</div>
<div class="card rounded-end-0">
<div class="card-body" align="left">
<div class="darkorange-text"><i class="bi bi-speedometer2"></i> TRANSACTIONS & FEES</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">1H Period&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_1h" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">24H Period&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_24h" hx-trigger="load, every 10s"></div>
</div>
</div>
</div>
</div>
<div class="card me-2">
<div class="card">
<div class="card-body" align="left">
<div class="darkorange-text"><i class="bi bi-hammer"></i> MINING</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">Hashrate (1440 Blocks)&nbsp;</div><div class="value-text text-end" hx-get="/rpc/network/hashrate" hx-trigger="load, every 10s"> KG/s</div>
<div class="value-text">Hashrate&nbsp;</div><div class="value-text text-end" hx-get="/rpc/network/hashrate" hx-trigger="load, every 10s"> KG/s</div>
</div>
<br>
<div class="d-flex justify-content-between">
@@ -103,7 +117,7 @@
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#mining_cost">
<i class="bi bi-question-circle"></i>
</button>
&nbsp;</div><div class="value-text text-end" hx-get="/rpc/mining/production_cost" hx-trigger="load, every 10s"></div>
</div><div class="value-text text-end" hx-get="/rpc/mining/production_cost" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
@@ -112,27 +126,22 @@
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#ratio">
<i class="bi bi-question-circle"></i>
</button>
&nbsp;</div><div class="value-text text-end" hx-get="/rpc/mining/reward_ratio" hx-trigger="load, every 10s"></div>
</div>
</div>
</div>
<div class="card">
<div class="card-body" align="left">
<div class="darkorange-text"><i class="bi bi-speedometer2"></i> TRANSACTIONS & FEES</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">1H Period (60 Blocks)&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_1h" hx-trigger="load, every 10s"></div>
</div><div class="value-text text-end" hx-get="/rpc/mining/reward_ratio" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">24H Period (1440 Blocks)&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_24h" hx-trigger="load, every 10s"></div>
<div class="value-text">Breakeven Electricity Cost
<!-- Button trigger breakeven explanation modal -->
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#breakeven">
<i class="bi bi-question-circle"></i>
</button>
</div><div class="value-text text-end" hx-get="/rpc/mining/breakeven_cost" hx-trigger="load, every 10s"></div>
</div>
</div>
</div>
</div>
<div class="card-group mb-4">
<div class="card me-2">
<div class="card-body" align="left">
@@ -222,7 +231,7 @@
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#soft_sup">
<i class="bi bi-question-circle"></i>
</button>
&nbsp;</div><div class="value-text text-end" hx-get="/rpc/market/soft_supply" hx-trigger="load, every 10s"></div>
</div><div class="value-text text-end" hx-get="/rpc/market/soft_supply" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
@@ -260,7 +269,7 @@
<div class="darkorange-text"><i class="bi bi-hammer"></i> MINING</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">Hashrate (1440 Blocks)&nbsp;</div><div class="value-text text-end" hx-get="/rpc/network/hashrate" hx-trigger="load, every 10s"> KG/s</div>
<div class="value-text">Hashrate&nbsp;</div><div class="value-text text-end" hx-get="/rpc/network/hashrate" hx-trigger="load, every 10s"> KG/s</div>
</div>
<br>
<div class="d-flex justify-content-between">
@@ -277,7 +286,7 @@
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#mining_cost">
<i class="bi bi-question-circle"></i>
</button>
&nbsp;</div><div class="value-text text-end" hx-get="/rpc/mining/production_cost" hx-trigger="load, every 10s"></div>
</div><div class="value-text text-end" hx-get="/rpc/mining/production_cost" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
@@ -286,7 +295,16 @@
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#ratio">
<i class="bi bi-question-circle"></i>
</button>
&nbsp;</div><div class="value-text text-end" hx-get="/rpc/mining/reward_ratio" hx-trigger="load, every 10s"></div>
</div><div class="value-text text-end" hx-get="/rpc/mining/reward_ratio" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">Breakeven Elec. Cost
<!-- Button trigger breakeven explanation modal -->
<button type="button" class="btn-sm" data-bs-toggle="modal" data-bs-target="#breakeven">
<i class="bi bi-question-circle"></i>
</button>
</div><div class="value-text text-end" hx-get="/rpc/mining/breakeven_cost" hx-trigger="load, every 10s"></div>
</div>
</div>
</div>
@@ -295,11 +313,11 @@
<div class="darkorange-text"><i class="bi bi-speedometer2"></i> TRANSACTIONS & FEES</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">1H Period (60 Blocks)&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_1h" hx-trigger="load, every 10s"></div>
<div class="value-text">1H Period&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_1h" hx-trigger="load, every 10s"></div>
</div>
<br>
<div class="d-flex justify-content-between">
<div class="value-text">24H Period (1440 Blocks)&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_24h" hx-trigger="load, every 10s"></div>
<div class="value-text">24H Period&nbsp;</div><div class="value-text text-end" hx-get="/rpc/txns/count_24h" hx-trigger="load, every 10s"></div>
</div>
</div>
</div>
@@ -419,6 +437,23 @@
</div>
</div>
<div class="modal fade" id="breakeven" tabindex="-1" aria-labelledby="breakeven_label" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="breakeven_label">Breakeven Electricity Cost</h1>
<div data-bs-theme="light">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
</div>
<div class="modal-body">
Electricity threshold cost below which mining is profitable.<br>
Assuming G1-mini ASIC as a miner device.
</div>
</div>
</div>
</div>
</div>
</code>