From f3393824e4bc3c9a26fcf4d5559ae752cc011fca Mon Sep 17 00:00:00 2001 From: lalanza808 Date: Fri, 3 Apr 2020 23:19:08 -0700 Subject: [PATCH] setting up tx pool --- src/data_types.rs | 38 ++++++++++++++++++++++++++++++++++++-- src/main.rs | 39 ++++++++++++++++++++++++++++++++++++--- static/css/main.css | 4 ++++ templates/index.html.tera | 35 +++++++++++++++++++++++++---------- 4 files changed, 101 insertions(+), 15 deletions(-) diff --git a/src/data_types.rs b/src/data_types.rs index 0916eb8..9b46049 100644 --- a/src/data_types.rs +++ b/src/data_types.rs @@ -2,7 +2,7 @@ pub struct RPCPayload { pub jsonrpc: String, pub id: String, - pub method: String, + pub method: Option, pub params: Option } @@ -11,7 +11,7 @@ impl Default for RPCPayload { RPCPayload { jsonrpc: "2.0".to_string(), id: "0".to_string(), - method: "get_info".to_string(), + method: None, params: None, } } @@ -144,3 +144,37 @@ pub struct GetBlockResult { pub miner_tx_hash: String, pub tx_hashes: Option>, } + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)] +pub struct GetTransactionPool { + pub credits: u32, + pub spent_key_images: Vec, + pub status: String, + pub top_hash: String, + pub transactions: Vec +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)] +pub struct SpentKeyImages { + pub id_hash: String, + pub txs_hashes: Vec +} + +#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)] +pub struct Transactions { + pub blob_size: u32, + pub do_not_relay: bool, + pub double_spend_seen: bool, + pub fee: u64, + pub id_hash: String, + pub kept_by_block: bool, + pub last_failed_height: u32, + pub last_failed_id_hash: String, + pub last_relayed_time: i64, + pub max_used_block_height: u32, + pub max_used_block_id_hash: String, + pub receive_time: i64, + pub relayed: bool, + pub tx_blob: String, + pub weight: u32 +} diff --git a/src/main.rs b/src/main.rs index 071b755..ee3838c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn issue_rpc(method: &str, params: Option) -> RequestBuilder { env::var("DAEMON_URI").unwrap() ); let post_data = RPCPayload { - method: method.to_string(), + method: Some(method.to_string()), params: params, ..Default::default() }; @@ -39,6 +39,29 @@ fn issue_raw_rpc(method: &str, params: JsonValue) -> RequestBuilder { http_client.post(&url).json(¶ms) } +fn build_rpc(method: &str, data: Option, raw: bool) -> RequestBuilder { + let http_client = Client::new(); + let daemon_uri = env::var("DAEMON_URI").unwrap(); + match raw { + true => { + let uri = format!("{}/{}", &daemon_uri, &method); + if let None = data { + http_client.post(&uri) + } else { + http_client.post(&uri).json(&data) + } + }, + false => { + let uri = format!("{}/json_rpc", &daemon_uri); + let data = RPCPayload { + method: Some(method.to_string()), + ..Default::default() + }; + http_client.post(&uri).json(&data) + } + } +} + #[get("/block/hash/")] fn get_block_by_hash(block_hash: String) -> Template { let params = RPCParams { @@ -120,9 +143,19 @@ fn search(value: &RawStr) -> Redirect { #[get("/")] fn index() -> Template { - let res: GetInfo = issue_rpc(&"get_info", None) + let daemon_info: GetInfo = issue_rpc(&"get_info", None) .send().unwrap().json().unwrap(); - Template::render("index", &res.result) + + let tx_pool: GetTransactionPool = build_rpc( + &"get_transaction_pool", None, true + ).send().unwrap().json().unwrap(); + + let context: JsonValue = json!({ + "daemon_info": daemon_info.result, + "tx_pool": tx_pool.transactions + }); + + Template::render("index", context) } #[get("/error", )] diff --git a/static/css/main.css b/static/css/main.css index fe11603..e69fa21 100755 --- a/static/css/main.css +++ b/static/css/main.css @@ -283,3 +283,7 @@ p.subheader { .container td { font-size: 1.1em; } + +.tx-table th, .tx-table td { + text-align: center; +} diff --git a/templates/index.html.tera b/templates/index.html.tera index cc0baa1..6a5b2a7 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -16,7 +16,7 @@

Version

-

{% if version %}{{ version }}{% else %}?{% endif %}

+

{% if daemon_info.version %}{{ daemon_info.version }}{% else %}?{% endif %}

@@ -24,7 +24,7 @@

Difficulty

-

{{ difficulty }}

+

{{ daemon_info.difficulty }}

@@ -32,7 +32,7 @@

Height

-

{{ height }}

+

{{ daemon_info.height }}

@@ -40,7 +40,7 @@

Network

-

{{ nettype }}

+

{{ daemon_info.nettype }}

@@ -48,7 +48,7 @@

Transactions

-

{{ tx_count }}

+

{{ daemon_info.tx_count }}

@@ -56,7 +56,7 @@

Mempool Size

-

{{ tx_pool_size }}

+

{{ daemon_info.tx_pool_size }}

@@ -64,7 +64,7 @@

Connections

-

{{ incoming_connections_count }} in / {{ outgoing_connections_count }} out

+

{{ daemon_info.incoming_connections_count }} in / {{ daemon_info.outgoing_connections_count }} out

@@ -72,7 +72,7 @@

Status

-

{{ status }}

+

{{ daemon_info.status }}

@@ -81,8 +81,23 @@

-

Mempool Transactions

-

soon

+
+ + + + + + + + {% for tx in tx_pool %} + + + + + + {% endfor %} +

Transaction Pool

HashAmountFee
{{ tx.id_hash | truncate(length=8) }}?{{ tx.fee / 1000000000000 }} XMR
+