From f7b0420e2b4f2f59c4e61ca1da664937280ba7d7 Mon Sep 17 00:00:00 2001 From: lalanza808 Date: Sun, 5 Apr 2020 22:00:25 -0700 Subject: [PATCH] address lookup and qr codes --- Cargo.toml | 2 ++ src/main.rs | 24 ++++++++++++++++++++++ static/css/main.css | 5 +++++ templates/address.html.tera | 35 +++++++++++++++++++++++++++++++++ templates/base.html.tera | 2 +- templates/block.html.tera | 2 +- templates/transaction.html.tera | 2 +- 7 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 templates/address.html.tera diff --git a/Cargo.toml b/Cargo.toml index 4b11697..1170ef2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,5 @@ serde_json = "1.0" serde_derive = "1.0" reqwest = { version = "0.10.4", features = ["blocking", "json"] } openssl = { version = "0.10", features = ["vendored"] } +qrcode-generator = "1.0.6" +base64 = "0.12.0" diff --git a/src/main.rs b/src/main.rs index d073f27..eae9324 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate rocket_contrib; #[macro_use] extern crate serde_derive; extern crate reqwest; +extern crate qrcode_generator; mod data_types; use rocket::http::RawStr; @@ -12,6 +13,7 @@ use rocket_contrib::templates::Template; use rocket_contrib::serve::StaticFiles; use reqwest::blocking::{RequestBuilder, Client}; use reqwest::Error; +use qrcode_generator::QrCodeEcc; use std::env; use data_types::*; @@ -96,6 +98,19 @@ fn get_transaction_by_hash(tx_hash: String) -> Template { Template::render("transaction", context) } +#[get("/address/")] +fn show_wallet_address(wallet_address: String) -> Template { + let address_uri = format!("monero:{}", wallet_address); + let qr_code: String = qrcode_generator::to_svg_to_string(address_uri, QrCodeEcc::Low, 256, None) + .unwrap(); + let qr_code: String = base64::encode(qr_code); + let context: JsonValue = json!({ + "qr_code": qr_code, + "wallet_address": wallet_address + }); + Template::render("address", context) +} + #[get("/search?")] fn search(value: &RawStr) -> Redirect { // This search implementation is not ideal but it works. @@ -140,6 +155,14 @@ fn search(value: &RawStr) -> Redirect { } } } + } else if sl == 95 { + // Equal to 95 characters is probably a wallet address. + // For this let's just redirect to the `show_wallet_address` route. + return Redirect::found(uri!(show_wallet_address: value.as_str())) + } else if sl == 105 { + // Equal to 105 characters is probably an integrated address. + // For this let's just redirect to the `show_wallet_address` route. + return Redirect::found(uri!(show_wallet_address: value.as_str())) } else { // Anything else hasn't been implemented yet // so redirect to error response. @@ -214,6 +237,7 @@ fn main() { get_block_by_height, get_block_by_hash, get_transaction_by_hash, + show_wallet_address, error ]) .mount("/static", StaticFiles::from("./static")) diff --git a/static/css/main.css b/static/css/main.css index e69fa21..abc5df0 100755 --- a/static/css/main.css +++ b/static/css/main.css @@ -287,3 +287,8 @@ p.subheader { .tx-table th, .tx-table td { text-align: center; } + +.center { + margin: 0 auto; + display: block; +} diff --git a/templates/address.html.tera b/templates/address.html.tera new file mode 100644 index 0000000..99818f6 --- /dev/null +++ b/templates/address.html.tera @@ -0,0 +1,35 @@ +{% extends "base" %} + +{% block content %} + +
+
+
+
+
+

Wallet Address

+

Address: {{ wallet_address }}

+
+
+ +
+ +
+
+
+
+ + + +{% endblock content %} diff --git a/templates/base.html.tera b/templates/base.html.tera index 88229e5..39a6c33 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -14,7 +14,7 @@