adding emission page

This commit is contained in:
aglkm
2024-11-14 15:35:48 +03:00
parent 1717db430b
commit 84d3588708
6 changed files with 226 additions and 24 deletions

17
Cargo.lock generated
View File

@@ -831,6 +831,7 @@ dependencies = [
"serde",
"serde_json",
"shellexpand",
"tera_thousands",
]
[[package]]
@@ -2273,6 +2274,16 @@ dependencies = [
"unic-segment",
]
[[package]]
name = "tera_thousands"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1087c29fa0b4b12ccd41617704e3f89237616185ce11359b433af67fd04ff332"
dependencies = [
"tera",
"thousands",
]
[[package]]
name = "thiserror"
version = "1.0.63"
@@ -2293,6 +2304,12 @@ dependencies = [
"syn",
]
[[package]]
name = "thousands"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
[[package]]
name = "thread_local"
version = "1.1.8"

View File

@@ -6,20 +6,21 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = {version = "0.5.0", features = ["json"]}
serde = {version = "1.0.198", features = ["derive"]}
serde_json = "1.0.111"
num-format = "0.4.4"
fs_extra = "1.3.0"
humantime = "2.1.0"
chrono = "0.4.37"
futures = "0.3.30"
config = "0.14.0"
lazy_static = "1.4.0"
shellexpand = "3.1.0"
either = "1.11.0"
anyhow = "1.0.86"
env_logger = "0.11.3"
rocket = {version = "0.5.0", features = ["json"]}
serde = {version = "1.0.198", features = ["derive"]}
serde_json = "1.0.111"
num-format = "0.4.4"
fs_extra = "1.3.0"
humantime = "2.1.0"
chrono = "0.4.37"
futures = "0.3.30"
config = "0.14.0"
lazy_static = "1.4.0"
shellexpand = "3.1.0"
either = "1.11.0"
anyhow = "1.0.86"
env_logger = "0.11.3"
tera_thousands = "0.1.0"
[dependencies.reqwest]
version = "0.11.23"

View File

@@ -10,6 +10,7 @@ use rocket::serde::json::json;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use serde_json::Value;
use tera_thousands::separate_with_commas;
use crate::data::{Block, Dashboard, Kernel, Output, Statistics, Transactions, OUTPUT_SIZE, KERNEL_SIZE};
use crate::requests::CONFIG;
@@ -131,7 +132,7 @@ async fn kernel(excess: &str) -> Template {
})
}
return Template::render("error", context! {
Template::render("error", context! {
route: "error",
})
}
@@ -151,7 +152,7 @@ async fn output(commit: &str) -> Template {
})
}
return Template::render("error", context! {
Template::render("error", context! {
route: "error",
})
}
@@ -232,6 +233,38 @@ fn stats(statistics: &State<Arc<Mutex<Statistics>>>) -> Template {
}
// Rendering Grinflation page.
#[get("/emission")]
fn emission(dashboard: &State<Arc<Mutex<Dashboard>>>) -> Template {
let data = dashboard.lock().unwrap();
let mut usd = 0.0;
let mut btc = 0.0;
if data.price_usd.is_empty() == false && data.price_btc.is_empty() == false {
usd = data.price_usd.parse::<f64>().unwrap();
btc = data.price_btc.parse::<f64>().unwrap();
}
Template::render("emission", context! {
route: "emission",
cg_api: CONFIG.coingecko_api.clone(),
usd_minute: format!("{:.2}", usd * 60.0),
usd_hour: ((usd * 3600.0) as u64).to_formatted_string(&Locale::en),
usd_day: ((usd * 86400.0) as u64).to_formatted_string(&Locale::en),
usd_week: ((usd * 604800.0) as u64).to_formatted_string(&Locale::en),
usd_month: ((usd * 2592000.0) as u64).to_formatted_string(&Locale::en),
usd_year: ((usd * 31557600.0) as u64).to_formatted_string(&Locale::en),
btc_minute: format!("{:.8}", btc * 60.0),
btc_hour: format!("{:.8}", btc * 3600.0),
btc_day: format!("{:.8}", btc * 86400.0),
btc_week: format!("{:.8}", btc * 604800.0),
btc_month: format!("{:.8}", btc * 2592000.0),
btc_year: format!("{:.8}", btc * 31557600.0),
})
}
// Owner API.
// Whitelisted methods: get_connected_peers, get_peers, get_status.
#[post("/v2/owner", data="<data>")]
@@ -777,9 +810,10 @@ async fn main() {
block_size, block_weight, block_details_by_height, block_header_by_hash,
soft_supply, production_cost, reward_ratio, breakeven_cost,
last_block_age, block_list_by_height, block_list_index, search, kernel,
output, api_owner, api_foreign, stats, unspent_outputs, kernels])
output, api_owner, api_foreign, stats, unspent_outputs, kernels,
emission])
.mount("/static", FileServer::from("static"))
.attach(Template::fairing())
.attach(Template::custom(|engines| {engines.tera.register_filter("separate_with_commas", separate_with_commas)}))
.launch()
.await;
}

View File

@@ -6,6 +6,10 @@
color: #FF7518 !important;
}
.green-text {
color: #5cb85c !important;
}
.card-background {
background-color: #FBFBFB !important;
}

View File

@@ -47,6 +47,9 @@
<li class="nav-item">
<a class="nav-link" href="/stats"><i class="bi bi-calculator"></i> Statistics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/emission"><i class="bi bi-graph-down-arrow"></i> Emission</a>
</li>
{% elif route == "block_list" or route == "block_list_by_height" %}
<li class="nav-item">
<a class="nav-link" href="/"><i class="bi bi-speedometer"></i> Dashboard</a>
@@ -57,6 +60,9 @@
<li class="nav-item">
<a class="nav-link" href="/stats"><i class="bi bi-calculator"></i> Statistics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/emission"><i class="bi bi-graph-down-arrow"></i> Emission</a>
</li>
{% elif route == "stats" %}
<li class="nav-item">
<a class="nav-link" href="/"><i class="bi bi-speedometer"></i> Dashboard</a>
@@ -67,6 +73,22 @@
<li class="nav-item">
<a class="nav-link" href="/stats"><div class="darkorange-text"><i class="bi bi-calculator"></i> Statistics</div></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/emission"><i class="bi bi-graph-down-arrow"></i> Emission</a>
</li>
{% elif route == "emission" %}
<li class="nav-item">
<a class="nav-link" href="/"><i class="bi bi-speedometer"></i> Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/block_list"><i class="bi bi-box"></i> Blocks</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/stats"><i class="bi bi-calculator"></i> Statistics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/emission"><div class="darkorange-text"><i class="bi bi-graph-down-arrow"></i> Emission</div></a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="/"><i class="bi bi-speedometer"></i> Dashboard</a>
@@ -77,6 +99,9 @@
<li class="nav-item">
<a class="nav-link" href="/stats"><i class="bi bi-calculator"></i> Statistics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/emission"><i class="bi bi-graph-down-arrow"></i> Emission</a>
</li>
{% endif %}
</ul>
@@ -190,12 +215,6 @@
</div>
</div>
<br>
<div class="d-flex justify-content-start">
<div class="value-text">
<a class="text-decoration-none" href="https://grinflation.com/">Grinflation</a>
</div>
</div>
<br>
<div class="d-flex justify-content-start">
<div class="value-text">
<a class="text-decoration-none" href="https://grinexplorer.net/">Grinexplorer</a>

View File

@@ -0,0 +1,127 @@
{% extends "base" %}
{% block content %}
{% if cg_api == "enabled" %}
<code>
<div class="card border-start-0 border-end-0 border-bottom-0 rounded-0">
<div class="card-body" align="center">
<h5>Inflation Rate</h5>
<h5><span class="green-text" hx-get="/rpc/inflation/rate" hx-trigger="load, every 10s">%</span></h5>
<br>
<h5>Price</h5>
<h5><span class="green-text" hx-get="/rpc/price/usd" hx-trigger="load, every 10s"></span> <span class="darkorange-text" hx-get="/rpc/price/btc" hx-trigger="load, every 10s"></span></h5><br>
<h5>Supply</h5>
<h5><span class="green-text" hx-get="/rpc/market/supply" hx-trigger="load, every 10s">/span></h5>
<br>
<h5>Market Cap</h5>
<h5><span class="green-text" hx-get="/rpc/market/cap_usd" hx-trigger="load, every 10s"></span> <span class="darkorange-text" hx-get="/rpc/market/cap_btc" hx-trigger="load, every 10s"></span></h5>
</div>
</div>
</code>
<div class="card border-start-0 border-end-0 border-top-0 border-bottom-0 rounded-0">
<div class="card-body" align=center>
<figure class="text-center">
<blockquote class="blockquote">
<p class="fw-lighter">Grin was started with as fair of a launch as possible for what's under our control. We did this for good reason: we believe in Grin's mission to enable private money for everyone and open access to it.</p>
</blockquote>
<figcaption class="blockquote-footer">
<cite title="Source Title">Ignotus Peverell</cite>
</figcaption>
</figure>
</div>
</div>
<code>
<div class="card border-start-0 border-end-0 border-top-0 border-bottom-0 rounded-0">
<div class="card-body" align=center>
<div><h5>Emission <i class="bi bi-fire"></i> 1 GRIN/SEC</h5></div>
<br>
<h6>
1 Minute ツ 60<br>
<span class="green-text">$ {{ usd_minute }} </span>
<span class="darkorange-text">{{ btc_minute }}</span>
</h6>
<br>
<h6>
1 Hour ツ 3,600<br>
<span class="green-text">$ {{ usd_hour }} </span>
<span class="darkorange-text">₿ {{ btc_hour }}</span>
</h6>
<br>
<h6>
1 Day ツ 86,400<br>
<span class="green-text">$ {{ usd_day }} </span>
<span class="darkorange-text">₿ {{ btc_day }}</span>
</h6>
<br>
<h6>
1 Week ツ 604,800<br>
<span class="green-text">$ {{ usd_week }} </span>
<span class="darkorange-text">₿ {{ btc_week }}</span>
</h6>
<br>
<h6>
1 Month ツ 2,592,000<br>
<span class="green-text">$ {{ usd_month }} </span>
<span class="darkorange-text">₿ {{ btc_month }}</span>
</h6>
<br>
<h6>
1 Year ツ 31,557,600<br>
<span class="green-text">$ {{ usd_year }} </span>
<span class="darkorange-text">₿ {{ btc_year }}</span>
</h6>
</div>
</div>
</code>
<div class="card border-start-0 border-end-0 border-top-0 border-bottom-0 rounded-0">
<div class="card-body" align=center>
<figure class="text-center">
<blockquote class="blockquote">
<p class="fw-lighter">I don't measure grin's success by its marketcap, but by its elegance, simplicity, scalability and long term survival.</p>
</blockquote>
<figcaption class="blockquote-footer">
<cite title="Source Title">John Tromp</cite>
</figcaption>
</figure>
</div>
</div>
{% endif %}
<code>
<div class="card border-start-0 border-end-0 border-top-0 rounded-0">
<div class="card-body" align=center>
<div><h5>Inflation Rate by Year</span><h5></div>
<br>
<h6>
<span class="text-secondary">2019</span> ツ 0 <i class="bi bi-dash-lg"></i>
</h6>
{% for i in range(end=100) %}
<br>
<h6>
<span class="text-secondary">{{ 2019 + i + 1 }}</span> ツ {{ ((i + 1) * 31557600) | separate_with_commas }}
<span class="green-text">
{{ (31557600 / ((i + 1) * 31557600)) * 100 | round(method="ceil", precision=2)}} %
</span>
</h6>
{% endfor %}
</div>
</div>
</code>
{% endblock %}