Added "From Blockchain Time" / "To Obsolete Time"
I hardly believe it myself, but this "just werkded" (TM) the first time
This commit is contained in:
14
src/lib.rs
14
src/lib.rs
@@ -4,6 +4,7 @@ use rocket::serde::Serialize;
|
|||||||
use std::convert::Into;
|
use std::convert::Into;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use serde_with::{serde_as, DisplayFromStr};
|
use serde_with::{serde_as, DisplayFromStr};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub enum BlockchainSupported {
|
pub enum BlockchainSupported {
|
||||||
BTC,
|
BTC,
|
||||||
@@ -12,6 +13,19 @@ pub enum BlockchainSupported {
|
|||||||
ETH,
|
ETH,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromStr for BlockchainSupported {
|
||||||
|
type Err = String;
|
||||||
|
fn from_str(val: &str) -> Result<Self, Self::Err> {
|
||||||
|
match val {
|
||||||
|
"BTC" => Ok(BlockchainSupported::BTC),
|
||||||
|
"BSV" => Ok(BlockchainSupported::BSV),
|
||||||
|
"XMR" => Ok(BlockchainSupported::XMR),
|
||||||
|
"ETH" => Ok(BlockchainSupported::ETH),
|
||||||
|
_ => Err("You picked an unsupported blockchain type! Create a patch and I'll probably accept it!".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type BlockHeight = i64;
|
type BlockHeight = i64;
|
||||||
|
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@@ -1,6 +1,6 @@
|
|||||||
#[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, time_to_blockheight_specific_chain};
|
use blockchain_time::{BlockchainInfo, BlockchainSupported, update_all_blockheights, time_to_blockheight_specific_chain, blockheight_specific_chain_to_time};
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
@@ -48,8 +48,23 @@ fn to_blockchain_time(input_datetime: &str) -> Template {
|
|||||||
Template::render("blockchain_time_results", context)
|
Template::render("blockchain_time_results", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/to_obsolete_time?<blockheight>&<blockchain>")]
|
||||||
|
fn to_obsolete_time(blockheight: i64, blockchain: &str) -> Template {
|
||||||
|
let blockchain: Result<BlockchainSupported, String> = blockchain.parse();
|
||||||
|
let blockchain = match blockchain {
|
||||||
|
Ok(bl) => bl,
|
||||||
|
Err(err) => {
|
||||||
|
return Template::render("error", context!{ error: err });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let context = context! {
|
||||||
|
time: blockheight_specific_chain_to_time(blockheight, blockchain)
|
||||||
|
};
|
||||||
|
Template::render("obsolete_time", context)
|
||||||
|
}
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
fn rocket() -> _ {
|
fn rocket() -> _ {
|
||||||
rocket::build().mount("/", routes![index, update_blockchains, to_blockchain_time])
|
rocket::build().mount("/", routes![index, update_blockchains, to_blockchain_time, to_obsolete_time])
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<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>
|
||||||
<form id="form" method="GET" action="to_blockchain_time">
|
<form id="to_blocktmie" method="GET" action="to_blockchain_time">
|
||||||
<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">
|
<input type="submit" value="Submit">
|
||||||
@@ -12,7 +12,18 @@
|
|||||||
<div>
|
<div>
|
||||||
<h2>Convert from Blockchain Time</h2>
|
<h2>Convert from Blockchain Time</h2>
|
||||||
<p><b>Booo</b> why are you going this way??? Don't you know your blocktimes??</p>
|
<p><b>Booo</b> why are you going this way??? Don't you know your blocktimes??</p>
|
||||||
<p><b><i><a href="#">UNIMPLEMENTED</a></i></b></p>
|
<form id="to_obsolete_time" method="GET" action="to_obsolete_time">
|
||||||
|
<label for="blockheight">Input Block Height</label>
|
||||||
|
<input type="int" id="blockheight" name="blockheight">
|
||||||
|
<label for="blockchain">Blockchain</label>
|
||||||
|
<select if="blockchain" name="blockchain">
|
||||||
|
<option value="BSV">BSV</option>
|
||||||
|
<option value="BTC">BTC</option>
|
||||||
|
<option value="XMR">XMR</option>
|
||||||
|
<option value="ETH">ETH</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="I'm a weenie that doesn't know my blocktimes">
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="cur_blocks">
|
<div class="cur_blocks">
|
||||||
<h2>Latest Block Heights and Times Cached</h2>
|
<h2>Latest Block Heights and Times Cached</h2>
|
||||||
|
|||||||
7
templates/obsolete_time.html.tera
Normal file
7
templates/obsolete_time.html.tera
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>BOOOOOOOOOOOOOOOOOOO</h1>
|
||||||
|
<h6>here's your obsolete time, in UTC, because timezones are boring to get correct, and no longer needed in the new blocktime order</h6>
|
||||||
|
<p class="result">{{time}}</p>
|
||||||
|
<p>Why don't you go back <a href="/">home</a> and try another thing</p>
|
||||||
|
{% endblock content %}
|
||||||
Reference in New Issue
Block a user