Also refactored the "base" template stuff - really should've done that in a separate commit
57 lines
1.9 KiB
Rust
57 lines
1.9 KiB
Rust
#[macro_use] extern crate rocket;
|
|
use rocket_dyn_templates::{context, Template};
|
|
use blockchain_time::{BlockchainInfo, BlockchainSupported, update_all_blockheights, time_to_blockheight_specific_chain};
|
|
use chrono::prelude::*;
|
|
|
|
#[get("/")]
|
|
fn index() -> Template {
|
|
let blockchain_infos: Vec<(String, BlockchainInfo)> = vec!{
|
|
("BSV".to_string(), BlockchainSupported::BSV.into()),
|
|
("BTC".to_string(), BlockchainSupported::BTC.into()),
|
|
("XMR".to_string(), BlockchainSupported::XMR.into()),
|
|
("ETH".to_string(), BlockchainSupported::ETH.into()),
|
|
};
|
|
let context = context! {
|
|
blockchain_infos
|
|
};
|
|
Template::render("index", context)
|
|
}
|
|
|
|
#[get("/update_blockchains")]
|
|
fn update_blockchains() -> Template {
|
|
update_all_blockheights();
|
|
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, to_blockchain_time])
|
|
.attach(Template::fairing())
|
|
}
|