From f7b06f5d560b82fefbd8383f7da2fb3eda7d8c51 Mon Sep 17 00:00:00 2001 From: lalanza808 Date: Sun, 5 Apr 2020 00:35:03 -0700 Subject: [PATCH] improve templates and data structs --- src/data_types.rs | 13 ++++++++++--- src/main.rs | 17 ++++++++++++++++- templates/index.html.tera | 32 +++++++------------------------- templates/transaction.html.tera | 4 ++-- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/data_types.rs b/src/data_types.rs index 0989f0b..0cc7a46 100644 --- a/src/data_types.rs +++ b/src/data_types.rs @@ -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, + pub block_timestamp: Option, pub double_spend_seen: bool, pub in_pool: bool, - pub output_indices: Vec, + pub output_indices: Option>, } #[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, 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, diff --git a/src/main.rs b/src/main.rs index 589ea19..d073f27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { + 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 = 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, diff --git a/templates/index.html.tera b/templates/index.html.tera index 77cc120..ee064bc 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -88,39 +88,21 @@

Transactions that have yet to be mined into a block. This is where payments sit in a PENDING state.

+ Received Time Hash - Amount Fee + Inputs / Outputs + Ring Decoys - {% for tx in tx_json %} - -

Ring Sig Type: {{ tx.rct_signatures.type }}

-

Tx Fee: {{ tx.rct_signatures.txnFee }}

-

Extra: {{ tx.extra }}

-

Tx Inputs

- {{ tx.vin | length }} - {% for vin in tx.vin %} -

Amount: {{ vin.key.amount / 1000000000000 }} XMR

-

Key Image: {{ vin.key.k_image }}

-

Key Offsets: {{ vin.key.key_offsets }}

- {% endfor %} -

Tx Outputs

- {% for vout in tx.vout %} -

Amount: {{ vout.amount / 1000000000000 }} XMR

-

Stealth Address: {{ vout.target.key }}

- {% endfor %} - - {% endfor %} - - {% comment %} {% for tx in tx_pool %} - {{ tx.id_hash | truncate(length=8) }} - ? + {{ tx.receive_time }} + {{ tx.id_hash | truncate(length=8) }} {{ tx.fee / 1000000000000 }} XMR + {{ tx.tx_json_full.vin | length }} / {{ tx.tx_json_full.vout | length }} + {{ tx.tx_json_full.vin.0.key.key_offsets | length }} {% endfor %} - {% endcomment %} diff --git a/templates/transaction.html.tera b/templates/transaction.html.tera index 7b7b9de..3dabee4 100644 --- a/templates/transaction.html.tera +++ b/templates/transaction.html.tera @@ -25,7 +25,7 @@

Block Height

-

{{ tx_info.0.block_height }}

+

{% if tx_info.0.block_height %}{{ tx_info.0.block_height }}{% else %}pending{% endif %}

@@ -49,7 +49,7 @@


-

View Block

+ {% if tx_info.0.block_height %}

View Block

{% endif %}