adding custom qr code generation

master
lalanza808 5 years ago
parent 34c4f8e445
commit 1bc234bd61

@ -7,6 +7,7 @@ extern crate qrcode_generator;
mod data_types; mod data_types;
use rocket::http::RawStr; use rocket::http::RawStr;
use rocket::request::Form;
use rocket::response::Redirect; use rocket::response::Redirect;
use rocket_contrib::json::{Json,JsonValue}; use rocket_contrib::json::{Json,JsonValue};
use rocket_contrib::templates::Template; use rocket_contrib::templates::Template;
@ -104,9 +105,22 @@ fn get_transaction_by_hash(tx_hash: String) -> Template {
Template::render("transaction", context) Template::render("transaction", context)
} }
#[get("/address/<wallet_address>")] #[get("/address/<wallet_address>?<tx_amount>&<tx_description>&<recipient_name>&<tx_payment_id>")]
fn show_wallet_address(wallet_address: String) -> Template { fn show_wallet_address(
let address_uri = format!("monero:{}", wallet_address); wallet_address: String,
tx_amount: Option<String>,
tx_description: Option<String>,
recipient_name: Option<String>,
tx_payment_id: Option<String>
) -> Template {
let address_uri = format!(
"monero:{}&tx_amount={}&tx_description={}&recipient_name={}&tx_payment_id={}",
wallet_address,
tx_amount.unwrap_or("".to_string()),
tx_description.unwrap_or("".to_string()),
recipient_name.unwrap_or("".to_string()),
tx_payment_id.unwrap_or("".to_string())
);
let qr_code: String = qrcode_generator::to_svg_to_string(address_uri, QrCodeEcc::Low, 256, None) let qr_code: String = qrcode_generator::to_svg_to_string(address_uri, QrCodeEcc::Low, 256, None)
.unwrap(); .unwrap();
let qr_code: String = base64::encode(qr_code); let qr_code: String = base64::encode(qr_code);
@ -164,11 +178,11 @@ fn search(value: &RawStr) -> Redirect {
} else if sl == 95 { } else if sl == 95 {
// Equal to 95 characters is probably a wallet address. // Equal to 95 characters is probably a wallet address.
// For this let's just redirect to the `show_wallet_address` route. // For this let's just redirect to the `show_wallet_address` route.
return Redirect::found(uri!(show_wallet_address: value.as_str())) return Redirect::found(uri!(show_wallet_address: value.as_str(), "", "", "", ""))
} else if sl == 105 { } else if sl == 105 {
// Equal to 105 characters is probably an integrated address. // Equal to 105 characters is probably an integrated address.
// For this let's just redirect to the `show_wallet_address` route. // For this let's just redirect to the `show_wallet_address` route.
return Redirect::found(uri!(show_wallet_address: value.as_str())) return Redirect::found(uri!(show_wallet_address: value.as_str(), "", "", "", ""))
} else { } else {
// Anything else hasn't been implemented yet // Anything else hasn't been implemented yet
// so redirect to error response. // so redirect to error response.

@ -297,3 +297,13 @@ p.subheader {
margin: 0 auto; margin: 0 auto;
display: block; display: block;
} }
.qr_form form {
text-align: center;
}
.qr_form form input {
width: 75%;
margin: .5em auto;
padding-bottom: 1em;
}

@ -13,23 +13,19 @@
<div class="center"> <div class="center">
<img src="data:image/svg+xml;base64,{{ qr_code }}" width=200 class="center"> <img src="data:image/svg+xml;base64,{{ qr_code }}" width=200 class="center">
</div> </div>
<!-- Want to generate a QR code for incoming payment? <div class="qr_form">
<form action="." method="get"> <p>Want to generate a QR code for incoming payment?</p>
<input type="text" name="amount" placeholder="Enter amount for transaction."> <form action="" method="get">
<input type="submit" value="Search"> <input type="text" name="tx_amount" placeholder="Enter amount for transaction.">
</form> --> <input type="text" name="tx_payment_id" placeholder="Enter a payment ID for transaction.">
<input type="text" name="recipient_name" placeholder="Enter the name of the recipient.">
<input type="text" name="tx_description" placeholder="Enter a description for the transaction.">
<button type="submit" value="">Regenerate QR Code</button>
</form>
</div>
</section> </section>
</div> </div>
</div> </div>
</section> </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 %} {% endblock content %}

Loading…
Cancel
Save