Added blocktime generation
Also refactored the "base" template stuff - really should've done that in a separate commit
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -1,6 +1,7 @@
|
|||||||
#[macro_use] extern crate rocket;
|
#[macro_use] extern crate rocket;
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
use blockchain_time::{BlockchainInfo, BlockchainSupported, update_all_blockheights};
|
use blockchain_time::{BlockchainInfo, BlockchainSupported, update_all_blockheights, time_to_blockheight_specific_chain};
|
||||||
|
use chrono::prelude::*;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> Template {
|
fn index() -> Template {
|
||||||
@@ -22,9 +23,34 @@ fn update_blockchains() -> Template {
|
|||||||
Template::render("update_complete", context!{})
|
Template::render("update_complete", context!{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[get("/to_blockchain_time?<input_datetime>")]
|
||||||
|
fn to_blockchain_time(input_datetime: &str) -> Template {
|
||||||
|
let dt = NaiveDateTime::parse_from_str(input_datetime, "%FT%R");
|
||||||
|
let dt = match dt {
|
||||||
|
Ok(dt) => {
|
||||||
|
dt.and_utc()
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("error: {}", e);
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let blocktimes = vec!{
|
||||||
|
("BSV".to_string(), time_to_blockheight_specific_chain(dt, BlockchainSupported::BSV)),
|
||||||
|
("BTC".to_string(), time_to_blockheight_specific_chain(dt, BlockchainSupported::BTC)),
|
||||||
|
("XMR".to_string(), time_to_blockheight_specific_chain(dt, BlockchainSupported::XMR)),
|
||||||
|
("ETH".to_string(), time_to_blockheight_specific_chain(dt, BlockchainSupported::ETH)),
|
||||||
|
};
|
||||||
|
let context = context!{
|
||||||
|
blocktimes
|
||||||
|
};
|
||||||
|
println!("{:?}", context);
|
||||||
|
Template::render("blockchain_time_results", context)
|
||||||
|
}
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
fn rocket() -> _ {
|
fn rocket() -> _ {
|
||||||
rocket::build().mount("/", routes![index, update_blockchains])
|
rocket::build().mount("/", routes![index, update_blockchains, to_blockchain_time])
|
||||||
// .mount("/update_blockchains", routes![update_blockchains])
|
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
}
|
}
|
||||||
|
|||||||
22
templates/base.html.tera
Normal file
22
templates/base.html.tera
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Big Tim</title>
|
||||||
|
<style>
|
||||||
|
.blockchain_infos {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.blockchain_info {
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
.result {
|
||||||
|
font-family: monospace, monospace;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block content %}{% endblock content %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
templates/blockchain_time_results.html.tera
Normal file
13
templates/blockchain_time_results.html.tera
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Big Tim Results</h1>
|
||||||
|
<div class="blockchain_infos">
|
||||||
|
{% for bts in blocktimes %}
|
||||||
|
<div class="blockchain_info">
|
||||||
|
<h2>{{bts[0]}}</h2>
|
||||||
|
<p>Height: <span class="result">{{bts[1]}}</span></p>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<p>I hope that was useful for you! <a href="/">Go home</a> to try again.
|
||||||
|
{% endblock content %}
|
||||||
@@ -1,42 +1,27 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "base" %}
|
||||||
<html lang="en">
|
{% block content %}
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Big Tim</title>
|
|
||||||
<style>
|
|
||||||
.blockchain_infos {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
.blockchain_info {
|
|
||||||
margin: 20px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Welcome to Blockchain Time</h1><p>A.K.A. Big Tim</p>
|
<h1>Welcome to Blockchain Time</h1><p>A.K.A. Big Tim</p>
|
||||||
<div>
|
<div>
|
||||||
<h2>Convert to Blockchain Time</h2>
|
<h2>Convert to Blockchain Time</h2>
|
||||||
<h3>Yay!</h3>
|
<form id="form" method="GET" action="to_blockchain_time">
|
||||||
<form id="form" method="GET" action="to_blocktime">
|
|
||||||
<label for="input_datetime">Input DateTime (in UTC only currently)</label>
|
<label for="input_datetime">Input DateTime (in UTC only currently)</label>
|
||||||
<input type="datetime-local" id="input_datetime" name="input_datetime">
|
<input type="datetime-local" id="input_datetime" name="input_datetime">
|
||||||
|
<input type="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h2>Convert from Blockchain Time</h2>
|
<h2>Convert from Blockchain Time</h2>
|
||||||
<h3>Booo</h3>
|
<p><b>Booo</b> why are you going this way??? Don't you know your blocktimes??</p>
|
||||||
<p>why are you going this way??? Don't you know your blocktimes??</p>
|
<p><b><i><a href="#">UNIMPLEMENTED</a></i></b></p>
|
||||||
...
|
|
||||||
</div>
|
</div>
|
||||||
<div class="cur_blocks">
|
<div class="cur_blocks">
|
||||||
<h2>Current Block Heights and Times</h2>
|
<h2>Latest Block Heights and Times Cached</h2>
|
||||||
<div class="blockchain_infos">
|
<div class="blockchain_infos">
|
||||||
{% for bi in blockchain_infos %}
|
{% for bi in blockchain_infos %}
|
||||||
<div class="blockchain_info">
|
<div class="blockchain_info">
|
||||||
<h3>{{ bi[0] }}</h3>
|
<h3>{{ bi[0] }}</h3>
|
||||||
<p>Blockheight: {{ bi[1].latest_block_height }}</p>
|
<p>Blockheight: <span class="result">{{ bi[1].latest_block_height }}</span></p>
|
||||||
<p>Time Seen: {{ bi[1].latest_block_time }}
|
<p>Time Seen: <span class="result">{{ bi[1].latest_block_time }}</span></p>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
@@ -44,8 +29,6 @@
|
|||||||
<a href="update_blockchains">Update Blockchain Information</a>
|
<a href="update_blockchains">Update Blockchain Information</a>
|
||||||
<p>Pressing the above button might take some time... or it might crash the appliaction...
|
<p>Pressing the above button might take some time... or it might crash the appliaction...
|
||||||
or it'll do what you want... you won't know till you press it.</p>
|
or it'll do what you want... you won't know till you press it.</p>
|
||||||
|
<p>Please don't press it multiple times</p>
|
||||||
|
<p>In fact, maybe don't press it at all</p>
|
||||||
{{ __tera_context }}
|
{% endblock content %}
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<html>
|
{% extends "base" %}
|
||||||
<head>
|
{% block content %}
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
If you're seeing this, it probably worked. Go back <a href="/">here</a> to check.
|
If you're seeing this, it probably worked. Go back <a href="/">here</a> to check.
|
||||||
</body>
|
{% endblock content %}
|
||||||
</html>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user