diff --git a/src/main.rs b/src/main.rs index c282413..0fe4af4 100644 --- a/src/main.rs +++ b/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?")] +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()) } diff --git a/templates/base.html.tera b/templates/base.html.tera new file mode 100644 index 0000000..f530295 --- /dev/null +++ b/templates/base.html.tera @@ -0,0 +1,22 @@ + + + + + Big Tim + + + + {% block content %}{% endblock content %} + + diff --git a/templates/blockchain_time_results.html.tera b/templates/blockchain_time_results.html.tera new file mode 100644 index 0000000..b2324ea --- /dev/null +++ b/templates/blockchain_time_results.html.tera @@ -0,0 +1,13 @@ +{% extends "base" %} +{% block content %} +

Big Tim Results

+
+ {% for bts in blocktimes %} +
+

{{bts[0]}}

+

Height: {{bts[1]}}

+
+ {% endfor %} +
+

I hope that was useful for you! Go home to try again. +{% endblock content %} diff --git a/templates/index.html.tera b/templates/index.html.tera index a6236a7..50063cb 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -1,42 +1,27 @@ - - - - - Big Tim - - - +{% extends "base" %} +{% block content %}

Welcome to Blockchain Time

A.K.A. Big Tim

Convert to Blockchain Time

-

Yay!

-
+ +

Convert from Blockchain Time

-

Booo

-

why are you going this way??? Don't you know your blocktimes??

- ... +

Booo why are you going this way??? Don't you know your blocktimes??

+

UNIMPLEMENTED

-

Current Block Heights and Times

+

Latest Block Heights and Times Cached

{% for bi in blockchain_infos %}

{{ bi[0] }}

-

Blockheight: {{ bi[1].latest_block_height }}

-

Time Seen: {{ bi[1].latest_block_time }} +

Blockheight: {{ bi[1].latest_block_height }}

+

Time Seen: {{ bi[1].latest_block_time }}

{% endfor %} @@ -44,8 +29,6 @@ Update Blockchain Information

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.

- - -{{ __tera_context }} - - +

Please don't press it multiple times

+

In fact, maybe don't press it at all

+{% endblock content %} diff --git a/templates/update_complete.html.tera b/templates/update_complete.html.tera index cb8e650..f67ad34 100644 --- a/templates/update_complete.html.tera +++ b/templates/update_complete.html.tera @@ -1,7 +1,4 @@ - - - - +{% extends "base" %} +{% block content %} If you're seeing this, it probably worked. Go back here to check. - - +{% endblock content %}