improving json response parsing

master
lalanza808 5 years ago
parent c4d3df61c8
commit 24c7d02b3d

@ -180,35 +180,42 @@ pub struct Transactions {
pub weight: u32
}
// #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
// pub struct TransactionJSON {
// pub version: u32,
// pub unlock_time: u64,
// pub vin: TransactionInputs,
// pub vout: TransactionOutputs,
// pub extra: String,
// pub signatures: Vec<String>
// }
//
// #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
// pub struct TransactionInputs {
// pub pubkey: PreviousTransactionKey
// }
//
// #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
// pub struct PreviousTransactionKey {
// pub amount: u32,
// pub key_offsets: Vec<u32>,
// pub k_image: String
// }
//
// #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
// pub struct TransactionOutputs {
// pub amount: u32,
// pub target: OutputStealthAddress
// }
//
// #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
// pub struct OutputStealthAddress {
// pub key: String
// }
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct TransactionJSON {
pub version: u32,
pub unlock_time: u64,
pub vin: Vec<TransactionInputs>,
pub vout: Vec<TransactionOutputs>,
pub extra: Vec<u32>,
pub rct_signatures: RingSignatures
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct TransactionInputs {
pub key: PreviousTransactionKey
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct PreviousTransactionKey {
pub amount: u32,
pub key_offsets: Vec<u32>,
pub k_image: String
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct TransactionOutputs {
pub amount: u32,
pub target: OutputStealthAddress
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct OutputStealthAddress {
pub key: String
}
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
pub struct RingSignatures {
pub r#type: u32,
pub txnFee: u64,
pub outPk: Vec<String>
}

@ -7,7 +7,7 @@ mod data_types;
use rocket::http::RawStr;
use rocket::response::Redirect;
use rocket_contrib::json::{Json, JsonValue};
use rocket_contrib::json::JsonValue;
use rocket_contrib::templates::Template;
use rocket_contrib::serve::StaticFiles;
use reqwest::blocking::{RequestBuilder, Client};
@ -152,13 +152,21 @@ fn index() -> Template {
let daemon_info: GetInfo = issue_rpc(&"get_info", None)
.send().unwrap().json().unwrap();
let tx_pool: GetTransactionPool = build_rpc(
let mut tx_pool: GetTransactionPool = build_rpc(
&"get_transaction_pool", None, true
).send().unwrap().json().unwrap();
let mut tx_json_raw: Vec<TransactionJSON> = vec![];
for f in &mut tx_pool.transactions {
let j: TransactionJSON = serde_json::from_str(&f.tx_json).unwrap();
tx_json_raw.push(j)
};
let context: JsonValue = json!({
"daemon_info": daemon_info.result,
"tx_pool": tx_pool.transactions
"tx_pool": tx_pool.transactions,
"tx_json": tx_json_raw
});
Template::render("index", context)

@ -92,6 +92,27 @@
<th>Amount</th>
<th>Fee</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>
@ -99,6 +120,7 @@
<td>{{ tx.fee / 1000000000000 }} XMR</td>
</tr>
{% endfor %}
{% endcomment %}
</table>
</div>
</header>

Loading…
Cancel
Save