clean up code, add prove sending page and form

master
lza_menace 3 years ago
parent 8d0709240a
commit d9b7629931

1
.gitignore vendored

@ -3,3 +3,4 @@
docker-compose.prod.yml docker-compose.prod.yml
docker-compose.stage.yml docker-compose.stage.yml
docker-compose.dev.yml docker-compose.dev.yml
data

@ -243,3 +243,17 @@ pub struct QRData {
pub recipient_name: String, pub recipient_name: String,
pub tx_payment_id: String pub tx_payment_id: String
} }
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)]
pub struct CheckTxKeyResponse {
pub jsonrpc: String,
pub id: u32,
pub result: Option<CheckTxKeyResult>
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug, Clone)]
pub struct CheckTxKeyResult {
pub confirmations: u32,
pub in_pool: bool,
pub received: u64,
}

@ -42,8 +42,6 @@ fn build_rpc(method: &str, raw_data: Option<JsonValue>, raw: bool) -> RequestBui
#[get("/block/hash/<block_hash>")] #[get("/block/hash/<block_hash>")]
fn get_block_by_hash(block_hash: String) -> Template { fn get_block_by_hash(block_hash: String) -> Template {
// https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_block
// http POST crypto.int.lzahq.tech:34568/json_rpc method=get_block params:='{"hash": "83faf32a04708bead3e712947b8ad8e1e6ab50f3093948bfb3e71fb0089a7b68"}'
let payload: JsonValue = json!({ let payload: JsonValue = json!({
"method": "get_block", "method": "get_block",
"params": { "params": {
@ -59,8 +57,6 @@ fn get_block_by_hash(block_hash: String) -> Template {
#[get("/block/height/<block_height>")] #[get("/block/height/<block_height>")]
fn get_block_by_height(block_height: String) -> Template { fn get_block_by_height(block_height: String) -> Template {
// https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_block
// http POST crypto.int.lzahq.tech:34568/json_rpc method=get_block params:='{"height": 225460}'
let payload: JsonValue = json!({ let payload: JsonValue = json!({
"method": "get_block", "method": "get_block",
"params": { "params": {
@ -74,11 +70,31 @@ fn get_block_by_height(block_height: String) -> Template {
Template::render("block", &res.result) Template::render("block", &res.result)
} }
#[get("/receipt?<address>&<tx_hash>&<tx_key>")]
fn get_tx_receipt(address: String, tx_hash: String, tx_key: String) -> Template {
let payload: JsonValue = json!({
"method": "check_tx_key",
"params": {
"address": address,
"txid": tx_hash,
"tx_key": tx_key
}
});
let http_client = Client::new();
let wallet_uri = env::var("WALLET_URI").unwrap();
let uri = format!("{}/json_rpc", &wallet_uri);
let res: CheckTxKeyResponse = http_client.post(&uri).json(&payload)
.send().unwrap().json().unwrap();
let context = json!({
"res": &res.result,
"tx_hash": tx_hash,
"address": address
});
Template::render("receipt", context)
}
#[get("/transaction/<tx_hash>")] #[get("/transaction/<tx_hash>")]
fn get_transaction_by_hash(tx_hash: String) -> Template { fn get_transaction_by_hash(tx_hash: String) -> Template {
// https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#get_transactions
// echo '{"txs_hashes": ["98f68768d258544856e0b6c3a3aac8773a094fe184f9b9daba1554a9d8fc2e02"], "decode_as_json": true}' \
// | http POST crypto.int.lzahq.tech:34568/get_transactions
let params: JsonValue = json!({ let params: JsonValue = json!({
"txs_hashes": [&tx_hash], "txs_hashes": [&tx_hash],
"decode_as_json": true "decode_as_json": true
@ -198,19 +214,6 @@ fn search(value: &RawStr) -> Redirect {
}; };
} }
// #[get("/tx_pool")]
// fn show_tx_pool() -> Json<GetTransactionPool> {
// let mut tx_pool: GetTransactionPool = build_rpc(
// &"get_transaction_pool", None, None, true
// ).send().unwrap().json().unwrap();
//
// for f in &mut tx_pool.transactions {
// f.process();
// };
//
// Json(tx_pool)
// }
#[get("/")] #[get("/")]
fn index() -> Template { fn index() -> Template {
let daemon_uri = env::var("DAEMON_URI").unwrap(); let daemon_uri = env::var("DAEMON_URI").unwrap();
@ -265,6 +268,7 @@ fn main() {
get_block_by_height, get_block_by_height,
get_block_by_hash, get_block_by_hash,
get_transaction_by_hash, get_transaction_by_hash,
get_tx_receipt,
show_wallet_address, show_wallet_address,
error error
]) ])

@ -2078,7 +2078,7 @@ input, select, textarea {
/* Nav */ /* Nav */
#nav { #nav {
margin: 2.5em 0 0 0; margin: .5em 0 0 0;
} }
#nav > ul { #nav > ul {

@ -6,8 +6,8 @@
<div class="container"> <div class="container">
<section id="header"> <section id="header">
<nav id="nav"> <nav id="nav">
<a href="/"><h1>Go Back</h1><br> <a href="/"><h1>Go Back</h1>
<img src="//files.lzahq.tech/wow/WOW-Bux-720x435.png" width=300 /> <img src="//files.lzahq.tech/wow/WOW-Bux-720x435.png" width=250 />
</a> </a>
</nav> </nav>
</section> </section>

@ -6,8 +6,8 @@
<div class="container"> <div class="container">
<section id="header"> <section id="header">
<nav id="nav"> <nav id="nav">
<a href="/"><h1>Go Back</h1><br> <a href="/"><h1>Go Back</h1>
<img src="//files.lzahq.tech/wow/Wownero-Mine-Stock-720x500.png" width=300 /> <img src="//files.lzahq.tech/wow/Wownero-Mine-Stock-720x500.png" width=250 />
</a> </a>
</nav> </nav>
</section> </section>

@ -7,7 +7,7 @@
<section id="header"> <section id="header">
<h1>Wownero Block Explorer</h1> <h1>Wownero Block Explorer</h1>
<nav id="nav"> <nav id="nav">
<img src="//files.lzahq.tech/wow/Wownero-Development-Stock-720x440.png"/ width=300> <img src="//files.lzahq.tech/wow/Wownero-Development-Stock-720x440.png"/ width=250>
<div class="search"> <div class="search">
<form action="/search" method="get"> <form action="/search" method="get">
<input type="text" name="value" placeholder="Enter a transaction hash, block hash, block height, or wallet address."> <input type="text" name="value" placeholder="Enter a transaction hash, block hash, block height, or wallet address.">

@ -0,0 +1,61 @@
{% extends "base" %}
{% block content %}
<section id="main">
<div class="container">
<section id="header">
<nav id="nav">
<a href="/"><h1>Go Home</h1><br />
<img src="//files.lzahq.tech/wow/WOW-Stack-720x455.png" width=150 />
</a>
</nav>
</section>
<div class="col-12">
<section>
<header class="major">
<h2>Confirm TX Receipt</h2>
{% if res %}
<p class="subheader"><strong>To Address</strong>: {{ address }}</p>
<p class="subheader"><strong>Transaction ID</strong>: {{ tx_hash }}</p>
</header>
<div class="row">
<div class="col-4 col-6-medium col-12-small">
<section class="box">
<header>
<h3>Confirmations</h3>
</header>
<p>{{ res.confirmations }}</p>
</section>
</div>
<div class="col-4 col-6-medium col-12-small">
<section class="box">
<header>
<h3>Amount</h3>
</header>
<p>{{ res.received / 100000000000 }} WOW</p>
</section>
</div>
<div class="col-4 col-6-medium col-12-small">
<section class="box">
<header>
<h3>In Pool</h3>
</header>
<p>{{ res.in_pool }}</p>
</section>
</div>
</div>
{% else %}
<p class="subheader"><strong>Invalid Confirmation</strong></p>
{% endif %}
</section>
</div>
<br><br>
<header class="major">
<h2><a href="/transaction/{{ tx_hash }}">View Transaction</a></h2>
</header>
</div>
</section>
{% endblock content %}

@ -6,8 +6,8 @@
<div class="container"> <div class="container">
<section id="header"> <section id="header">
<nav id="nav"> <nav id="nav">
<a href="/"><h1>Go Back</h1><br> <a href="/"><h1>Go Back</h1>
<img src="//files.lzahq.tech/wow/WOW-Teleporter-720x1180.png" height=220 /> <img src="//files.lzahq.tech/wow/WOW-Teleporter-720x1180.png" height=200 />
</a> </a>
</nav> </nav>
</section> </section>
@ -69,8 +69,15 @@
</div> </div>
</div> </div>
</section> </section>
</div> <section>
<br><br> <h1 class="center">Prove Sending</h1>
<form method="get" action="/receipt" class="center">
<input type="text" name="tx_hash" placeholder="Transaction Hash / ID" value="{{ tx_hash }}" type="hidden" class="hidden">
<input type="text" name="address" placeholder="Address">
<input type="text" name="tx_key" placeholder="Transaction Key">
<input type="submit" value="Prove" class="btn">
</form>
</section>
<div class="tx-table"> <div class="tx-table">
<table> <table>
<caption><h2>Inputs ({{ tx_info.0.as_json_full.vin | length | default(value="?") }})</h2></caption> <caption><h2>Inputs ({{ tx_info.0.as_json_full.vin | length | default(value="?") }})</h2></caption>
@ -110,4 +117,26 @@
</div> </div>
</section> </section>
<style>
.center {
margin: 0 auto;
display: block;
text-align: center;
}
.hidden {
display: none;
}
h1 {
font-size: 2em;
padding-bottom: 1em;
}
input[type=text] {
width: 50%;
margin: 1em;
}
input[type=submit] {
margin: 1em;
}
</style>
{% endblock content %} {% endblock content %}

Loading…
Cancel
Save