setting up tx pool

master
lalanza808 5 years ago
parent d240a8bcce
commit f3393824e4

@ -2,7 +2,7 @@
pub struct RPCPayload {
pub jsonrpc: String,
pub id: String,
pub method: String,
pub method: Option<String>,
pub params: Option<RPCParams>
}
@ -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<Vec<String>>,
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct GetTransactionPool {
pub credits: u32,
pub spent_key_images: Vec<SpentKeyImages>,
pub status: String,
pub top_hash: String,
pub transactions: Vec<Transactions>
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct SpentKeyImages {
pub id_hash: String,
pub txs_hashes: Vec<String>
}
#[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
}

@ -22,7 +22,7 @@ fn issue_rpc(method: &str, params: Option<RPCParams>) -> 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(&params)
}
fn build_rpc(method: &str, data: Option<JsonValue>, 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/<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", )]

@ -283,3 +283,7 @@ p.subheader {
.container td {
font-size: 1.1em;
}
.tx-table th, .tx-table td {
text-align: center;
}

@ -16,7 +16,7 @@
<header>
<h3>Version</h3>
</header>
<p>{% if version %}{{ version }}{% else %}?{% endif %}</p>
<p>{% if daemon_info.version %}{{ daemon_info.version }}{% else %}?{% endif %}</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -24,7 +24,7 @@
<header>
<h3>Difficulty</h3>
</header>
<p>{{ difficulty }}</p>
<p>{{ daemon_info.difficulty }}</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -32,7 +32,7 @@
<header>
<h3>Height</h3>
</header>
<p>{{ height }}</p>
<p>{{ daemon_info.height }}</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -40,7 +40,7 @@
<header>
<h3>Network</h3>
</header>
<p>{{ nettype }}</p>
<p>{{ daemon_info.nettype }}</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -48,7 +48,7 @@
<header>
<h3>Transactions</h3>
</header>
<p>{{ tx_count }}</p>
<p>{{ daemon_info.tx_count }}</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -56,7 +56,7 @@
<header>
<h3>Mempool Size</h3>
</header>
<p>{{ tx_pool_size }}</p>
<p>{{ daemon_info.tx_pool_size }}</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -64,7 +64,7 @@
<header>
<h3>Connections</h3>
</header>
<p>{{ incoming_connections_count }} in / {{ outgoing_connections_count }} out</p>
<p>{{ daemon_info.incoming_connections_count }} in / {{ daemon_info.outgoing_connections_count }} out</p>
</section>
</div>
<div class="col-3 col-6-medium col-12-small">
@ -72,7 +72,7 @@
<header>
<h3>Status</h3>
</header>
<p>{{ status }}</p>
<p>{{ daemon_info.status }}</p>
</section>
</div>
</div>
@ -81,8 +81,23 @@
</div>
<br><br>
<header class="major">
<h2>Mempool Transactions</h2>
<p>soon</p>
<div class="tx-table">
<table>
<caption><h2>Transaction Pool</h2></caption>
<tr>
<th>Hash</th>
<th>Amount</th>
<th>Fee</th>
</tr>
{% for tx in tx_pool %}
<tr>
<td>{{ tx.id_hash | truncate(length=8) }}</td>
<td>?</td>
<td>{{ tx.fee / 1000000000000 }} XMR</td>
</tr>
{% endfor %}
</table>
</div>
</header>
</div>
</section>

Loading…
Cancel
Save