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;
|
||||
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("/")]
|
||||
fn index() -> Template {
|
||||
@@ -22,9 +23,34 @@ fn update_blockchains() -> Template {
|
||||
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]
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![index, update_blockchains])
|
||||
// .mount("/update_blockchains", routes![update_blockchains])
|
||||
rocket::build().mount("/", routes![index, update_blockchains, to_blockchain_time])
|
||||
.attach(Template::fairing())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user