improve templates and data structs

master
lalanza808 4 years ago
parent 24c7d02b3d
commit f7b06f5d56

@ -123,11 +123,11 @@ pub struct GetTransactions {
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct GetTransactionsTxs {
pub block_height: u32,
pub block_timestamp: i64,
pub block_height: Option<u32>,
pub block_timestamp: Option<i64>,
pub double_spend_seen: bool,
pub in_pool: bool,
pub output_indices: Vec<u32>,
pub output_indices: Option<Vec<u32>>,
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
@ -177,9 +177,16 @@ pub struct Transactions {
pub relayed: bool,
pub tx_blob: String,
pub tx_json: String,
pub tx_json_full: Option<TransactionJSON>,
pub weight: u32
}
impl Transactions {
pub fn process(&mut self) {
self.tx_json_full = Some(serde_json::from_str(&self.tx_json).unwrap())
}
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct TransactionJSON {
pub version: u32,

@ -7,7 +7,7 @@ mod data_types;
use rocket::http::RawStr;
use rocket::response::Redirect;
use rocket_contrib::json::JsonValue;
use rocket_contrib::json::{Json,JsonValue};
use rocket_contrib::templates::Template;
use rocket_contrib::serve::StaticFiles;
use reqwest::blocking::{RequestBuilder, Client};
@ -147,6 +147,19 @@ 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, true
).send().unwrap().json().unwrap();
for f in &mut tx_pool.transactions {
f.process();
};
Json(tx_pool)
}
#[get("/")]
fn index() -> Template {
let daemon_info: GetInfo = issue_rpc(&"get_info", None)
@ -159,6 +172,7 @@ fn index() -> Template {
let mut tx_json_raw: Vec<TransactionJSON> = vec![];
for f in &mut tx_pool.transactions {
f.process();
let j: TransactionJSON = serde_json::from_str(&f.tx_json).unwrap();
tx_json_raw.push(j)
};
@ -196,6 +210,7 @@ fn main() {
.mount("/", routes![
index,
search,
show_tx_pool,
get_block_by_height,
get_block_by_hash,
get_transaction_by_hash,

@ -88,39 +88,21 @@
<p>Transactions that have yet to be mined into a block. This is where payments sit in a PENDING state.</p>
</caption>
<tr>
<th>Received Time</th>
<th>Hash</th>
<th>Amount</th>
<th>Fee</th>
<th>Inputs / Outputs</th>
<th>Ring Decoys</th>
</tr>
{% for tx in tx_json %}
<p>Ring Sig Type: {{ tx.rct_signatures.type }}</p>
<p>Tx Fee: {{ tx.rct_signatures.txnFee }}</p>
<p>Extra: {{ tx.extra }}</p>
<h1>Tx Inputs</h1>
{{ tx.vin | length }}
{% for vin in tx.vin %}
<p>Amount: {{ vin.key.amount / 1000000000000 }} XMR</p>
<p>Key Image: {{ vin.key.k_image }}</p>
<p>Key Offsets: {{ vin.key.key_offsets }}</p>
{% endfor %}
<h1>Tx Outputs</h1>
{% for vout in tx.vout %}
<p>Amount: {{ vout.amount / 1000000000000 }} XMR</p>
<p>Stealth Address: {{ vout.target.key }}</p>
{% endfor %}
{% endfor %}
{% comment %}
{% for tx in tx_pool %}
<tr>
<td>{{ tx.id_hash | truncate(length=8) }}</td>
<td>?</td>
<td>{{ tx.receive_time }}</td>
<td><a href="/transaction/{{ tx.id_hash }}">{{ tx.id_hash | truncate(length=8) }}</a></td>
<td>{{ tx.fee / 1000000000000 }} XMR</td>
<td>{{ tx.tx_json_full.vin | length }} / {{ tx.tx_json_full.vout | length }}</td>
<td>{{ tx.tx_json_full.vin.0.key.key_offsets | length }}</td>
</tr>
{% endfor %}
{% endcomment %}
</table>
</div>
</header>

@ -25,7 +25,7 @@
<header>
<h3>Block Height</h3>
</header>
<p>{{ tx_info.0.block_height }}</p>
<p>{% if tx_info.0.block_height %}{{ tx_info.0.block_height }}{% else %}pending{% endif %}</p>
</section>
</div>
<div class="col-4 col-6-medium col-12-small">
@ -49,7 +49,7 @@
</div>
<br><br>
<header class="major">
<h2><a href="/block/height/{{ tx_info.0.block_height }}">View Block</a></h2>
{% if tx_info.0.block_height %}<h2><a href="/block/height/{{ tx_info.0.block_height }}">View Block</a></h2>{% endif %}
</header>
</div>
</section>

Loading…
Cancel
Save