add remainder of routes to use

master
lza_menace 2 years ago
parent 3556b27497
commit 5358696d79

@ -1,6 +1,6 @@
#[macro_use] extern crate rocket; #[macro_use] extern crate rocket;
mod routes; mod routes;
use routes::block::get_height; use routes::{block, transaction, address, search};
#[get("/")] #[get("/")]
fn index() -> &'static str { fn index() -> &'static str {
@ -11,5 +11,8 @@ fn index() -> &'static str {
fn rocket() -> _ { fn rocket() -> _ {
rocket::build() rocket::build()
.mount("/", routes![index]) .mount("/", routes![index])
.mount("/block", routes![get_height]) .mount("/block", routes![block::height, block::hash])
.mount("/transaction", routes![transaction::hash, transaction::receipt])
.mount("/address", routes![address::show])
.mount("/search", routes![search::show])
} }

@ -0,0 +1,4 @@
#[get("/")]
pub fn show() -> &'static str {
"address details and qr"
}

@ -1,12 +1,23 @@
use rocket::serde::json; use rocket::serde::json::{Value, json};
#[get("/height/<block_height>")] #[get("/height/<height>")]
pub fn get_height(block_height: i32) -> json::Value { pub fn height(height: i32) -> Value {
return json::json!({ let payload: Value = json!({
"method": "get_block", "method": "get_block",
"params": { "params": {
"height": block_height "height": height
} }
}); });
return payload;
}
#[get("/hash/<hash>")]
pub fn hash(hash: String) -> Value {
let payload: Value = json!({
"method": "get_block",
"params": {
"hash": hash
}
});
return payload;
} }

@ -1,2 +1,4 @@
pub mod block; pub mod block;
// pub mod block::get_height; pub mod transaction;
pub mod address;
pub mod search;

@ -0,0 +1,5 @@
#[get("/<value>")]
pub fn show(value: String) -> &'static str {
println!("found args: {}", value);
"search options/args"
}

@ -0,0 +1,47 @@
use rocket::serde::json::{Value, json};
#[get("/<hash>")]
pub fn hash(hash: String) -> Value {
let params: Value = json!({
"txs_hashes": [&hash],
"decode_as_json": true
});
// let mut res: GetTransactions = build_rpc(
// &"get_transactions", Some(params), true
// ).send().unwrap().json().unwrap();
// if res.txs.len() > 0 {
// for f in &mut res.txs {
// f.process();
// };
// };
// let context = json!({
// "tx_info": res.txs,
// "hash": hash,
// "debug": res.clone()
// });
return params;
}
#[get("/receipt?<address>&<hash>&<key>")]
pub fn receipt(address: String, hash: String, key: String) -> Value {
let payload: Value = json!({
"method": "check_tx_key",
"params": {
"address": address,
"txid": hash,
"tx_key": key
}
});
// let http_client = Client::new();
// let wallet_uri = env::var("WALLET_URI").unwrap();
// let uri = format!("{}/json_rpc", &wallet_uri);
// let res: CheckTxKeyResponse = http_client.post(&uri).json(&payload)
// .send().unwrap().json().unwrap();
// let context = json!({
// "res": &res.result,
// "hash": hash,
// "address": address
// });
// Template::render("receipt", context)
return payload;
}
Loading…
Cancel
Save