address lookup and qr codes

master
lalanza808 5 years ago
parent 12075ebc02
commit f7b0420e2b

@ -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"

@ -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/<wallet_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?<value>")]
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"))

@ -287,3 +287,8 @@ p.subheader {
.tx-table th, .tx-table td {
text-align: center;
}
.center {
margin: 0 auto;
display: block;
}

@ -0,0 +1,35 @@
{% extends "base" %}
{% block content %}
<section id="main">
<div class="container">
<div class="col-12">
<section>
<header class="major">
<h2>Wallet Address</h2>
<p class="subheader"><strong>Address</strong>: {{ wallet_address }}</p>
</header>
<div class="center">
<img src="data:image/svg+xml;base64,{{ qr_code }}" width=200 class="center">
</div>
<!-- Want to generate a QR code for incoming payment?
<form action="." method="get">
<input type="text" name="amount" placeholder="Enter amount for transaction.">
<input type="submit" value="Search">
</form> -->
</section>
</div>
</div>
</section>
<!--
https://monero.fandom.com/wiki/URI_formatting
address String hierarch. The raw address (or the openalias?).
tx_payment_id String ? The proposed payment ID of the transaction.
recipient_name String ? The proposed contact name of the recipient.
tx_amount UInt64 query The proposed amount of the transaction in floating point units (eg. 5.3 XMR instead of 5300000000000)
tx_description String fragment Describes the transaction which should be initiated.
-->
{% endblock content %}

@ -14,7 +14,7 @@
<nav id="nav">
<div class="search">
<form action="/search" method="get">
<input type="text" name="value" placeholder="Enter a transaction hash, block hash, or block height.">
<input type="text" name="value" placeholder="Enter a transaction hash, block hash, block height, or wallet address.">
<input type="submit" value="Search">
</form>
</div>

@ -9,7 +9,7 @@
<header class="major">
<h2>Block {{ block_header.height }}</h2>
<p class="subheader"><strong>Hash</strong>: {{ block_header.hash }}</p>
<p class="subheader"><strong>Timestamp</strong>: {{ block_header.timestamp }}
<p class="subheader"><strong>Timestamp</strong>: {{ block_header.timestamp }}</p>
</header>
<div class="row">
<div class="col-4 col-6-medium col-12-small">

@ -17,7 +17,7 @@
<header class="major">
<h2>Transaction {{ tx_hash | truncate(length=4) }}</h2>
<p class="subheader"><strong>Full Hash</strong>: {{ tx_hash }}</p>
<p class="subheader"><strong>Block Timestamp</strong>: {{ tx_info.0.block_timestamp }}
<p class="subheader"><strong>Block Timestamp</strong>: {% if tx_info.0.block_timestamp %}{{ tx_info.0.block_timestamp }}{% else %}?{% endif %}</p>
</header>
<div class="row">
<div class="col-4 col-6-medium col-12-small">

Loading…
Cancel
Save